# Choice pills

Source: https://ecosphere.dev/docs/forms/choice-pills (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

Many small values chosen at once: sections, working days, periods.

`import { EcoChoicePills } from "vue-ecosphere"`

## Sections, with an escape from the enumeration

The dashed pill is not another value; here it adds a section to show the event.

Vue (vue-ecosphere):

```vue
<EcoChoicePills v-model="sections" label="Sections" :options="sectionOptions"
  addable add-label="Stream instead" @add="…" />
```

React (react-ecosphere):

```tsx
const [sections, setSections] = useState(["A", "B", "C"]);

<EcoChoicePills value={sections} onChange={setSections} label="Sections" options={sectionOptions}
  addable addLabel="Stream instead" onAdd={() => …} />
```

## Working days

Vue (vue-ecosphere):

```vue
<EcoChoicePills v-model="days" label="Working days"
  :options="['Mon','Tue','Wed','Thu','Fri','Sat','Sun'].map((d) => ({ label: d, value: d }))" />
```

React (react-ecosphere):

```tsx
const [days, setDays] = useState(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]);

<EcoChoicePills value={days} onChange={setDays} label="Working days"
  options={["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].map((d) => ({ label: d, value: d }))} />
```

## Periods a subject may fall in

Vue (vue-ecosphere):

```vue
<EcoChoicePills v-model="periods" label="Periods"
  :options="['P1','P2','P3','P4','P5','P6','P7','P8'].map((p) => ({ label: p, value: p }))" />
```

React (react-ecosphere):

```tsx
const [periods, setPeriods] = useState(["P1", "P2", "P4"]);

<EcoChoicePills value={periods} onChange={setPeriods} label="Periods"
  options={["P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8"].map((p) => ({ label: p, value: p }))} />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `(string \| number)[]` | [] | The chosen values. |
| `options` | `EcoOption[]` | — | Short values in a closed set. |
| `label` | `string` | — | Accessible name of the group. |
| `addable` | `boolean` | false | One dashed pill--add at the end — the escape from the enumeration. |
| `addLabel` | `string` | "Add" | Text of the add pill (or use the #add slot). |
| `disabled` | `boolean` | false | Disable every pill. |
| `@add` | `() => void` | — | The add pill was pressed. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `(string \| number)[]` | [] | The chosen values. |
| `options` | `EcoOption[]` | — | Short values in a closed set. |
| `label` | `string` | — | Accessible name of the group. |
| `addable` | `boolean` | false | One dashed pill--add at the end — the escape from the enumeration. |
| `addLabel` | `string` | "Add" | Text of the add pill (or pass add, a node that replaces it). |
| `disabled` | `boolean` | false | Disable every pill. |
| `onAdd` | `() => void` | — | The add pill was pressed. |
