CommonSelectItem.vue 2.5 KB

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