This project implements a flexible and customizable Select component for React applications. It provides a rich set of features to enhance user interaction and data selection in various scenarios, following best practices in TypeScript and React development.
- Multiple Selection Modes: Supports both single and multiple selection.
- Flexible Data Handling: Works with various data types and formats, utilizing TypeScript generics for type safety.
- Customizable Dropdown: Offers a default dropdown with the option to provide a custom implementation.
- Customizable Labels: Supports custom rendering of selected option labels.
- Search Functionality: Enables users to search through options.
- Option Creation: Allows creation of new options on-the-fly.
- Removable Options: Users can remove selected options easily.
- Various Display Variants:
- Default Select
- Action Sheet
- Multi-Select
- Tags / Combobox
- Default Select: A standard dropdown for selecting single items.
- Action Sheet: Displays options with additional details and icons.
- Multi-Select: Allows selection of multiple items, often used for selecting people or categories.
- Combobox with Tags: Enables selection and creation of multiple tags.
options
: Array of selectable options.value
: Currently selected option(s).onChange
: Callback function for handling selection changes.multiple
: Enables multi-select mode when true.searchable
: Enables search functionality when true.creatable
: Allows creation of new options when true.placeholder
: Placeholder text for the select input.customDropdown
: Optional prop for providing a custom dropdown component.customLabel
: Optional prop for providing a custom label component.customInput
: Optional prop for providing a custom input component.renderOption
: Optional function for custom rendering of options.label
: Optional label for the select component.hint
: Optional hint text for the select component.useSearchIcon
: Optional flag to display a search icon.disabled
: Optional flag to disable the select component.showErrorState
: Optional flag to display error state.
import Select from './components/Select'
// Example usage
const MyComponent = () => {
const [value, setValue] = useState(null)
const options = [
{ value: '1', label: 'Option 1' },
{ value: '2', label: 'Option 2' },
{ value: '3', label: 'Option 3' },
]
return (
<Select<ExtendedOption>
options={options}
value={value}
onChange={setValue}
placeholder='Select an option'
searchable
multiple
label='My Select'
hint='Choose one or more options'
/>
)
}
The Select component supports advanced customization through custom dropdown, label, and input components:
import CustomDropdown from './CustomDropdown'
import CustomLabel from './CustomLabel'
import CustomInput from './CustomInput'
;<Select
// ...other props
customDropdown={CustomDropdown}
customLabel={CustomLabel}
customInput={CustomInput}
/>
- Clone the repository
- Install dependencies:
npm install
- Start the development server:
npm run dev