shadcn-vue/apps/www/src/content/docs/components/switch.md
2024-10-26 20:23:08 +03:00

1.1 KiB

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

Installation

npx shadcn-vue@latest add switch

<template #Manual>

Install the following dependency:

npm install radix-vue

Copy and paste the following code into your project

<<< @/lib/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 :checked="isDark" @update:checked="toggleTheme">
      <template #thumb>
          <Icon v-if="isDark" icon="lucide:moon" class="size-3"></Icon>
          <Icon v-else icon="lucide:sun" class="size-3"></Icon>
      </template>
  </Switch>
</template>

Examples

Form