|
| 1 | +# react-multi-select-component |
| 2 | + |
| 3 | +Simple multiple selection dropdown component with `checkboxes`, `search` and `select-all` |
| 4 | + |
| 5 | +[](https://codesandbox.io/s/muddy-brook-322qc?fontsize=14&hidenavigation=1&theme=dark) |
| 6 | + |
| 7 | +[](https://github.com/harshzalavadiya/react-multi-select-component/actions) |
| 8 | +[](https://npm.im/react-multi-select-component) |
| 9 | +[](https://bundlephobia.com/result?p=react-multi-select-component) |
| 10 | + |
| 11 | +## ✨ Features |
| 12 | + |
| 13 | +- 🍃 Lightweight (~14KB) |
| 14 | +- 💅 Themeable |
| 15 | +- ✌ Written w/ TypeScript |
| 16 | + |
| 17 | +## 🔧 Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +npm i react-multi-select-component # npm |
| 21 | +yarn add react-multi-select-component # yarn |
| 22 | +``` |
| 23 | + |
| 24 | +## 📦 Example |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +```tsx |
| 29 | +import React, { useState } from "react"; |
| 30 | +import MultiSelect from "react-multi-select-component"; |
| 31 | + |
| 32 | +const Example: React.FC = () => { |
| 33 | + const options = [ |
| 34 | + { label: "Grapes 🍇", value: "grapes" }, |
| 35 | + { label: "Mango 🥭", value: "mango" }, |
| 36 | + { label: "Strawberry 🍓", value: "strawberry" } |
| 37 | + ]; |
| 38 | + |
| 39 | + const [selected, setSelected] = useState([]); |
| 40 | + |
| 41 | + return ( |
| 42 | + <div> |
| 43 | + <h1>Select Fruits</h1> |
| 44 | + <pre>{JSON.stringify(selected)}</pre> |
| 45 | + <MultiSelect |
| 46 | + options={options} |
| 47 | + selected={selected} |
| 48 | + onChange={setSelected} |
| 49 | + labelledBy={"Select"} |
| 50 | + /> |
| 51 | + </div> |
| 52 | + ); |
| 53 | +}; |
| 54 | + |
| 55 | +export default App; |
| 56 | +``` |
| 57 | + |
| 58 | +## 👀 Props |
| 59 | + |
| 60 | +| Prop | Description | Type | Default | |
| 61 | +| --------------------- | --------------------------------- | ------------------ | ------- | |
| 62 | +| `labelledBy` | value for `aria-labelledby` | `string` | | |
| 63 | +| `options` | options for dropdown | `[{label, value}]` | | |
| 64 | +| `selected` | pre-selected rows | `[value]` | `[]` | |
| 65 | +| `hasSelectAll` | toggle 'Select All' option | `boolean` | `true` | |
| 66 | +| `isLoading` | show spinner on select | `boolean` | `false` | |
| 67 | +| `shouldToggleOnHover` | toggle dropdown on hover option | `boolean` | `false` | |
| 68 | +| `overrideStrings` | Override default strings for i18n | `object` | | |
| 69 | +| `onChange` | onChhange callback | `function` | | |
| 70 | +| `disabled` | disable dropdown | `boolean` | `false` | |
| 71 | +| `selectAllLabel` | _select all_ label | `string` | | |
| 72 | +| `disableSearch` | hide search textbox | `boolean` | `false` | |
| 73 | +| `filterOptions` | custom filter options | `function` | | |
| 74 | +| `theme` | theme variables | `object` | | |
| 75 | + |
| 76 | +## 🌐 Internationalization |
| 77 | + |
| 78 | +You can override the strings to be whatever you want, including translations for your languages. |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "selectSomeItems": "Select...", |
| 83 | + "allItemsAreSelected": "All items are selected.", |
| 84 | + "selectAll": "Select All", |
| 85 | + "search": "Search" |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +## 💅 Themeing |
| 90 | + |
| 91 | +You can override theme variables to change colors |
| 92 | + |
| 93 | +```json |
| 94 | +{ |
| 95 | + "primary": "#4285F4", |
| 96 | + "hover": "#f1f3f5", |
| 97 | + "border": "#ccc", |
| 98 | + "gray": "#aaa", |
| 99 | + "background": "#fff", |
| 100 | + "borderRadius": "4px", |
| 101 | + "height": "38px" |
| 102 | +} |
| 103 | +``` |
| 104 | + |
| 105 | +## 🤠 Credits |
| 106 | + |
| 107 | +- This project gets inspiration and several pieces of logical code from [react-multiple-select](https://github.com/Khan/react-multi-select/) |
| 108 | +- [TypeScript](https://github.com/microsoft/typescript) |
| 109 | +- [Rollup](https://github.com/rollup/rollup) |
| 110 | +- [Emotion](https://github.com/emotion-js/emotion) |
| 111 | + |
| 112 | +## 📜 License |
| 113 | + |
| 114 | +MIT © [harshzalavadiya](https://github.com/harshzalavadiya) |
0 commit comments