Segmented control
Segmented control with a sliding thumb and a toggle group, for view modes, filters and text formatting buttons.
How to use it
Run npx @blossomui/react add segmented-control, or copy src/components/UI/SegmentedControl/SegmentedControl.tsx into your React project and import it.
import { SegmentedControl, ToggleGroup } from './components/ui/SegmentedControl'
Props
SegmentedOption
| Prop | Type | Description |
|---|
| value (required) | string | |
| label | string | |
| icon | ReactNode | |
| disabled | boolean | |
| ariaLabel | string | Accessible name when the option only has an icon. |
SegmentedControlProps
| Prop | Type | Description |
|---|
| options (required) | SegmentedOption[] | |
| value | string | Controlled value. Use together with `onChange`. |
| defaultValue | string | Initial value when the control is not controlled. |
| onChange | (value: string) => void | |
| size | 'sm' | 'md' | 'lg' | |
| fullWidth | boolean | Make every option take the same share of the width. |
| variant | 'boxed' | 'filled' | `boxed` slides a white card, `filled` slides the brand color. |
| color | string | Accent color of this component: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| disabled | boolean | |
| label | string | Accessible name of the group. |
ToggleItem
| Prop | Type | Description |
|---|
| value (required) | string | |
| label | string | |
| icon | ReactNode | |
| disabled | boolean | |
| ariaLabel | string | Accessible name when the item only has an icon. |
ToggleGroupSingleProps
| Prop | Type | Description |
|---|
| type | 'single' | `single` lets one item be pressed at a time, `multiple` lets any number be pressed. |
| value | string | null | |
| defaultValue | string | null | |
| onChange | (value: string | null) => void | |
ToggleGroupMultipleProps
| Prop | Type | Description |
|---|
| type (required) | 'multiple' | |
| value | string[] | |
| defaultValue | string[] | |
| onChange | (value: string[]) => void | |