CommonBackButton.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { useWalker } from '#shared/router/walker.ts'
  5. import { useLocaleStore } from '#shared/stores/locale.ts'
  6. import type { RouteLocationRaw } from 'vue-router'
  7. interface Props {
  8. fallback: RouteLocationRaw
  9. label?: string
  10. // list of routes users shouldn't go back to
  11. // useful, if there is a possible infinite loop
  12. // ticket -> information -> ticket -> information -> ...
  13. ignore?: string[]
  14. avoidHomeButton?: boolean
  15. }
  16. const props = defineProps<Props>()
  17. const walker = useWalker()
  18. const isHomeButton = computed(() => {
  19. return !(props.avoidHomeButton || walker.getBackUrl(props.fallback) !== '/')
  20. })
  21. const locale = useLocaleStore()
  22. const icon = computed(() => {
  23. if (isHomeButton.value) return 'home'
  24. if (locale.localeData?.dir === 'rtl') return 'chevron-right'
  25. return 'chevron-left'
  26. })
  27. </script>
  28. <template>
  29. <button
  30. class="flex cursor-pointer items-center"
  31. :aria-label="isHomeButton ? $t('Go home') : $t('Go back')"
  32. :class="{ 'gap-2': label }"
  33. type="button"
  34. @click="$walker.back(fallback, ignore)"
  35. >
  36. <CommonIcon :name="icon" decorative />
  37. <span v-if="label">{{ isHomeButton ? $t('Home') : $t(label) }}</span>
  38. </button>
  39. </template>