| 1 | <script setup lang="ts"> |
| 2 | import type { PropType } from 'vue' |
| 3 | import type { SelectionItem } from './types' |
| 4 | import { useVModel } from '@vueuse/core' |
| 5 | |
| 6 | const props = defineProps({ |
| 7 | modelValue: { |
| 8 | type: [Object, String, Number, Boolean] as PropType<any>, |
| 9 | }, |
| 10 | title: { |
| 11 | type: String, |
| 12 | }, |
| 13 | items: { |
| 14 | type: Array as PropType<SelectionItem<any>[]>, |
| 15 | }, |
| 16 | }) |
| 17 | |
| 18 | const emit = defineEmits<{ |
| 19 | (e: any): void |
| 20 | }>() |
| 21 | const value = useVModel(props, 'modelValue', emit, { passive: true }) |
| 22 | </script> |
| 23 | |
| 24 | <template> |
| 25 | <div class="select-list"> |
| 26 | <div class="title"> |
| 27 | {{ title }} |
| 28 | </div> |
| 29 | <div class="items"> |
| 30 | <div |
| 31 | v-for="item of items" |
| 32 | :key="item.value" |
| 33 | class="item" |
| 34 | :class="{ active: value === item.value }" |
| 35 | @click="() => { value = item.value; item.onClick?.() }" |
| 36 | > |
| 37 | <div class="i-carbon:checkmark text-green-500 mya" :class="{ 'opacity-0': value !== item.value }" /> |
| 38 | <div :class="{ 'opacity-50': value !== item.value }"> |
| 39 | {{ item.display || item.value }} |
| 40 | </div> |
| 41 | </div> |
| 42 | </div> |
| 43 | </div> |
| 44 | </template> |
| 45 | |
| 46 | <style lang="postcss" scoped> |
| 47 | .item { |
| 48 | @apply flex rounded whitespace-nowrap py-1 gap-1 px-2 cursor-default hover:bg-gray-400 hover:bg-opacity-10; |
| 49 | } |
| 50 | |
| 51 | .title { |
| 52 | @apply text-sm op75 px3 py1 select-none text-nowrap font-bold; |
| 53 | } |
| 54 | </style> |
| 55 |