toggle-item.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script setup lang="ts">
  2. import type { SelectOption } from '@vben/types';
  3. import { ToggleGroup, ToggleGroupItem } from '@vben-core/shadcn-ui';
  4. defineOptions({
  5. name: 'PreferenceToggleItem',
  6. });
  7. withDefaults(defineProps<{ disabled?: boolean; items: SelectOption[] }>(), {
  8. disabled: false,
  9. items: () => [],
  10. });
  11. const modelValue = defineModel<string>();
  12. </script>
  13. <template>
  14. <div
  15. :class="{
  16. 'pointer-events-none opacity-50': disabled,
  17. }"
  18. class="hover:bg-accent flex w-full items-center justify-between rounded-md px-2 py-2"
  19. disabled
  20. >
  21. <span class="text-sm">
  22. <slot></slot>
  23. </span>
  24. <ToggleGroup
  25. v-model="modelValue"
  26. class="gap-2"
  27. size="sm"
  28. type="single"
  29. variant="outline"
  30. >
  31. <template v-for="item in items" :key="item.value">
  32. <ToggleGroupItem
  33. :value="item.value"
  34. class="data-[state=on]:bg-primary data-[state=on]:text-primary-foreground h-7 rounded-sm"
  35. >
  36. {{ item.label }}
  37. </ToggleGroupItem>
  38. </template>
  39. </ToggleGroup>
  40. </div>
  41. </template>