Switch

An on/off toggle for settings that apply immediately.

Status: stable. Category: Forms.

import { Switch } from '@glyphui/ui'

Exports: Switch, switchStyles.

Notes

  • Use a Switch for instant settings and a Checkbox for choices submitted with a form.

Switch props

PropTypeDefaultDescription
asChildboolean
size"sm" | "md"

Example: Settings list

import { Field, Switch } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="grid max-w-sm gap-4">
      <Field
        orientation="horizontal"
        label="Product updates"
        description="A short email when we ship."
      >
        <Switch defaultChecked />
      </Field>
      <Field orientation="horizontal" label="Weekly digest" description="Every Monday at 9:00.">
        <Switch />
      </Field>
    </div>
  )
}

Example: Sizes

import { Switch } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex items-center gap-4">
      <Switch size="sm" aria-label="Small switch" defaultChecked />
      <Switch size="md" aria-label="Medium switch" defaultChecked />
    </div>
  )
}

Live page: https://glyphui.xyz/components/switch