SnowballSH Foundation UI

Switch

Pick a framework. Both use the same recipe, so the styling matches exactly.

Switch props for React
PropTypeDefaultDescription
checkedbooleanCurrent state. In Svelte it is bindable with bind:checked.
onCheckedChange(checked: boolean) => voidCalled after each toggle.
disabledbooleanBlocks toggling and dims the control.

Also takes className and children. Anything else passes through to the button.

switch.demo.tsx
import { useState } from "react";
import { Switch } from "../react/index.js";

export default function SwitchDemo() {
  const [on, setOn] = useState(true);
  return (
    <div className="flex items-center gap-4">
      <label className="flex items-center gap-2 text-ink">
        <Switch checked={on} onCheckedChange={setOn} aria-label="Snow mode" />
        Snow mode {on ? "on" : "off"}
      </label>
      <Switch checked={false} disabled aria-label="Disabled switch" />
    </div>
  );
}