# custom-multi-or-simple-select

> Custom select with search, multiple select and create

Latest version **1.0.118** (published 2023-03-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install custom-multi-or-simple-select
pnpm add custom-multi-or-simple-select
yarn add custom-multi-or-simple-select
bun add custom-multi-or-simple-select
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.118 |
| Published | 2023-03-28 |
| First published | 2023-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Olivier Belleval |
| Maintainers | kilann |

## Links

- npm: https://www.npmjs.com/package/custom-multi-or-simple-select
- npm.io page: https://npm.io/package/custom-multi-or-simple-select

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.2.0
- [@types/react](https://npm.io/package/@types/react.md) ^18.0.29

## Recent versions

- 1.0.118 (latest) — 2023-03-28
- 1.0.117 — 2023-03-27
- 1.0.116 — 2023-03-27
- 1.0.115 — 2023-03-27
- 1.0.114 — 2023-03-27
- 1.0.113 — 2023-03-27
- 1.0.112 — 2023-03-27
- 1.0.111 — 2023-03-26
- 1.0.11 — 2023-03-26
- 1.0.1 — 2023-03-26
- 1.0.0 — 2023-03-26

## README

# 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:

```bash
npm install custom-multi-or-simple-select
```

## Usage
Import the CustomSelect component from the package:

```typescript
import { CustomSelect } from 'custom-multi-or-simple-select';
```

Import the default styles:
```typescript
import "custom-multi-or-simple-select/dist/styles/CustomSelect.css";
```

Use the CustomSelect component in your React application:

```typescript
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
| Prop              | Type                     | Default           | Description                                                                                                                                                 |
|-------------------|--------------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| multiple          | boolean                  | true              | Whether multiple options can be selected.                                                                                                                   |
| options           | OptionObject[]           | -                 | An array of option objects. Each object must have an `id` and a `label`, and may also have a `group`.                                                       |
| hasSelectAll      | boolean                  | true              | Whether to display the "Select All" option.                                                                                                                 |
| isCreatable       | boolean                  | false             | Allows the user to create new options if the search does not match any existing options.                                                                    |
| closeOnChange     | boolean                  | -                 | Whether to close the dropdown when an option is selected (only applicable when `multiple` is `false`).                                                      |
| onChange          | function                 | -                 | A callback function called when the selected options change. The function receives an array of selected `OptionObject`s as its argument.                    |
| isLoading         | boolean                  | false             | Whether the component should display a loading state.                                                                                                       |
| className         | string                   | ''                | A custom class name for the main `CustomSelect` component.                                                                                                 |
| classNameDropdown | string                   | ''                | A custom class name for the dropdown containing the options.                                                                                                |
| classNameOption   | string                   | ''                | A custom class name for the option elements.                                                                                                                 |
| placeholder       | string                   | "Select one or more options" | Placeholder text for the search bar when no options are selected.                                                                                         |


## Types
| Type             | Description                                                                                   |
|------------------|-----------------------------------------------------------------------------------------------|
| OptionObject     | An object representing a selectable option. It must have an `id` (string) and a `label` (string), and may also have a `group` (string).               |
| CustomSelectProps| An object containing all the props for the `CustomSelect` component. See the props table for details on each property.                               |
| AddNewOptionProps| An object containing the props for the `AddNewOption` component, including `label` (string), `text` (string), `onClick` (function), and `className` (string).|
| OptionRowProps   | An object containing the props for the `OptionRow` component, including `option` (OptionObject), `selected` (boolean), `multiple` (boolean), `onClick` (function), and `className` (string).|
| SearchBarProps   | An object containing the props for the `SearchBar` component, including `value` (string), `onChange` (function), `className` (string), and `placeholder` (string).|


## Default Styles
| Class Name        | Properties                                                                                                                                              |
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| CustomSelect      | `position: relative;`                                                                                                                                   |
| dropdown          | `position: absolute; width: 100%; background: #fff; z-index: 99; border-radius: 5px; border: 2px solid #ccc; padding-left: 1%; max-height: 20vh; overflow-y: auto;` |
| group             | `margin-top: .25rem; display: flex; flex-direction: column; justify-content: center; align-items: flex-start;`                                           |
| group-options     | `padding-left: 1rem;`                                                                                                                                   |
| select-all        | `display: flex; justify-content: flex-start; align-items: center; gap: .25rem; width: 100%; border-bottom: 2px solid #ccc;`                             |
| SearchBar         | `display: flex; flex-direction: row; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 5px; border: 2px solid #ccc; padding-left: 1%;` |
| OptionRow         | `display: flex; justify-content: flex-start; align-items: center; gap: .25rem;`                                                                         |
| AddNewOption      | `padding-left: 1%;`                                                                                                                                     |

---
_Source: https://npm.io/package/custom-multi-or-simple-select · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
