CommonSelectPill.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 CommonSelect from '#mobile/components/CommonSelect/CommonSelect.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. 'update:modelValue': [string | number | (string | number)[]]
  16. select: [SelectOption]
  17. }>()
  18. const dialogProps = computed(() => {
  19. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  20. const { placeholder, ...dialogProps } = props
  21. return dialogProps
  22. })
  23. const defaultLabel = computed(() => {
  24. const option = props.options.find(
  25. (option) => option.value === props.modelValue,
  26. )
  27. return option?.label || props.placeholder || ''
  28. })
  29. </script>
  30. <template>
  31. <CommonSelect
  32. #default="{ open, state: expanded }"
  33. v-bind="dialogProps"
  34. @update:model-value="emit('update:modelValue', $event)"
  35. @select="emit('select', $event)"
  36. >
  37. <button
  38. type="button"
  39. aria-controls="common-select"
  40. aria-owns="common-select"
  41. aria-haspopup="dialog"
  42. :aria-expanded="expanded"
  43. class="inline-flex w-auto cursor-pointer rounded-lg bg-gray-600 py-1 ltr:pl-2 ltr:pr-1 rtl:pl-1 rtl:pr-2"
  44. @click="open()"
  45. @keypress.space.prevent="open()"
  46. >
  47. <slot>
  48. {{ defaultLabel }}
  49. </slot>
  50. <CommonIcon
  51. class="self-center"
  52. name="caret-down"
  53. size="tiny"
  54. decorative
  55. />
  56. </button>
  57. </CommonSelect>
  58. </template>