shadcn-vue/apps/www/src/content/docs/components/switch.md
2024-11-22 17:58:53 +08:00

1.1 KiB

title description source primitive
Switch A control that allows the user to toggle between checked and not checked. apps/www/registry/default/ui/switch https://www.reka-ui.com/docs/components/switch.html

Installation

npx shadcn-vue@latest add switch

<template #Manual>

Install the following dependency:

npm install reka-ui

Copy and paste the following code into your project

<<< @/registry/default/ui/switch/Switch.vue

Usage

<script setup lang="ts">
import { Switch } from '@/components/ui/switch'
</script>

<template>
  <Switch />
</template>

Add icon inside switch thumb

<template>
  <Switch :model-value="isDark" @update:model-value="toggleTheme">
    <template #thumb>
      <Icon v-if="isDark" icon="lucide:moon" class="size-3" />
      <Icon v-else icon="lucide:sun" class="size-3" />
    </template>
  </Switch>
</template>

Examples

Form