select-item.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <script setup lang="ts">
  2. import type { SelectOption } from '@vben/types';
  3. import { useSlots } from 'vue';
  4. import { CircleHelp } from '@vben/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. tip?: string;
  22. }>(),
  23. {
  24. disabled: false,
  25. placeholder: '',
  26. tip: '',
  27. items: () => [],
  28. },
  29. );
  30. const selectValue = defineModel<string>();
  31. const slots = useSlots();
  32. </script>
  33. <template>
  34. <div
  35. :class="{
  36. 'hover:bg-accent': !(slots.tip || tip),
  37. 'pointer-events-none opacity-50': disabled,
  38. }"
  39. class="my-1 flex w-full items-center justify-between rounded-md px-2 py-1"
  40. >
  41. <span class="flex items-center text-sm">
  42. <slot></slot>
  43. <VbenTooltip v-if="slots.tip || tip" side="bottom">
  44. <template #trigger>
  45. <CircleHelp class="ml-1 size-3 cursor-help" />
  46. </template>
  47. <slot name="tip">
  48. <template v-if="tip">
  49. <p v-for="(line, index) in tip.split('\n')" :key="index">
  50. {{ line }}
  51. </p>
  52. </template>
  53. </slot>
  54. </VbenTooltip>
  55. </span>
  56. <Select v-model="selectValue">
  57. <SelectTrigger class="h-8 w-41.25">
  58. <SelectValue :placeholder="placeholder" />
  59. </SelectTrigger>
  60. <SelectContent>
  61. <template v-for="item in items" :key="item.value">
  62. <SelectItem :value="item.value"> {{ item.label }} </SelectItem>
  63. </template>
  64. </SelectContent>
  65. </Select>
  66. </div>
  67. </template>