CommonSelectPill.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import CommonSelect from '#mobile/components/CommonSelect/CommonSelect.vue'
  4. import { computed } from 'vue'
  5. import type { SelectOption } from '#shared/components/CommonSelect/types.ts'
  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, state: expanded }"
  36. v-bind="dialogProps"
  37. @update:model-value="emit('update:modelValue', $event)"
  38. @select="emit('select', $event)"
  39. >
  40. <button
  41. type="button"
  42. aria-controls="common-select"
  43. aria-owns="common-select"
  44. aria-haspopup="dialog"
  45. :aria-expanded="expanded"
  46. 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"
  47. @click="open()"
  48. @keypress.space.prevent="open()"
  49. >
  50. <slot>
  51. {{ defaultLabel }}
  52. </slot>
  53. <CommonIcon
  54. class="self-center"
  55. name="caret-down"
  56. size="tiny"
  57. decorative
  58. />
  59. </button>
  60. </CommonSelect>
  61. </template>