CommonBreadcrumb.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { useLocaleStore } from '#shared/stores/locale.ts'
  5. import type { BreadcrumbItem } from './types.ts'
  6. const props = defineProps<{
  7. items: BreadcrumbItem[]
  8. emphasizeLastItem?: boolean
  9. size?: 'small' | 'large'
  10. }>()
  11. const locale = useLocaleStore()
  12. // TODO: Missing handling when there is not enough space for the breadcrumb
  13. const lastItemClasses = computed(() => {
  14. return props.emphasizeLastItem ? ['last:dark:text-white last:text-black'] : []
  15. })
  16. const sizeClasses = computed(() => {
  17. if (props.size === 'small') return ['text-xs']
  18. return ['text-base'] // default -> 'large'
  19. })
  20. </script>
  21. <template>
  22. <nav
  23. :class="sizeClasses"
  24. :aria-label="$t('Breadcrumb navigation')"
  25. class="max-w-full"
  26. >
  27. <ol class="flex">
  28. <li
  29. v-for="(item, idx) in items"
  30. :key="item.label as string"
  31. class="flex items-center"
  32. :class="lastItemClasses"
  33. >
  34. <CommonIcon
  35. v-if="item.icon"
  36. :name="item.icon"
  37. size="xs"
  38. class="shrink-0 ltr:mr-1 rtl:ml-1"
  39. />
  40. <CommonLink
  41. v-if="item.route"
  42. class="focus:outline-none focus-visible:outline-1 focus-visible:outline-offset-1 focus-visible:outline-blue-800"
  43. :link="item.route"
  44. internal
  45. >
  46. <CommonLabel size="large" class="line-clamp-1 hover:underline">{{
  47. item.noOptionLabelTranslation
  48. ? $t(item.label as string)
  49. : item.label
  50. }}</CommonLabel>
  51. </CommonLink>
  52. <h1 v-else class="line-clamp-1" aria-current="page">
  53. {{
  54. item.noOptionLabelTranslation
  55. ? $t(item.label as string)
  56. : item.label
  57. }}
  58. </h1>
  59. <CommonIcon
  60. v-if="idx !== items.length - 1"
  61. :name="
  62. locale.localeData?.dir === 'rtl' ? 'chevron-left' : 'chevron-right'
  63. "
  64. size="xs"
  65. class="mx-1 inline-flex shrink-0"
  66. />
  67. <!-- Add a slot at the end of the last item. -->
  68. <slot v-if="idx === items.length - 1" name="trailing" />
  69. </li>
  70. </ol>
  71. </nav>
  72. </template>