Switch

A toggle control for binary choices with smooth animations.

Overview

The Switch component provides a toggle control for binary choices, offering a more visually distinct alternative to checkboxes for on/off or enable/disable settings. Built on Base UI primitives, it offers full keyboard navigation and accessibility features.

Usage

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

With Label

Always associate switches with descriptive labels for better accessibility and user experience:

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

Examples

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
checkedbooleanThe controlled checked state of the switch.
defaultCheckedbooleanfalseThe default checked state when uncontrolled.
onCheckedChange(checked: boolean) => voidCallback fired when the checked state changes.
size"sm" | "md" | "lg""md"The size of the switch.
disabledbooleanfalseWhether the switch is disabled.
requiredbooleanfalseWhether the switch is required.
namestringThe name of the switch for form submission.
valuestring"on"The value of the switch when in a form.
idstringThe HTML id for label association.
classNamestringAdditional CSS classes for the switch.
childrenReact.ReactNodeCustom thumb content (defaults to <code>&lt;SwitchThumb /&gt;</code>).

URL State Props

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

PropTypeDefaultDescription
paramNamestringURL parameter name for syncing state with URL. Enables URL state management.
onUrlValueChange(checked: boolean) => voidCallback when URL parameter value changes.
paramClearOnDefaultbooleantrueRemove URL param when value equals default.
paramDebouncenumberDebounce URL updates in milliseconds.
paramThrottlenumberThrottle URL updates in milliseconds.

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