Line data Source code
1 16 : <script setup lang="ts">
2 : import type { ToggleGroupRootEmits, ToggleGroupRootProps } from 'reka-ui'
3 : import { ToggleGroupRoot, useForwardProps } from 'reka-ui'
4 : import type { HTMLAttributes } from 'vue'
5 : import { provide, toRef } from 'vue'
6 :
7 : import { cn } from '@comfyorg/tailwind-utils'
8 :
9 : import type { ToggleGroupVariants } from './toggleGroup.variants'
10 : import {
11 : toggleGroupVariantKey,
12 : toggleGroupVariants
13 : } from './toggleGroup.variants'
14 :
15 : interface Props extends ToggleGroupRootProps {
16 : class?: HTMLAttributes['class']
17 : variant?: ToggleGroupVariants['variant']
18 : allowEmpty?: boolean
19 : }
20 :
21 2355 : const {
22 : class: className,
23 : variant = 'default',
24 : allowEmpty = true,
25 : ...restProps
26 : } = defineProps<Props>()
27 :
28 110 : const emits = defineEmits<ToggleGroupRootEmits>()
29 :
30 110 : const forwarded = useForwardProps(restProps)
31 :
32 36 : function updateModelValue(value: ToggleGroupRootEmits['update:modelValue'][0]) {
33 36 : if (!allowEmpty && restProps.type === 'single' && value == null) return
34 23 : emits('update:modelValue', value)
35 : }
36 :
37 110 : provide(
38 : toggleGroupVariantKey,
39 : toRef(() => variant)
40 : )
41 110 : </script>
42 :
43 : <template>
44 133 : <ToggleGroupRoot
45 : v-bind="forwarded"
46 : :class="cn(toggleGroupVariants({ variant }), className)"
47 : @update:model-value="updateModelValue"
48 : >
49 : <slot />
50 : </ToggleGroupRoot>
51 : </template>
|