123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
- <script setup lang="ts">
- import { computed, ref, useSlots } from 'vue'
- import CommonBackButton from '#mobile/components/CommonBackButton/CommonBackButton.vue'
- import CommonButton from '#mobile/components/CommonButton/CommonButton.vue'
- import type { CommonButtonProps } from '#mobile/components/CommonButton/types.ts'
- import CommonRefetch from '#mobile/components/CommonRefetch/CommonRefetch.vue'
- import type { RouteLocationRaw } from 'vue-router'
- export interface Props {
- containerTag?: 'header' | 'div'
- title?: string
- titleClass?: string
- backTitle?: string
- backIgnore?: string[]
- backUrl?: RouteLocationRaw
- backAvoidHomeButton?: boolean
- defaultAttrs?: Record<string, unknown>
- refetch?: boolean
- actionTitle?: string
- actionHidden?: boolean
- actionBtnProps?: CommonButtonProps
- onAction?(): void
- }
- const headerElement = ref()
- defineExpose({
- headerElement,
- })
- const props = withDefaults(defineProps<Props>(), {
- refetch: false,
- containerTag: 'header',
- })
- const slots = useSlots()
- const hasSlots = computed(() => Object.keys(slots).length > 0)
- const headerClass = computed(() => {
- return [
- 'flex items-center justify-center text-center text-lg font-bold',
- props.titleClass,
- ]
- })
- </script>
- <template>
- <component
- :is="containerTag"
- v-if="title || backUrl || (onAction && actionTitle) || hasSlots"
- ref="headerElement"
- class="grid h-[64px] shrink-0 grid-cols-[75px_auto_75px] border-b-[0.5px] border-white/10 bg-black px-4"
- data-test-id="appHeader"
- >
- <div class="flex items-center justify-self-start text-base">
- <slot
- name="before"
- :data="{ backUrl, backTitle, backIgnore, backAvoidHomeButton }"
- >
- <CommonBackButton
- v-if="backUrl"
- :fallback="backUrl"
- :label="backTitle"
- :ignore="backIgnore"
- :avoid-home-button="backAvoidHomeButton"
- />
- </slot>
- </div>
- <div class="flex flex-1 items-center justify-center">
- <CommonRefetch v-bind="defaultAttrs" :refetch="refetch">
- <slot :data="{ defaultAttrs, refetch }">
- <h1 :class="headerClass">
- {{ $t(title) }}
- </h1>
- </slot>
- </CommonRefetch>
- </div>
- <div
- v-if="((onAction || actionTitle) && !actionHidden) || slots.after"
- class="flex items-center justify-self-end text-base"
- >
- <slot name="after" :data="{ actionBtnProps }">
- <CommonButton
- v-bind="{
- variant: 'primary',
- transparentBackground: true,
- ...actionBtnProps,
- }"
- @click="onAction?.()"
- >
- {{ $t(actionTitle) }}
- </CommonButton>
- </slot>
- </div>
- </component>
- </template>
|