2026-01-02 13:41:09 +00:00
|
|
|
<!-- Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/ -->
|
2022-07-20 19:07:07 +00:00
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-02-20 09:55:34 +00:00
|
|
|
import { computed } from 'vue'
|
2024-05-17 13:31:19 +00:00
|
|
|
|
2023-04-24 12:50:55 +00:00
|
|
|
import { useWalker } from '#shared/router/walker.ts'
|
2024-05-17 13:31:19 +00:00
|
|
|
import { useLocaleStore } from '#shared/stores/locale.ts'
|
|
|
|
|
|
|
|
|
|
import type { RouteLocationRaw } from 'vue-router'
|
2022-07-20 19:07:07 +00:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
fallback: RouteLocationRaw
|
|
|
|
|
label?: string
|
2022-12-12 11:26:34 +00:00
|
|
|
// list of routes users shouldn't go back to
|
|
|
|
|
// useful, if there is a possible infinite loop
|
|
|
|
|
// ticket -> information -> ticket -> information -> ...
|
|
|
|
|
ignore?: string[]
|
2023-02-23 13:25:04 +00:00
|
|
|
avoidHomeButton?: boolean
|
2022-07-20 19:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-20 09:55:34 +00:00
|
|
|
const props = defineProps<Props>()
|
|
|
|
|
|
|
|
|
|
const walker = useWalker()
|
|
|
|
|
|
|
|
|
|
const isHomeButton = computed(() => {
|
2024-04-15 16:46:40 +00:00
|
|
|
return !(props.avoidHomeButton || walker.getBackUrl(props.fallback) !== '/')
|
2023-02-20 09:55:34 +00:00
|
|
|
})
|
2023-02-23 13:25:04 +00:00
|
|
|
|
2023-06-09 11:34:29 +00:00
|
|
|
const locale = useLocaleStore()
|
2023-02-23 13:25:04 +00:00
|
|
|
|
|
|
|
|
const icon = computed(() => {
|
2023-12-08 14:28:20 +00:00
|
|
|
if (isHomeButton.value) return 'home'
|
|
|
|
|
if (locale.localeData?.dir === 'rtl') return 'chevron-right'
|
|
|
|
|
return 'chevron-left'
|
2023-02-23 13:25:04 +00:00
|
|
|
})
|
2022-07-20 19:07:07 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<button
|
|
|
|
|
class="flex cursor-pointer items-center"
|
2023-02-20 09:55:34 +00:00
|
|
|
:aria-label="isHomeButton ? $t('Go home') : $t('Go back')"
|
2022-07-20 19:07:07 +00:00
|
|
|
:class="{ 'gap-2': label }"
|
2023-03-03 16:46:32 +00:00
|
|
|
type="button"
|
2022-12-12 11:26:34 +00:00
|
|
|
@click="$walker.back(fallback, ignore)"
|
2022-07-20 19:07:07 +00:00
|
|
|
>
|
2023-02-23 13:25:04 +00:00
|
|
|
<CommonIcon :name="icon" decorative />
|
2023-02-20 09:55:34 +00:00
|
|
|
<span v-if="label">{{ isHomeButton ? $t('Home') : $t(label) }}</span>
|
2022-07-20 19:07:07 +00:00
|
|
|
</button>
|
|
|
|
|
</template>
|