Documentation
Switch

Switch

An accessible toggle switch built on @radix-ui/react-switch. The thumb slides with a spring animation when toggled.

Installation

# Package
npm install @lumina-ui/react
 
# CLI
npx lumina-ui add switch
# deps: @radix-ui/react-switch framer-motion clsx

Usage

import { Switch, Label } from '@lumina-ui/react'
 
export default function Example() {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
      <Switch id="notifications" />
      <Label htmlFor="notifications">Enable notifications</Label>
    </div>
  )
}

Controlled

import { useState } from 'react'
import { Switch } from '@lumina-ui/react'
 
export default function Controlled() {
  const [enabled, setEnabled] = useState(false)
  return (
    <Switch checked={enabled} onCheckedChange={setEnabled} aria-label="Dark mode" />
  )
}

Props

PropTypeDescription
checkedbooleanControlled on/off state
defaultCheckedbooleanUncontrolled initial state
onCheckedChange(checked: boolean) => voidChange handler
disabledbooleanDisables the switch

Accessibility

  • role="switch" with aria-checked managed by Radix
  • Keyboard: Space toggles
  • Thumb spring animation disabled when prefers-reduced-motion is set