Peach: Local-first video metadata scraper and media manager.
Switch
Choose between a set of options.
Default
Ensure the width of each item is wide enough to prevent jumping when active.
import { Switch, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
export function Component(): JSX.Element {
return (
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="default">
<SwitchControl defaultChecked label="Source" value="source" />
<SwitchControl label="Output" value="output" />
</Switch>
</div>
);
}
Disabled
import { Switch, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
export function Component(): JSX.Element {
return (
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="view-mode">
<SwitchControl defaultChecked disabled label="Source" value="source" />
<SwitchControl disabled label="Output" value="output" />
</Switch>
</div>
);
}
Sizes
import { Switch, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
export function Component(): JSX.Element {
return (
<div className="flex relative min-w-px max-w-full flex-col lg:flex-row lg:flex-wrap flex-1">
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="sizes-small" size="small">
<SwitchControl defaultChecked label="Source" value="source" />
<SwitchControl label="Output" value="output" />
</Switch>
</div>
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="sizes-default">
<SwitchControl defaultChecked label="Source" value="source" />
<SwitchControl label="Output" value="output" />
</Switch>
</div>
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="sizes-large" size="large">
<SwitchControl defaultChecked label="Source" value="source" />
<SwitchControl label="Output" value="output" />
</Switch>
</div>
</div>
);
}
Full width
import { Switch, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
export function Component(): JSX.Element {
return (
<Switch name="full-width" style={{ width: '100%' }}>
<SwitchControl
defaultChecked
label="Source"
size="large"
value="source"
/>
<SwitchControl label="Output" size="large" value="output" />
</Switch>
);
}
Tooltip
import { Switch, Tooltip, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
export function Component(): JSX.Element {
return (
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="view-mode">
<Tooltip desktopOnly text="View Source">
<SwitchControl
defaultChecked
label="Source"
name="tooltip"
size="large"
value="source"
/>
</Tooltip>
<Tooltip desktopOnly text="View Output">
<SwitchControl
label="Output"
name="tooltip"
size="large"
value="output"
/>
</Tooltip>
</Switch>
</div>
);
}
Icon
import { Switch, SwitchControl } from '@vercel/geistcn/components';
import type { JSX } from 'react';
import {
IconGridSquare,
IconListUnordered,
} from '@vercel/geistcn-assets/icons';
export function Component(): JSX.Element {
return (
<div className="flex relative min-w-px max-w-full flex-col lg:flex-row lg:flex-wrap flex-1">
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="icons-small" size="small">
<SwitchControl
defaultChecked
icon={<IconGridSquare />}
value="source"
/>
<SwitchControl icon={<IconListUnordered />} value="output" />
</Switch>
</div>
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="icons-default">
<SwitchControl
defaultChecked
icon={<IconGridSquare />}
value="source"
/>
<SwitchControl icon={<IconListUnordered />} value="output" />
</Switch>
</div>
<div className="flex relative min-w-px max-w-full flex-col items-start flex-1">
<Switch name="icons-large" size="large">
<SwitchControl
defaultChecked
icon={<IconGridSquare />}
value="source"
/>
<SwitchControl icon={<IconListUnordered />} value="output" />
</Switch>
</div>
</div>
);
}
Best Practices
- Use Switch as a segmented selector for 2–3 mutually exclusive options that show different views of the same surface, like
SourcevsOutput. - For a boolean on/off setting, use
Toggle. Switch implements radio semantics, so two options stay mutually exclusive rather than reading as a checkbox. - Past 3 options or when labels grow beyond a couple of words, switch to
Tabsor aSelect. - Pass a
nameso the underlying radios are grouped; without it, more than one option can appear selected at once. - Set
defaultChecked(or controlledchecked) on exactly oneSwitch.Controlso the group has a defined initial state. - Pad each
Switch.Controlso the widest label fits without the active pill resizing on selection. Test with the longest copy in the set. - Title Case each
Switch.Controllabel. Keep labels to one or two words and parallel:Source/Output, notSource/Show output. - Always provide a
labelon everySwitch.Control, even when aniconcarries the meaning, so screen readers announce the option. The component renders it asgeist-sr-onlyfor icon-only controls. - Pair an icon-only Switch with a
Tooltipon each control so sighted users get the same label assistive tech receives.