Install
Pull Toggle from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { Toggle } from "@brika/clay";import { Toggle } from "@brika/clay/components/toggle";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
import { Toggle } from '@brika/clay/components/toggle';
import { Bold } from 'lucide-react';
/** A single toggle button that stays pressed until clicked again. */
export default function ToggleDefaultDemo() {
return (
<Toggle aria-label="Toggle bold">
<Bold />
</Toggle>
);
}Toggle, every way
Accessibility
- Carries
aria-pressedautomatically, AT announces "pressed" / "not pressed". - Icon-only toggles REQUIRE an
aria-label, there is no text fallback. - Use
variant="outline"to make the active state more visually distinct.
Theme tokens
Every CSS variable Toggle reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Toggle
without touching component code.
Toggle tokens
23 tokens--toggle-hover-containercolorvar(--muted)components.toggle.hoverContainerHover background of the toggle in its resting (off) state. Pairs with `hover-label` and the hover backdrop blur.
--toggle-hover-labelcolorvar(--muted-foreground)components.toggle.hoverLabelHover label color of the toggle in its resting (off) state.
--toggle-hover-bordercolorvar(--border)components.toggle.hoverBorderHover border color of the toggle in its resting (off) state.
--toggle-active-containercolorvar(--accent)components.toggle.activeContainerBackground of the toggle when pressed (`data-[state=on]`).
--toggle-active-labelcolorvar(--accent-foreground)components.toggle.activeLabelLabel color of the toggle when pressed (`data-[state=on]`).
--toggle-active-bordercolorvar(--border)components.toggle.activeBorderBorder color of the toggle when pressed (`data-[state=on]`).
--toggle-outline-bordercolorvar(--input)components.toggle.outlineBorderResting border color of the outline toggle variant. Hover and active states fall through to `hover-border` / `active-border`.
--toggle-radiusradiusvar(--radius-control)components.toggle.radiusToggle corner radius.
--toggle-heightsize2.25remcomponents.toggle.heightDefault toggle height.
--toggle-padding-xsizecalc(var(--spacing) * 3)components.toggle.paddingXInline padding inside the toggle.
--toggle-padding-ysizecalc(var(--spacing) * 2)components.toggle.paddingYBlock padding inside the toggle.
--toggle-gapsizecalc(var(--spacing) * 2)components.toggle.gapGap between adjacent children inside the toggle.
--toggle-border-widthborder-width0pxcomponents.toggle.borderWidthBorder width on the toggle. Set non-zero for outline-style variants.
--toggle-border-styleborder-stylesolidcomponents.toggle.borderStyleBorder style on the toggle (`solid`, `dashed`, `double`, `none`).
--toggle-font-familyfont-familyvar(--font-sans)components.toggle.fontFamilyTypeface for toggle.
--toggle-font-sizefont-sizevar(--text-body-md)components.toggle.fontSizeFont size for toggle.
--toggle-font-weightfont-weight500components.toggle.fontWeightFont weight for toggle.
--toggle-line-heightline-height1.25components.toggle.lineHeightLine height for toggle.
--toggle-letter-spacingletter-spacing0components.toggle.letterSpacingLetter spacing for toggle. Useful for caps labels.
--toggle-text-transformtext-transformnonecomponents.toggle.textTransformText transform for toggle (`uppercase`, `lowercase`, `capitalize`, `none`).
--toggle-backdrop-blurblur0pxcomponents.toggle.backdropBlurBackdrop blur applied to the toggle on hover and active (`data-[state=on]`). Set non-zero for a frosted-glass affordance, the resting state stays transparent.
--toggle-durationdurationvar(--motion-standard-duration)components.toggle.durationTransition duration for toggle state changes.
--toggle-easingeasingvar(--motion-standard-easing)components.toggle.easingTransition easing for toggle state changes.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.toggle, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"toggle": {
"paddingX": "calc(var(--spacing) * 3)"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-toggle-…) — see the
chips on each token row.
API reference
Props specific to Toggle. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.