Line data Source code
1 16 : <script setup lang="ts">
2 : import type { ToggleGroupItemProps } from 'reka-ui'
3 : import { ToggleGroupItem, useForwardProps } from 'reka-ui'
4 : import type { HTMLAttributes } from 'vue'
5 : import { computed, inject, ref } from 'vue'
6 :
7 : import { cn } from '@comfyorg/tailwind-utils'
8 :
9 : import type { ToggleGroupItemVariants } from './toggleGroup.variants'
10 : import {
11 : toggleGroupItemVariants,
12 : toggleGroupVariantKey
13 : } from './toggleGroup.variants'
14 :
15 : interface Props extends ToggleGroupItemProps {
16 : class?: HTMLAttributes['class']
17 : variant?: ToggleGroupItemVariants['variant']
18 : size?: ToggleGroupItemVariants['size']
19 : }
20 :
21 386 : const {
22 : class: className,
23 : variant,
24 : size = 'default',
25 : ...restProps
26 : } = defineProps<Props>()
27 :
28 386 : const contextVariant = inject(toggleGroupVariantKey, ref('default'))
29 :
30 386 : const forwardedProps = useForwardProps(restProps)
31 :
32 386 : const resolvedVariant = computed(
33 : () => variant ?? contextVariant.value ?? 'default'
34 : )
35 : </script>
36 :
37 : <template>
38 : <ToggleGroupItem
39 : v-bind="forwardedProps"
40 : :class="
41 : cn(
42 : toggleGroupItemVariants({ variant: resolvedVariant, size }),
43 : 'min-w-0 flex-none',
44 : className
45 : )
46 : "
47 : >
48 : <slot />
49 : </ToggleGroupItem>
50 : </template>
|