CommonButton.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { startCase } from 'lodash-es'
  4. import { computed } from 'vue'
  5. import type { CommonButtonProps } from '#mobile/components/CommonButton/types.ts'
  6. const props = withDefaults(defineProps<CommonButtonProps>(), {
  7. type: 'button',
  8. variant: 'secondary',
  9. })
  10. const transparentBackgroundClasses = computed(() => {
  11. if (props.transparentBackground) return ['rounded-none', 'bg-transparent']
  12. return ['rounded-xl']
  13. })
  14. const variantClasses = computed(() => {
  15. switch (props.variant) {
  16. case 'primary':
  17. if (props.transparentBackground) return ['text-blue']
  18. return ['bg-blue', 'text-white']
  19. case 'submit':
  20. if (props.transparentBackground) return ['font-semibold', 'text-yellow']
  21. return ['bg-yellow', 'font-semibold', 'text-black-full']
  22. case 'danger':
  23. if (props.transparentBackground) return ['text-red-bright']
  24. return ['bg-red-dark', 'text-red-bright']
  25. case 'secondary':
  26. default:
  27. if (props.transparentBackground) return ['text-white']
  28. return ['bg-gray-500', 'text-white']
  29. }
  30. })
  31. </script>
  32. <template>
  33. <button
  34. :type="type"
  35. :form="form"
  36. :disabled="disabled"
  37. :class="[
  38. ...transparentBackgroundClasses,
  39. ...variantClasses,
  40. {
  41. 'opacity-50': disabled,
  42. },
  43. ]"
  44. class="text-base"
  45. >
  46. <slot>{{ $t(startCase(variant)) }}</slot>
  47. </button>
  48. </template>