Switch
Styled switch component built on the zw-switch primitive.
@zeus-web/switchData Entryzweb add switchGenerated
Playground
Source
Choose the framework entry that matches your application.
html
<script type="module">
import '@zeus-web/switch/wc/auto'
</script>
<zw-switch default-checked>Dark mode</zw-switch>tsx
import { Switch } from '@zeus-web/switch/react'
export function SwitchExample() {
return <Switch defaultChecked>Dark mode</Switch>
}vue
<script setup lang="ts">
import { Switch } from '@zeus-web/switch/vue'
</script>
<template>
<Switch default-checked>Dark mode</Switch>
</template>Add
bash
zweb add switchImports
Styled registry component:
tsx
import { Switch } from '@/components/ui/switch'Primitive React wrapper:
tsx
import { Switch } from '@zeus-web/switch/react'Web Component entry:
ts
import '@zeus-web/switch/wc/auto'Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | - | Controlled checked state. |
defaultChecked | boolean | - | Initial checked state. |
size | SwitchSizeValues: sm, md, lg | md | Switch size. |
required | boolean | - | Marks the switch as required. |
ariaLabel | string | - | Accessible label for unlabeled switches. |
ariaDescribedby | string | - | ID reference for additional accessible description. |
Events
| Event | React prop | Detail | Description |
|---|---|---|---|
checked-change | onCheckedChange | checked: boolean, nativeEvent: Event | Emitted when checked state changes. |
Slots
| Slot | Description |
|---|---|
default | Label content. |
Styling
Uses Tailwind: yes
Theme tokens:
bg-primarybg-input
Internal selectors:
[&_[data-slot=switch-track]][&_[data-slot=switch-thumb]]
Registry
Registry source: available.
Add command: zweb add switch
Type: component
Dependencies:
@zeus-web/switchclass-variance-authority
Registry dependencies:
cnglobals
Files:
templates/react/switch.tsx→components/ui/switch.tsxtemplates/vue/switch.ts→components/ui/switch.ts
AI usage rules
Do:
- Use Switch for on/off settings.
- Use Checkbox instead when the field is part of a multi-select list.
Do not:
- Do not use Switch for submitting an immediate destructive action.
Examples
React styled usage
tsx
import { Switch } from '@/components/ui/switch'
export function Example() {
return <Switch>Enable notifications</Switch>
}