1.0.3 • Published 10 months ago

bt-react-select v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Select Component

Overview

The Select component is a versatile dropdown component for React applications. It supports various features such as search, chip list selection, and custom icons.

Select Component Select Component

Live Demo

Installation

To use the Select component, ensure you have the necessary dependencies installed:

npm install react react-dom react-icons

Usage

Basic Usage

import Select from "./components/select";
import { DUMMY_OPTIONS } from "./data/dummy";

const handleSelectChange = (value: string) => {
  console.log("Selected value: ", value);
};

<Select
  label="Team member"
  placeholder="Select team member"
  options={DUMMY_OPTIONS}
  onChange={handleSelectChange}
/>;

With Icons

import { FaRegUser } from "react-icons/fa6";

<Select
  showItemIcon
  label="Team member"
  placeholder="Select team member"
  options={DUMMY_OPTIONS}
  icon={<FaRegUser />}
  onChange={handleSelectChange}
/>;

Searchable Select

import { CiSearch } from "react-icons/ci";

<Select
  variant="search"
  label="Team member"
  placeholder="Select team member"
  options={DUMMY_OPTIONS}
  icon={<CiSearch />}
  onChange={handleSelectChange}
/>;

Chip List Select

<Select
  showItemIcon
  label="Team member"
  placeholder="Select team member"
  options={DUMMY_OPTIONS}
  onChange={handleSelectChange}
  variant="chipList"
/>

Props

SelectProps

PropTypeDefaultDescription
optionsOption[][]Array of options to display in the dropdown.
placeholderstring"Select an option"Placeholder text when no option is selected.
helperTextstringundefinedHelper text displayed below the dropdown.
labelstringundefinedLabel text displayed above the dropdown.
iconReact.ReactNodeundefinedIcon displayed inside the dropdown.
showItemIconbooleanfalseWhether to show icons for each item.
onChange(value: string) => voidundefinedCallback function when an option is selected.
selectedIconReact.ReactNodeundefinedIcon displayed for selected option.
variantSelectVariantSelectVariant.DEFAULTVariant of the select component.
disabledbooleanfalseWhether the select component is disabled.
defaultValuestringundefinedDefault value of the select component.
fieldNames{ label: string; value: string; img?: string }undefinedCustom field names for the options.
filterSort(optionA: Option, optionB: Option) => numberundefinedCustom filter and sort function for options.

Option

PropTypeDescription
valuestringThe value of the option.
labelstringThe label of the option.
imgstringOptional image URL for the option.

SelectVariant

VariantDescription
DEFAULTDefault variant with basic dropdown functionality.
SEARCHSearchable dropdown variant.
CHIP_LISTChip list variant allowing multiple selections.

License

This project is licensed under the MIT License.