usePrivateIcon.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import type { Props } from './CommonIcon.vue'
  4. import type { Animations, Sizes } from './types.ts'
  5. export const usePrivateIcon = (
  6. props: Omit<Props, 'size'> & { size: Sizes },
  7. ) => {
  8. const animationClassMap: Record<Animations, string> = {
  9. pulse: 'animate-pulse',
  10. spin: 'animate-spin',
  11. ping: 'animate-ping',
  12. bounce: 'animate-bounce',
  13. }
  14. const sizeMap: Record<Sizes, number> = {
  15. xs: 12,
  16. tiny: 16,
  17. small: 20,
  18. base: 24,
  19. medium: 32,
  20. large: 48,
  21. xl: 96,
  22. }
  23. const iconClass = computed(() => {
  24. let className = `icon-${props.name}`
  25. // by default, always spin the spinner
  26. const animation = props.animation || (props.name === 'spinner' && 'spin')
  27. if (animation) {
  28. className += ` ${animationClassMap[animation]}`
  29. }
  30. return className
  31. })
  32. const finalSize = computed(() => {
  33. if (props.fixedSize) return props.fixedSize
  34. return {
  35. width: sizeMap[props.size],
  36. height: sizeMap[props.size],
  37. }
  38. })
  39. return {
  40. iconClass,
  41. finalSize,
  42. }
  43. }