1.1.3 • Published 4 years ago

react-dragandselect v1.1.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

react-dragandselect

Installation

npm i react-dragandselect

or

yarn add react-dragandselect

Props

PropTypeDefaultDescription
isEnablebooleantrueCan enable/disable drag and select
stylestyle objectundefinedCan change wrapper style
boxStylestyle objectundefinedCan change box style (ex: { background-color: red, border-color: orange, opacity: 1})
onSelectedItems() => voidMust needCallback selected data key item

Usage

  • Must wrapping children item once again by <div><div data-select-key={uniquie key}></div></div>
  • Drag and select find item by data-select-key
  • Must set data-select-key what you want find selected items
  import DragAndSelect from 'react-dragandselect';

  const childStyle = { width: '100%', height: '100px', marginBottom: '10px', textAlign: 'center' };
  const childItems = [{ id: '1', color: 'red'}, { id: '2', color: 'orange' }, { id: '3', color: 'yellow' }, { id: '4', color: 'green' }, { id: '5', color: 'blue' }]

  const handleSelectedItems = (selectedDataKeys) => {
    console.log("selectedDataKeys", selectedDataKeys);
  }

  <DragAndSelect onSelectedItems={handleSelectedItems}>
    {
      childItems.map((childItem) => {
        return (
          <div>
            <div data-select-key={childItem.id} style={{...childStyle, backgroundColor: childItem.color}}>
              {childItem.id}
            </div>
          </div>
        );
      })
    }
  </DragAndSelect>

Demo

Demo code