primitives
Switch
Switch — базовый примитив RevueUI (Reka UI + shadcn-совместимый API).
Загрузка превью…
src/ui/switch/Switch.vue
<!--
Radix `Switch` → Reka UI `SwitchRoot`/`SwitchThumb`, тот же примитив.
-->
<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { computed } from "vue"
import { SwitchRoot, SwitchThumb, type SwitchRootEmits, type SwitchRootProps, useForwardPropsEmits } from "reka-ui"
import { cn } from "@/lib/utils"
const props = withDefaults(
defineProps<
SwitchRootProps & {
/** Доп. классы. Имя `class` — соглашение shadcn-vue (не `className`). */
class?: HTMLAttributes["class"]
size?: "sm" | "default"
}
>(),
{
size: "default",
}
)
const emits = defineEmits<SwitchRootEmits>()
const delegatedProps = computed(() => {
const { class: _class, size: _size, ...delegated } = props
return delegated
})
const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>
<template>
<SwitchRoot
data-slot="switch"
:data-size="props.size"
v-bind="forwarded"
:class="
cn(
'cn-switch peer group/switch relative inline-flex items-center transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 data-disabled:cursor-not-allowed data-disabled:opacity-50',
props.class
)
"
>
<SwitchThumb
data-slot="switch-thumb"
class="cn-switch-thumb pointer-events-none block ring-0 transition-transform"
/>
</SwitchRoot>
</template>
src/ui/switch/index.ts
export { default as Switch } from "./Switch.vue"
Установка
npx shadcn-vue@latest add https://revueui.rootapi.dev/r/switch.jsonЗависимости реестра
npm-зависимости
- reka-ui
Источник: порт из ReUI (Keenthemes, MIT)