CommonBadge.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { getBadgeClasses } from '#shared/initializer/initializeBadgeClasses.ts'
  5. import type { BadgeSize, BadgeVariant } from './types.ts'
  6. export interface Props {
  7. variant?: BadgeVariant
  8. size?: BadgeSize
  9. tag?: 'span' | 'div'
  10. }
  11. const props = withDefaults(defineProps<Props>(), {
  12. variant: 'info',
  13. size: 'small',
  14. tag: 'span',
  15. })
  16. const sizeClasses = computed(() => {
  17. switch (props.size) {
  18. case 'large':
  19. return 'text-base'
  20. case 'medium':
  21. return 'text-sm'
  22. case 'small':
  23. default:
  24. return 'text-xs'
  25. }
  26. })
  27. const paddingClasses = computed(() => {
  28. switch (props.size) {
  29. case 'large':
  30. return ['px-4', 'py-2.5']
  31. case 'medium':
  32. return ['px-3', 'py-2']
  33. case 'small':
  34. default:
  35. return ['px-2', 'py-1']
  36. }
  37. })
  38. const borderRadiusClass = computed(() => {
  39. switch (props.size) {
  40. case 'large':
  41. return 'rounded-xl'
  42. case 'medium':
  43. return 'rounded-lg'
  44. case 'small':
  45. default:
  46. return 'rounded-md'
  47. }
  48. })
  49. const classMap = getBadgeClasses()
  50. </script>
  51. <template>
  52. <component
  53. :is="tag"
  54. class="cursor-default"
  55. :class="[
  56. classMap.base,
  57. classMap[props.variant],
  58. ...paddingClasses,
  59. sizeClasses,
  60. borderRadiusClass,
  61. ]"
  62. data-test-id="common-badge"
  63. >
  64. <slot />
  65. </component>
  66. </template>