react-selectable-fast npm license github-issues

Install

npm i -S react-selectable-fast

react-selectable-fast

Demo

Draw a box with your mouse/touch to select items. Click on + icon of an individual item to select it.

JavaScript environment requirements

The React-Selectable-Fast package distributed on NPM use the widely-supported ES5 version of JavaScript to support as many browser environments as possible.

However, this package expects modern JavaScript globals (Map, Set, Array.from, Array.isArray Object.assign) to be defined. If you support older browsers and devices which may not yet provide these natively, consider including a global polyfill in your bundled application, such as core-js or babel-polyfill.

A polyfilled environment for React-Selectable-Fast using core-js to support older browsers might look like this:

import 'core-js/fn/object/assign'
import 'core-js/fn/array/from'
import 'core-js/fn/array/is-array'
import 'core-js/fn/map'
import 'core-js/fn/set'

import App from './myApp';

Usage

Example

Package exports 4 entities { SelectableGroup, createSelectable, SelectAll, DeselectAll }. To make other components selectable wrap them using HoC createSelectable, add passed selectableRef prop to the target node and put a list of seletable items under SelectableGroup.

import React, { Component } from 'react'
import { SelectableGroup } from 'react-selectable-fast'

class App extends Component {
  ...

  render() {
    return (
      <SelectableGroup
        className="main"
        clickClassName="tick"
        enableDeselect
        tolerance={this.state.tolerance}
        globalMouse={this.state.isGlobal}
        allowClickWithoutSelected={false}
        duringSelection={this.handleSelecting}
        onSelectionClear={this.handleSelectionClear}
        onSelectionFinish={this.handleSelectionFinish}
        ignoreList={['.not-selectable', '.item:nth-child(10)', '.item:nth-child(27)']}
      >
        <List items={this.props.items} />
      </SelectableGroup>
    )
  }
}
import React from 'react'
import { createSelectable } from 'react-selectable-fast'

const SomeComponent = ({ selectableRef, isSelected, isSelecting }) => (
  <div ref={selectableRef}>...</div>
)

export default createSelectable(SomeComponent)
import React, { Component } from 'react'
import { createSelectable, SelectAll, DeselectAll } from 'react-selectable-fast'
import SomeComponent from './SomeComponent'

const SelectableComponent = createSelectable(SomeComponent)

class List extends Component {
  ...

  render() {
    return (
      <div>
        <SelectAll className="selectable-button">
          <button>Select all</button>
        </SelectAll>
        <DeselectAll className="selectable-button">
          <button>Clear selection</button>
        </DeselectAll>
        {this.props.items.map((item, i) => (
          <SelectableComponent
            key={i}
            player={item.player}
            year={item.year}
          />
        ))}
      </div>
    )
  }
}

Configuration

Development

Clean lib and dist folders

npm run clean

Watch src folder

npm run watch

Start example dev-server

npm run watch:example

Lint src folder

npm run lint

License

See MIT