# @eisgs/switcher-button

> Активным может быть только один элемент.

Latest version **1.0.0** (published 2023-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eisgs/switcher-button
pnpm add @eisgs/switcher-button
yarn add @eisgs/switcher-button
bun add @eisgs/switcher-button
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-03-02 |
| First published | 2021-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | traidersu, krll_mdntsv, lzdyd |

## Links

- npm: https://www.npmjs.com/package/@eisgs/switcher-button
- npm.io page: https://npm.io/package/@eisgs/switcher-button

## Dependencies (1)

- [@eisgs/typography](https://npm.io/package/@eisgs/typography.md) ^1.3.1

## Recent versions

- 1.0.0 (latest) — 2023-03-02
- 0.0.8 — 2022-10-27
- 0.0.7 — 2022-06-02
- 0.0.5 — 2022-04-05
- 0.0.4 — 2022-02-24
- 0.0.3 — 2022-01-26
- 0.0.1 — 2021-12-29

## README

### Компонент SwitcherButtonGroup

Активным может быть только один элемент.

`value` и `onChange` используются для управления состоянием.

`options` - опции для создания компонента.

```jsx
import { SwitcherButtonGroup } from '@eisgs/switcher-button';

const defaultOptions = [
  { label: 'Опция 1', value: '100' },
  { label: 'Опция 2', value: '200' },
  { label: 'Опция 3', value: '300' },
  { label: 'Опция 4', value: '400' },
  { label: 'Опция 5', value: '500' },
];

const [value, setValue] = React.useState();
const [options, setOptions] = React.useState(defaultOptions);

const handleDelete = (val) => setOptions(options.filter((option) => option.value !== val));

const mappedOptions = options.map((option, index) => ({
  ...option,
  ...(index > 2 && { onDelete: handleDelete }),
}));

<SwitcherButtonGroup options={mappedOptions} value={value} onChange={setValue} />
```

### Компонент SwitcherButton

Все возможные виды кнопки - стандартное отображение и с возможностью удаления (+ активное состояние).

```jsx
const [value, setValue] = React.useState();

const handleDelete = (val) => val;

const options = [
  { label: 'Опция 1', value: '100' },
  { label: 'Опция 2', value: '200', isActive: true },
  { label: 'Опция 3', value: '300' },
  { label: 'Опция 4', value: '400', isActive: true },
];

<div style={{ display: 'flex' }}>
  {options.map((option, index) => {
    const { label, ...rest } = option;

    return (
      <SwitcherButton 
        {...rest} 
        {...(index > 1 && { onDelete: handleDelete })} 
        key={label}
      >
        {label}
      </SwitcherButton>
    );
  })}
</div>
```

---
_Source: https://npm.io/package/@eisgs/switcher-button · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
