2.0.1 • Published 6 years ago

react-selectronic v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-selectronic

Build Status

inspired by unclecheese/react-selectable

Usage

  1. support group selection with the shift key
  2. support multiple selection with the ctrl key(Windows OS) and the cmd key(Mac OS)
  3. not support group-selection with dragging

Install

yarn add react-selectronic

or

npm install --save react-selectronic

Example

import React from 'react';
import {
  SelectableGroup,
  createSelectable
} from 'react-selectronic';

const Foo = ({ selected, id, onClick }) => (
  <div
    className={selected ? 'selected' : 'unselected'}
    onClick={onClick}
  >
  </div>
);

const SelectableFoo = createSelectable(Foo);
const elements = [1, 2, 3, 4, 5, 6, 7];

class App extends React.Component {
  this.state = {
    selectedList: [],
  };

  render() {
    return (
      <SelectableGroup
        selectedList={this.state.selectedList}
        onChange={this.handleChange}
        uidList={elements}
      >
        {
          elements.map((ele) => (
            <SelectableFoo 
              key={ele} 
              uid={ele} // uid is required
            /> 
          ))
        }
        <div className="nonSelectable" /> // you can insert any component not selectable
      </SelectableGroup>
    );
  }
}

Components

SelectableGroup

Description

Click functions provider which handling the selecting strategy

Props

proptypedefaultrequirednotes
selectedListArray<*>[]vSelected list
onChangeSelectedList => voidvHandle next seelctedList
uidListArray<*>vAll uid(including non-selected) of data
ComponentComponent'div'Component of SelectableGroup

createSelectable

Description

An HOC to wrap onClick

Props

proptypedefaultrequirednotes
uid*vUnique id of the element
selectedbooleanvWhether element is selected
onClickevent => anyAdditional click callback

Caution: wrapped component(as Foo above) must be taken onClick property for selection-function.

Development

yarn start

the demo page will served on port 5000

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago

0.2.0

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago