switch
shadcn-vue/switchFreeComponent
shadcn-vue publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shadcn-vue on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-vue.com/r/styles/new-york/switch.jsonSource
1<script setup lang="ts">2import type { SwitchRootEmits, SwitchRootProps } from "reka-ui"3import type { HTMLAttributes } from "vue"4import { reactiveOmit } from "@vueuse/core"5import {6 SwitchRoot,7 SwitchThumb,8 useForwardPropsEmits,9} from "reka-ui"10import { cn } from "@/lib/utils"1112const props = defineProps<SwitchRootProps & { class?: HTMLAttributes["class"] }>()1314const emits = defineEmits<SwitchRootEmits>()1516const delegatedProps = reactiveOmit(props, "class")1718const forwarded = useForwardPropsEmits(delegatedProps, emits)19</script>2021<template>22 <SwitchRoot23 v-bind="forwarded"24 :class="cn(25 'peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',26 props.class,27 )"28 >29 <SwitchThumb30 :class="cn('pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0')"31 >32 <slot name="thumb" />33 </SwitchThumb>34 </SwitchRoot>35</template>
What it pulls in
npm packages
Files it writes
More from shadcn-vue
All 65 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn-vue | Components | Free | 2 deps · 5 files | |
| alertalert | shadcn-vue | Components | Free | no deps · 4 files | |
| alert-dialogalert-dialog | shadcn-vue | Components | Free | 2 deps · 10 files | |
| aspect-ratioaspect-ratio | shadcn-vue | Components | Free | 1 dep · 2 files | |
| attachmentattachment | shadcn-vue | Components | Free | 1 dep · 10 files | |
| avataravatar | shadcn-vue | Components | Free | 2 deps · 4 files | |
| badgebadge | shadcn-vue | Components | Free | 2 deps · 2 files | |
| breadcrumbbreadcrumb | shadcn-vue | Components | Free | 1 dep · 8 files |
