CommonTab.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { useTemplateRef, computed } from 'vue'
  4. interface Props {
  5. active?: boolean
  6. disabled?: boolean
  7. tabMode?: boolean
  8. size: 'medium' | 'large'
  9. label?: string
  10. icon?: string
  11. tooltip?: string
  12. }
  13. const props = defineProps<Props>()
  14. const el = useTemplateRef('el')
  15. const colorClasses = computed(() => {
  16. if (props.active)
  17. return 'bg-white text-black dark:bg-gray-200 dark:text-white'
  18. if (props.disabled) return 'text-stone-200 dark:text-neutral-500'
  19. return ''
  20. })
  21. const fontSizeClassMap = {
  22. medium: 'text-sm leading-snug',
  23. large: 'text-base leading-snug',
  24. }
  25. const iconClassMap = {
  26. medium: 'tiny',
  27. large: 'small',
  28. } as const
  29. </script>
  30. <template>
  31. <span
  32. ref="el"
  33. v-tooltip="tooltip"
  34. class="-:text-gray-100 -:dark:text-neutral-400 -:transition-colors inline-flex select-none items-center gap-1 text-nowrap rounded-full px-3.5 py-1 text-base outline-none focus-visible:outline-1 focus-visible:outline-offset-1 focus-visible:outline-blue-800"
  35. :class="[
  36. colorClasses,
  37. fontSizeClassMap[props.size],
  38. {
  39. 'cursor-pointer': !disabled && ((tabMode && !active) || !tabMode),
  40. },
  41. ]"
  42. :aria-disabled="disabled"
  43. >
  44. <CommonIcon
  45. v-if="icon"
  46. :name="icon"
  47. :size="iconClassMap[props.size]"
  48. decorative
  49. />
  50. <template v-if="label">
  51. {{ $t(label) }}
  52. </template>
  53. </span>
  54. </template>