Form

Switch

Toggles a single setting on or off.

Imports

Use the same component slug for React, Vue, and style token lookup. Do not import components from package roots.

import { Switch } from "@line/abc-def-react/switch";
<script setup lang="ts">
import { Switch } from "@line/abc-def-vue/switch";
</script>

Shadcn references

Compare the corresponding shadcn React and Vue documentation for the same component slug.

Basic usage

import { Switch } from "@line/abc-def-react/switch";
import { Label } from "@line/abc-def-react/label";

export function Example() {
  return (
    <div className="flex items-center gap-2">
      <Switch id="sync" defaultChecked />
      <Label htmlFor="sync">Sync tokens</Label>
    </div>
  );
}
<script setup lang="ts">
import { Field, FieldLabel } from "@line/abc-def-vue/field";
import { Switch } from "@line/abc-def-vue/switch";
</script>

<template>
  <Field orientation="horizontal">
    <Switch id="sync" default-checked />
    <FieldLabel for="sync">Sync tokens</FieldLabel>
  </Field>
</template>

Component tokens

Component TokenSemantic TokenDefault Primitive Token
--switch-ring--ring--color-zinc-400
--switch-border-destructive--destructive--color-red-50
--switch-bg-checked--primary--color-zinc-900
--switch-bg-unchecked--border-input--color-zinc-200
--switch-thumb-bg-checked--background--color-white
--switch-thumb-bg-unchecked--background--color-white

Composition exports

Switch

Usage notes

  • Use for immediate settings.
  • Use checkbox when the value is part of a form submission group.
  • Related component tokens use the `switch` token group in `@line/abc-def-styles/css`.