Forms
Switch
40 × 24 track with a 16px knob and 4px inset.
react-aria-components
Preview
"use client";
import { Switch } from "@/components/ui/switch";
export default function Example() {
return (
<div className="flex flex-col gap-3">
<Switch defaultSelected>Auto-enrich new prospects</Switch>
<Switch>Pause sequences on reply</Switch>
<Switch isDisabled>Sync to Salesforce</Switch>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-componentsCreate a
switch.tsxfile and paste the following code into it.src/components/ui/switch.tsx"use client"; import type { ReactNode } from "react"; import { Switch as AriaSwitch, type SwitchProps as AriaSwitchProps } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface SwitchProps extends Omit<AriaSwitchProps, "children" | "className"> { children?: ReactNode; className?: string; } /** Track 40 × 24 with a 16px knob and 4px inset. */ export function Switch({ children, className, ...props }: SwitchProps) { return ( <AriaSwitch {...props} className={cx("group flex cursor-default items-center gap-2.5 text-base text-fg data-disabled:text-fg-disabled", className)}> <span className={cx( "flex h-6 w-10 shrink-0 items-center rounded-full bg-chart-neutral p-1 transition-colors", "group-data-hovered:bg-fg-disabled group-data-focus-visible:shadow-focus", "group-data-selected:bg-accent group-data-selected:group-data-hovered:bg-accent-hover", "group-data-disabled:bg-muted", )} > <span className="size-4 rounded-full bg-white shadow-[0_1px_2px_rgb(0_0_0/0.12)] transition-transform duration-200 group-data-selected:translate-x-4 group-data-disabled:shadow-none" /> </span> {children} </AriaSwitch> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.