ToggleGroup
Row of toggles; single or multiple selection (text alignment, view mode, formatting).
Code
import * as React from 'react';
import { Stack, ToggleGroup } from '@fruit-labs/design';
export default function Demo() {
return (
<Stack direction="row" gap={4}>
<ToggleGroup
label="View"
defaultValue="grid"
items={[
{
value: 'grid',
icon: 'grid',
label: 'Grid',
},
{
value: 'list',
icon: 'menu',
label: 'List',
},
{
value: 'table',
icon: 'table',
label: 'Table',
},
]}
/>
<ToggleGroup
label="Filters"
type="multiple"
defaultValue={['star']}
items={[
{
value: 'star',
icon: 'star',
label: 'Starred',
},
{
value: 'lock',
icon: 'lock',
label: 'Private',
},
]}
/>
</Stack>
);
}Install
From npm:
npm install @fruit-labs/design
import { ToggleGroup } from '@fruit-labs/design';Or copy the TypeScript source into your project:
npx shadcn@latest add https://design.fruitlabs.online/r/toggle-group.jsonGuidelines
- Use SegmentedControl for labelled view switching; ToggleGroup for icon tool sets.
Props
| Prop | Type | Required |
|---|---|---|
items | Array<{ value: string; icon?: string; text?: React.ReactNode; label?: string; disabled?: boolean }> | Yes |
type | 'single' | 'multiple' | No |
value | string | string[] | No |
defaultValue | string | string[] | No |
onChange | (value: any) => void | No |
allowEmpty | boolean | No |
label | string | No |
className | string | No |