Veil UI
Components

Switch

A toggle for immediately applied settings, built on Radix Switch.

Installation

$ npx veil-ui@latest add switch

Usage

import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";

<div className="flex items-center gap-2">
  <Switch id="airplane" />
  <Label htmlFor="airplane">Airplane mode</Label>
</div>;

Examples

Basic

Sizes

Disabled

API reference

The package exports switch along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.

Accessibility

  • Switch exposes role="switch" and Space/Enter toggling; pair it with a Label for a discernible name.
  • Error and disabled states are exposed through native attributes and Radix data attributes.
  • Focus-visible rings follow the shared token system in both themes.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add switch --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { SwitchRoot, SwitchThumb } from "reka-ui";
import { computed } from "vue";

import { cn } from "@/lib/utils";

import {
  switchThumbVariants,
  switchVariants,
  type SwitchVariants,
} from "./variants";

const props = defineProps<{
  class?: string;
  size?: SwitchVariants["size"];
  disabled?: boolean;
}>();

const model = defineModel<boolean>({ default: false });

const rootClasses = computed(() =>
  cn(switchVariants({ size: props.size }), props.class),
);
const thumbClasses = computed(() => switchThumbVariants({ size: props.size }));
</script>

<template>
  <SwitchRoot
    v-model="model"
    data-slot="switch"
    :data-size="size ?? 'default'"
    :disabled="disabled"
    :class="rootClasses"
  >
    <SwitchThumb data-slot="switch-thumb" :class="thumbClasses" />
  </SwitchRoot>
</template>

On this page