Switch

A toggle control for binary choices with smooth animations.

Overview

The Switch component provides a toggle control for binary choices. The track lands two surface levels above its parent, unchecked hover follows the shared surface hover system, and the thumb resets to surface-1 while keeping its border two levels above the track.

Usage

import { Label } from "@tilt-legal/cubitt-components/label";
import { Switch } from "@tilt-legal/cubitt-components/switch";
<Switch />

Always associate switches with descriptive labels for better accessibility and to make label hover trigger the same interaction state as the switch.

<Label orientation="horizontal">
  <Switch />
  Enable notifications
</Label>

URL State

Provide paramName to sync the switch state with the current URL.

<Label orientation="horizontal">
  <Switch defaultChecked={false} paramName="notifications" />
  Enable notifications
</Label>

Examples

States

Default

Sizes

Checked by Default

Disabled

With Description

Settings Card

URL State

Sync a switch state with the URL. Try toggling the switch and refreshing the page or sharing the URL.

API Reference

Switch

The root component for creating switches with multiple size variants.

PropTypeDefaultDescription
checkedboolean-Controlled checked state.
defaultCheckedbooleanfalseInitial checked state when uncontrolled.
onCheckedChange(checked: boolean, eventDetails: SwitchPrimitive.Root.ChangeEventDetails) => void-Called when the checked state changes.
size"sm" | "md" | "lg""md"Switch size.
disabledbooleanfalseDisables the switch.
requiredbooleanfalseMarks the switch as required for form submission.
namestring-Form field name.
valuestring"on"Form value when checked.
idstring-HTML id for explicit label association.
classNamestring-Additional classes for the switch root.
childrenReact.ReactNode<SwitchThumb />Custom thumb content.

URL State Props

When provided with a paramName, the switch will sync its state with URL parameters via TanStack Router search params.

PropTypeDefaultDescription
paramNamestring-URL parameter name for syncing state.
paramValueboolean-Controlled URL state value.
onUrlValueChange(checked: boolean | null) => void-Called when the URL value changes.
paramClearOnDefaultbooleantrueRemoves the URL parameter when value equals the default.
paramDebouncenumber-Debounce window for URL updates.
paramThrottlenumber-Throttle window for URL updates.

SwitchThumb

The thumb component that slides within the switch track.

PropTypeDefaultDescription
size"sm" | "md" | "lg"Override the size from parent Switch.
classNamestringAdditional CSS classes for the thumb.

On this page