Skip to content

Switch

An on/off setting that applies at once, with a label slot and a thumb that settles on a spring.

Base UI1.4 kB gzipSource Registry JSON

Switch playground

Props

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/switch.json

The CLI writes components/ikada/switch.tsx and merges the ikada theme into your CSS. Or take it from the package: import { Switch } from "@sproutboat/ikada";

Usage

import { Switch } from "@/components/ikada/switch";

<Switch label="Auto-promote" defaultChecked />

Examples

States

Press and hold: the thumb squishes toward its travel, then rides the snappy spring.
Focused

Without a label

Without a visible label, pass aria-label.

Props

SwitchProps
PropTypeDescription
classNamestringClasses merged onto the root element, after ikada's own.
labelReactNodeVisible label beside the switch. Without it, pass aria-label.
styleCSSProperties | ((state: SwitchRootState) => CSSProperties)Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SwitchRootState>Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

Also takes every prop of Omit<ComponentProps<typeof BaseSwitch.Root>, "className" | "children">.

Source: src/components/switch.tsx