CommonSelectPill.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import CommonSelect from '@mobile/components/CommonSelect/CommonSelect.vue'
  4. import type { SelectOption } from '@shared/components/Form/fields/FieldSelect/types'
  5. import { computed } from 'vue'
  6. const props = defineProps<{
  7. modelValue?: string | number | boolean | (string | number | boolean)[] | null
  8. options: SelectOption[]
  9. placeholder?: string
  10. multiple?: boolean
  11. noClose?: boolean
  12. noOptionsLabelTranslation?: boolean
  13. }>()
  14. const emit = defineEmits<{
  15. (
  16. event: 'update:modelValue',
  17. value: string | number | (string | number)[],
  18. ): void
  19. (e: 'select', option: SelectOption): void
  20. }>()
  21. const dialogProps = computed(() => {
  22. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  23. const { placeholder, ...dialogProps } = props
  24. return dialogProps
  25. })
  26. const defaultLabel = computed(() => {
  27. const option = props.options.find(
  28. (option) => option.value === props.modelValue,
  29. )
  30. return option?.label || props.placeholder || ''
  31. })
  32. </script>
  33. <template>
  34. <CommonSelect
  35. #default="{ open }"
  36. v-bind="dialogProps"
  37. @update:model-value="emit('update:modelValue', $event)"
  38. @select="emit('select', $event)"
  39. >
  40. <button
  41. type="button"
  42. class="inline-flex w-auto cursor-pointer rounded-lg bg-gray-600 py-1 ltr:pl-2 ltr:pr-1 rtl:pr-2 rtl:pl-1"
  43. @click="open()"
  44. @keypress.space.prevent="open()"
  45. >
  46. <slot>
  47. {{ defaultLabel }}
  48. </slot>
  49. <CommonIcon
  50. class="self-center"
  51. name="mobile-caret-down"
  52. size="tiny"
  53. decorative
  54. />
  55. </button>
  56. </CommonSelect>
  57. </template>