switch-item.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script setup lang="ts">
  2. import { useSlots } from 'vue';
  3. import { MdiQuestionMarkCircleOutline } from '@vben-core/icons';
  4. import { Switch, VbenTooltip } from '@vben-core/shadcn-ui';
  5. defineOptions({
  6. name: 'PreferenceSwitchItem',
  7. });
  8. withDefaults(defineProps<{ disabled?: boolean }>(), {
  9. disabled: false,
  10. });
  11. const checked = defineModel<boolean>();
  12. const slots = useSlots();
  13. function handleClick() {
  14. checked.value = !checked.value;
  15. }
  16. </script>
  17. <template>
  18. <div
  19. :class="{
  20. 'pointer-events-none opacity-50': disabled,
  21. }"
  22. class="hover:bg-accent my-1 flex w-full items-center justify-between rounded-md px-2 py-2.5"
  23. @click="handleClick"
  24. >
  25. <span class="flex items-center text-sm">
  26. <slot></slot>
  27. <VbenTooltip v-if="slots.tip" side="bottom">
  28. <template #trigger>
  29. <MdiQuestionMarkCircleOutline class="ml-1 cursor-help" />
  30. </template>
  31. <slot name="tip"></slot>
  32. </VbenTooltip>
  33. </span>
  34. <span v-if="$slots.shortcut" class="ml-auto mr-2 text-xs opacity-60">
  35. <slot name="shortcut"></slot>
  36. </span>
  37. <Switch v-model:checked="checked" @click.stop />
  38. </div>
  39. </template>