CommonSelectItem.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import type { SelectOption } from '#shared/components/CommonSelect/types.ts'
  5. import { i18n } from '#shared/i18n.ts'
  6. import CommonTicketStateIndicator from '#mobile/components/CommonTicketStateIndicator/CommonTicketStateIndicator.vue'
  7. const props = defineProps<{
  8. option: SelectOption
  9. selected: boolean
  10. multiple?: boolean
  11. noLabelTranslate?: boolean
  12. }>()
  13. const emit = defineEmits<{
  14. select: [option: SelectOption]
  15. }>()
  16. const select = (option: SelectOption) => {
  17. if (props.option.disabled) {
  18. return
  19. }
  20. emit('select', option)
  21. }
  22. const label = computed(() => {
  23. const { option } = props
  24. if (props.noLabelTranslate) {
  25. return option.label
  26. }
  27. return i18n.t(option.label, ...(option.labelPlaceholder || []))
  28. })
  29. </script>
  30. <template>
  31. <div
  32. :class="{
  33. 'pointer-events-none': option.disabled,
  34. }"
  35. tabindex="0"
  36. :aria-selected="selected"
  37. class="focus:bg-blue-highlight flex h-[58px] cursor-pointer items-center self-stretch px-4 py-5 text-base leading-[19px] text-white first:rounded-t-xl last:rounded-b-xl focus:outline-none"
  38. role="option"
  39. :data-value="option.value"
  40. @click="select(option)"
  41. @keypress.space.prevent="select(option)"
  42. >
  43. <CommonIcon
  44. v-if="multiple"
  45. :class="{
  46. '!text-white': selected,
  47. 'opacity-30': option.disabled,
  48. }"
  49. size="base"
  50. decorative
  51. :name="selected ? 'check-box-yes' : 'check-box-no'"
  52. class="text-white/50 ltr:mr-3 rtl:ml-3"
  53. />
  54. <CommonTicketStateIndicator
  55. v-if="option.status"
  56. :color-code="option.status"
  57. :label="option.label || String(option.value)"
  58. :class="{
  59. 'opacity-30': option.disabled,
  60. }"
  61. class="ltr:mr-[11px] rtl:ml-[11px]"
  62. />
  63. <CommonIcon
  64. v-else-if="option.icon"
  65. :name="option.icon"
  66. size="small"
  67. :class="{
  68. '!text-white': selected,
  69. 'opacity-30': option.disabled,
  70. }"
  71. decorative
  72. class="text-white/80 ltr:mr-[11px] rtl:ml-[11px]"
  73. />
  74. <span
  75. :class="{
  76. 'font-semibold !text-white': selected,
  77. 'opacity-30': option.disabled,
  78. }"
  79. class="grow text-white/80"
  80. >
  81. {{ label || option.value }}
  82. </span>
  83. <CommonIcon
  84. v-if="!multiple"
  85. class="ltr:ml-2 rtl:mr-2"
  86. :class="{
  87. invisible: !selected,
  88. 'opacity-30': option.disabled,
  89. }"
  90. decorative
  91. size="tiny"
  92. name="check"
  93. />
  94. </div>
  95. </template>