import { Canvas, Meta, Controls } from "@storybook/addon-docs/blocks";
import * as SegmentedControlStories from "./SegmentedControl.stories";
# SegmentedControl
A segmented control component that allows users to select a single option from a set of mutually exclusive choices. It's visually similar to a button group where the selected item is highlighted. Unlike tabs, it doesn't have associated content panels.
## Features
- **Radio-like behavior**: Only one item can be selected at a time
- **Visual variants**: Accent (default) and Ghost styles
- **Icon support**: Optional icons can be added to items
- **Sizes**: Small and medium sizes available
- **Form integration**: Works with form labels, descriptions, and validation
- **Accessibility**: Built with proper ARIA attributes and keyboard navigation
## Basic Usage
```tsx
import { SegmentedControl } from "@webiny/admin-ui";
import { useState } from "react";
const MyComponent = () => {
const [value, setValue] = useState("option1");
return (
);
};
```
## With Icons
```tsx
import { SegmentedControl } from "@webiny/admin-ui";
import { Icon } from "@webiny/admin-ui";
},
{ label: "Unlock", value: "unlock", icon: },
{ label: "Settings", value: "settings", icon: }
]}
value={value}
onChange={setValue}
/>;
```
## Variants
### Accent (Default)
The accent variant uses the primary color for the selected state.
### Ghost
The ghost variant is designed for use on dark backgrounds, using a more subtle appearance.
## Form Integration
```tsx
```
## API
### SegmentedControl Props
| Prop | Type | Default | Description |
| ------------- | ------------------------------ | ---------- | ------------------------------- |
| `items` | `SegmentedControlItemParams[]` | - | Array of items to display |
| `value` | `string` | - | Currently selected value |
| `onChange` | `(value: string) => void` | - | Callback when selection changes |
| `variant` | `"accent" \| "ghost"` | `"accent"` | Visual style variant |
| `size` | `"sm" \| "md"` | `"md"` | Size of the control |
| `disabled` | `boolean` | `false` | Disable all items |
| `className` | `string` | - | Additional CSS class |
| `label` | `string \| React.ReactNode` | - | Form label |
| `description` | `string \| React.ReactNode` | - | Form description |
| `note` | `string \| React.ReactNode` | - | Form note |
| `required` | `boolean` | - | Show required indicator |
| `validation` | `object` | - | Validation state and message |
### SegmentedControlItemParams
| Prop | Type | Default | Description |
| ---------- | --------------------------- | ------- | -------------------------- |
| `label` | `string \| React.ReactNode` | - | Item label |
| `value` | `string \| number` | - | Item value |
| `disabled` | `boolean` | `false` | Disable this specific item |
| `icon` | `React.ReactNode` | - | Optional icon to display |
| `id` | `string` | - | Optional custom ID |
## Examples