1.2.2 • Published 1 year ago

react-dn-select v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-dn-select NPM Version

  • Supports both single and multi selection
  • Works with responsive layouts
  • Select box and items can be freely styled
  • Uses modern React components with hooks

See demo app

Install

npm install react-dn-select

Use

import { useState } from 'react';
import { DnSelect } from 'react-dn-select';

function App() {
  // items can be either primitives or objects
  const [items, setItems] = useState(['Foo', 'Bar', 'Baz', '...']);

  return (
    <div className="App">
      <DnSelect
        items={items}
        itemId={(item) => item.toLowerCase()}
        renderItem={({ item }) => <p>{item}</p>}
      />
    </div>
  );
}

Props

Required

NameDescriptionDefaultExample value
itemsThe items to be selectedundefined['Foo', 'Bar', 'Baz']
itemIdFunction to get each item's idundefined(item) => item.toLowerCase()
renderItemFunction to render each itemundefined({ item, isSelected }) => <p>{item}</p>

Optional

NameDescriptionDefaultExample value
initSelectedPreselected items on initial mount[]['Bar', 'Baz']
multiAllows multi-select when truefalsetrue
onDragStartFunction to react to selection startundefined(prevSelection) => {}
onDragMoveFunction to react to selection moveundefined(currSelection) => {}
onDragEndFunction to react to selection endundefined(finalSelection) => {}
escapableStops selection on Escape key presstruefalse
onEscapeFunction to fire when escapedundefined() => {}
throttleDelayPrevents rapid rerenders from pointermove100150
dragThresholdPixels to drag before drawing the select box14

Development

A minimal dev page can be found in the example directory. Execute npm run dev to run the demo page.

1.2.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago