Line data Source code
1 16 : <script setup lang="ts" generic="T extends string">
2 : import { createReusableTemplate } from '@vueuse/core'
3 : import { DropdownMenuRadioGroup } from 'reka-ui'
4 :
5 : import TextTooltip from '@comfyorg/design-system/tooltip/TextTooltip'
6 :
7 : import MenuItemContent from './MenuItemContent.vue'
8 : import MenuRadioItem from './MenuRadioItem.vue'
9 : import type { MenuRadioOption } from './types'
10 :
11 : defineProps<{
12 : options: MenuRadioOption<T>[]
13 : }>()
14 :
15 2355 : const selected = defineModel<T>({ required: true })
16 16 : const emit = defineEmits<{ select: [event: Event] }>()
17 :
18 16 : const [DefineItem, ReuseItem] = createReusableTemplate<{
19 : option: MenuRadioOption<T>
20 : }>({
21 : props: { option: { type: Object, required: true } }
22 : })
23 :
24 6 : function select(option: MenuRadioOption<T>, event: Event) {
25 6 : selected.value = option.value
26 6 : option.command?.()
27 6 : emit('select', event)
28 : }
29 16 : </script>
30 :
31 : <template>
32 : <DefineItem v-slot="{ option }">
33 : <MenuRadioItem :value="option.value" @select="select(option, $event)">
34 : <MenuItemContent
35 : :item="{
36 : label: option.label,
37 : icon: option.icon,
38 : checked: selected === option.value
39 : }"
40 : :has-submenu="false"
41 : />
42 : </MenuRadioItem>
43 : </DefineItem>
44 : <DropdownMenuRadioGroup :model-value="selected">
45 68 : <template v-for="option in options" :key="option.value">
46 : <TextTooltip v-if="option.tooltip" :text="option.tooltip" side="right">
47 : <ReuseItem :option />
48 : </TextTooltip>
49 : <ReuseItem v-else :option />
50 : </template>
51 : </DropdownMenuRadioGroup>
52 : </template>
|