1.0.118 • Published 1 year ago

custom-multi-or-simple-select v1.0.118

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

Custom Select Component

A customizable and easy-to-use React select component built with TypeScript and following the Atomic Design pattern.

Features

  • Single and multi-select options
  • Search and filter options
  • Option grouping
  • Create new options
  • Select/deselect all options

Installation

Install the package using npm:

npm install custom-multi-or-simple-select

Usage

Import the CustomSelect component from the package:

import { CustomSelect } from 'custom-multi-or-simple-select';

Import the default styles:

import "custom-multi-or-simple-select/dist/styles/CustomSelect.css";

Use the CustomSelect component in your React application:

const [selectedOption, setSelectedOption] = useState<OptionObject[]>([]);

const handleSelectChange = (selectedOptions: OptionObject[]) => {
	setSelectedOption(selectedOptions);
};

<CustomSelect
    multiple={true}
    options={options}
    hasSelectAll={true}
    isCreatable={false}
    closeOnChange={false}
    onChange={handleSelectChange}
    isLoading={false}
    className=""
    classNameDropdown=""
    classNameOption=""
    placeholder="Select one or more options"
/>

Props

PropTypeDefaultDescription
multiplebooleantrueWhether multiple options can be selected.
optionsOptionObject[]-An array of option objects. Each object must have an id and a label, and may also have a group.
hasSelectAllbooleantrueWhether to display the "Select All" option.
isCreatablebooleanfalseAllows the user to create new options if the search does not match any existing options.
closeOnChangeboolean-Whether to close the dropdown when an option is selected (only applicable when multiple is false).
onChangefunction-A callback function called when the selected options change. The function receives an array of selected OptionObjects as its argument.
isLoadingbooleanfalseWhether the component should display a loading state.
classNamestring''A custom class name for the main CustomSelect component.
classNameDropdownstring''A custom class name for the dropdown containing the options.
classNameOptionstring''A custom class name for the option elements.
placeholderstring"Select one or more options"Placeholder text for the search bar when no options are selected.

Types

TypeDescription
OptionObjectAn object representing a selectable option. It must have an id (string) and a label (string), and may also have a group (string).
CustomSelectPropsAn object containing all the props for the CustomSelect component. See the props table for details on each property.
AddNewOptionPropsAn object containing the props for the AddNewOption component, including label (string), text (string), onClick (function), and className (string).
OptionRowPropsAn object containing the props for the OptionRow component, including option (OptionObject), selected (boolean), multiple (boolean), onClick (function), and className (string).
SearchBarPropsAn object containing the props for the SearchBar component, including value (string), onChange (function), className (string), and placeholder (string).

Default Styles

Class NameProperties
CustomSelectposition: relative;
dropdownposition: absolute; width: 100%; background: #fff; z-index: 99; border-radius: 5px; border: 2px solid #ccc; padding-left: 1%; max-height: 20vh; overflow-y: auto;
groupmargin-top: .25rem; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;
group-optionspadding-left: 1rem;
select-alldisplay: flex; justify-content: flex-start; align-items: center; gap: .25rem; width: 100%; border-bottom: 2px solid #ccc;
SearchBardisplay: flex; flex-direction: row; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 5px; border: 2px solid #ccc; padding-left: 1%;
OptionRowdisplay: flex; justify-content: flex-start; align-items: center; gap: .25rem;
AddNewOptionpadding-left: 1%;
1.0.118

1 year ago

1.0.117

1 year ago

1.0.116

1 year ago

1.0.115

1 year ago

1.0.114

1 year ago

1.0.113

1 year ago

1.0.112

1 year ago

1.0.111

1 year ago

1.0.11

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago