select-item.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <script setup lang="ts">
  2. import type { SelectOption } from '@vben-core/typings';
  3. import { useSlots } from 'vue';
  4. import { CircleHelp } from '@vben-core/icons';
  5. import {
  6. Select,
  7. SelectContent,
  8. SelectItem,
  9. SelectTrigger,
  10. SelectValue,
  11. VbenTooltip,
  12. } from '@vben-core/shadcn-ui';
  13. defineOptions({
  14. name: 'PreferenceSelectItem',
  15. });
  16. withDefaults(
  17. defineProps<{
  18. disabled?: boolean;
  19. items?: SelectOption[];
  20. placeholder?: string;
  21. }>(),
  22. {
  23. disabled: false,
  24. placeholder: '',
  25. items: () => [],
  26. },
  27. );
  28. const selectValue = defineModel<string>();
  29. const slots = useSlots();
  30. </script>
  31. <template>
  32. <div
  33. :class="{
  34. 'hover:bg-accent': !slots.tip,
  35. 'pointer-events-none opacity-50': disabled,
  36. }"
  37. class="my-1 flex w-full items-center justify-between rounded-md px-2 py-1"
  38. >
  39. <span class="flex items-center text-sm">
  40. <slot></slot>
  41. <VbenTooltip v-if="slots.tip" side="bottom">
  42. <template #trigger>
  43. <CircleHelp class="ml-1 size-3 cursor-help" />
  44. </template>
  45. <slot name="tip"></slot>
  46. </VbenTooltip>
  47. </span>
  48. <Select v-model="selectValue">
  49. <SelectTrigger class="h-8 w-[165px]">
  50. <SelectValue :placeholder="placeholder" />
  51. </SelectTrigger>
  52. <SelectContent>
  53. <template v-for="item in items" :key="item.value">
  54. <SelectItem :value="item.value"> {{ item.label }} </SelectItem>
  55. </template>
  56. </SelectContent>
  57. </Select>
  58. </div>
  59. </template>