Skip to content

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 switch

Imports ​

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 ​

PropTypeDefaultDescription
checkedboolean-Controlled checked state.
defaultCheckedboolean-Initial checked state.
sizeSwitchSize
Values: sm, md, lg
mdSwitch size.
requiredboolean-Marks the switch as required.
ariaLabelstring-Accessible label for unlabeled switches.
ariaDescribedbystring-ID reference for additional accessible description.

Events ​

EventReact propDetailDescription
checked-changeonCheckedChangechecked: boolean, nativeEvent: EventEmitted when checked state changes.

Slots ​

SlotDescription
defaultLabel content.

Styling ​

Uses Tailwind: yes

Theme tokens:

  • bg-primary
  • bg-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/switch
  • class-variance-authority

Registry dependencies:

  • cn
  • globals

Files:

  • templates/react/switch.tsx → components/ui/switch.tsx
  • templates/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>
}

Released under the MIT License.