Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keyvaluesoftwaresystems/react-multi-selection-ui
React Multi Selection UI Component with search functionality
https://github.com/keyvaluesoftwaresystems/react-multi-selection-ui
multi-selection next-js react typescript
Last synced: 4 days ago
JSON representation
React Multi Selection UI Component with search functionality
- Host: GitHub
- URL: https://github.com/keyvaluesoftwaresystems/react-multi-selection-ui
- Owner: KeyValueSoftwareSystems
- License: mit
- Created: 2023-04-17T07:52:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-20T22:23:25.000Z (9 months ago)
- Last Synced: 2024-11-12T16:04:04.646Z (4 days ago)
- Topics: multi-selection, next-js, react, typescript
- Language: TypeScript
- Homepage:
- Size: 2.01 MB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# React Multi Selection UI
> A pre-built, customizable Multi-Selection UI component with an integrated search feature
Try tweaking a multi selection ui component using this codesandbox link here
## Installation
The easiest way to use react-multi-selection-ui-component is to install it from npm and build it into your app with Webpack.
```bash
npm install @keyvaluesystems/react-multi-selection-ui-component
```
You’ll need to install React separately since it isn't included in the package.
Note for **Next.js** users, if you are using Next.js version 13 or later, you will have to use the `use client` feature to ensure proper compatibility.
## Usage
React Multi Selection UI can run in a very basic mode by just providing the `options` like given below:
```jsx
import MultiSelection from "@keyvaluesystems/react-multi-selection-ui-component";;
```The optionsArray consists of objects with the following keys:
- `id`: A unique identifier for each option.
- `name`: A string representing the label for each option.
- `checked`: An optional boolean value indicating the default state of the optionAn example for options array is shown below:
```jsx
const optionsArray = [
{
id: 1,
name: "Option 1",
checked: true,
},
{
id: 2,
name: "Option 2",
},
];
```## v1.0.0 (Major Version Change)
This release includes breaking changes, new features, and updates. Please read this document carefully before upgrading
### Breaking Changes
- The `productList` prop has been renamed to `options`, and now each object within the options array includes an additional optional `checked` property.
- The `zeroState` prop is deprecated.
- Significant alterations have been made to the UI behavior.
Please take note of these changes during the upgrade### Migration Steps
- Update Options Prop: The `productList` prop has been renamed to `options`. Use the `options` prop to pass the list of items.
- Replace `searchPlaceholder` with placeholder:The `searchPlaceholder` prop has been replaced with `placeholder`.
- Utilize `renderEmptyItem` Prop: To pass the empty state component, use the renderEmptyItem prop.Before
```jsx
,
selectedList: ,
}}
/>
```After
```jsx
}
/>
```## Props
Props that can be passed to the component are listed below:
Prop
Description
Default
options: object[]
An array of objects to specify the id, name and default state of each option
[]
showCheckbox?: boolean
The boolean value to control the display of checkbox in the selection list
true
placeholder?: string
The placeholder value for the search text box if search is enabled and default text shown in the box if search is disabled
'Choose an option'
hideSelected?: boolean
The boolean value to control the display of selected values in the list
false
hideSearch?: boolean
The boolean value to control the display of search text box in the selection list
false
onSearch?: function
The callback function which will be triggered on text change in the search box
undefined
onItemClick?: function
The callback function which will be triggered on clicking the menu item row. Can be used for obtaining the clicked row id
undefined
setSelectedValues?: function
The callback function which will be triggered on clicking the check box and chip's close button. Can be used for obtaining the selected id's
undefined
styles?: object
Provides you with a bunch of callback functions to override the default styles.
undefined
showChips?: boolean
The boolean value to control the display of selected options as chips.
true
dropdownMaxHeight?: string | number
The prop to control the height of the dropdown modal.
'100%'
renderEmptyItem?: JSX
The JSX element to be shown in case of empty result.
No other options
isLoading?: boolean
The boolean value to show loading state in the dropdown list.
false
renderLoader?: JSX
The JSX element to be shown while loading.
Default loader component
hasError?: boolean
The boolean value to indicate error.
false
helperText?: ''
To display an additional message.
''
thresholdForBubble?: number
Show the bubble when the count of selected items reaches this threshold.
length of options array
icons?: object
Provides you with an object to replace the default icons used.
undefined
clearSearchClick?: function
The callback function which will be triggered on clicking close icon inside search box
undefined
## Style Customizations
All the default styles provided by this package are overridable using the `style` prop.
the below code shows all the overridable styles:```jsx
({...styles}),
UnSelectedMenuItem?: (id) => ({...styles}),
ChipComponent?: (id) => ({...styles}),
}}
/>
```To customize the style of various components, you can use the following prop names, each of which accepts a style object:
- `ArrowIcon`: Overrides the style of the right-arrow icon.
- `Container`: Overrides the style of the multi-selection UI container.
- `CheckedIcon`: Overrides the style of the checked icon.
- `ChipCloseIcon`: Overrides the style of the close icon within the chip.
- `ClearSearchIcon`: Overrides the style of the close icon within the search box.
- `HelperText`: Overrides the style of the helper text.
- `HiddenChipsIndicator`: Overrides the style of the bubble indicating the number of hidden chips if the thresholdForBubble prop has a value.
- `InputBox`: Overrides the style of the box containing the chips and search bar. Can be used to style the placeholder if the search is hidden.
- `SearchIcon`: Overrides the style of the search icon.
- `SearchComponent`: Overrides the styles of the search component.
- `UnCheckedIcon`: Overrides the style of the unchecked box.You can utilize the provided prop names to customize the style of individual items in the chip or each item in the menu. This can be achieved by passing a function that returns the desired style for each element.
- `ChipComponent` - Overrides the chip style
- `SelectedMenuItem` - Overrides the selected menu item styles
- `UnSelectedMenuItem` - Overrides the non selected item styles## Icon Customizations
The `icons` prop allows for the customization of default icons provided by this package
The following code displays the icons that can be customized```jsx
```
- `Arrow` - Overrides the down arrow(right)
- `ChipClose` - Overrides the chip close icon
- `Checked` - Overrides the checkbox checked icon
- `ClearSearch` - Overrides the close icon inside search box
- `Search` - Overrides the search icon