Skip to content
Klarhimmel UI

Toggle

npx shadcn add @klarhimmel/toggle

Examples

  • Basic

  • States

  • Toolbar

DetailsAbout, usage, props and more

A button that stays pressed: bold, favourite, mute.

When to use

  • Use for

    A tool or preference that stays on: bold, favourite, mute.

  • Not for

    A setting in a list. Use Switch. A choice submitted with a form. Use Checkbox.

  • Pairs with

    Icons, Toggle group, Tooltip.

Preview

toggle.tsx
import { Bold } from 'lucide-react';
import { Theme } from '@/components/klarhimmel/theme/style';
import { Toggle } from '@/components/klarhimmel/ui/toggle';

export default function Example() {
  return (
    <Theme theme="brand">
      <Toggle aria-label="Bold"><Bold aria-hidden /></Toggle>
    </Theme>
  );
}

Import

Import

import { Toggle } from '@/components/klarhimmel/ui/toggle';
Files
toggle.tsx, in components/klarhimmel/ui/. With it: theme, utils. npm: radix-ui.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

Props

PropTypeDefaultDescription
pressed / onPressedChangeboolean / (pressed: boolean) => void-Controlled or uncontrolled state.
aria-labelstring-Required for an icon-only toggle.
disabledbooleanfalsePrevents interaction.
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
Enter / SpacePresses or releases it
TabMoves focus

aria-pressed carries the state. An icon-only toggle needs an aria-label that stays the same when pressed.

Accessibility