CommonBadge.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  10. const props = withDefaults(defineProps<Props>(), {
  11. variant: 'info',
  12. size: 'small',
  13. })
  14. const sizeClasses = computed(() => {
  15. switch (props.size) {
  16. case 'large':
  17. return 'text-base'
  18. case 'medium':
  19. return 'text-sm'
  20. case 'small':
  21. default:
  22. return 'text-xs'
  23. }
  24. })
  25. const paddingClasses = computed(() => {
  26. switch (props.size) {
  27. case 'large':
  28. return ['px-4', 'py-2.5']
  29. case 'medium':
  30. return ['px-3', 'py-2']
  31. case 'small':
  32. default:
  33. return ['px-2', 'py-1']
  34. }
  35. })
  36. const borderRadiusClass = computed(() => {
  37. switch (props.size) {
  38. case 'large':
  39. return 'rounded-xl'
  40. case 'medium':
  41. return 'rounded-lg'
  42. case 'small':
  43. default:
  44. return 'rounded-md'
  45. }
  46. })
  47. const classMap = getBadgeClasses()
  48. </script>
  49. <template>
  50. <span
  51. :class="[
  52. classMap.base,
  53. classMap[props.variant],
  54. ...paddingClasses,
  55. sizeClasses,
  56. borderRadiusClass,
  57. ]"
  58. data-test-id="common-badge"
  59. >
  60. <slot />
  61. </span>
  62. </template>