LayoutHeader.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref } from 'vue'
  4. import type { RouteLocationRaw } from 'vue-router'
  5. import CommonButton from '../CommonButton/CommonButton.vue'
  6. import CommonBackButton from '../CommonBackButton/CommonBackButton.vue'
  7. import CommonRefetch from '../CommonRefetch/CommonRefetch.vue'
  8. export interface Props {
  9. title?: string
  10. titleClass?: string
  11. backTitle?: string
  12. backIgnore?: string[]
  13. backUrl?: RouteLocationRaw
  14. backAvoidHomeButton?: boolean
  15. refetch?: boolean
  16. actionTitle?: string
  17. actionHidden?: boolean
  18. onAction?(): void
  19. }
  20. const headerElement = ref()
  21. defineExpose({
  22. headerElement,
  23. })
  24. const props = withDefaults(defineProps<Props>(), {
  25. refetch: false,
  26. })
  27. const headerClass = computed(() => {
  28. return [
  29. 'flex items-center justify-center text-center text-lg font-bold',
  30. props.titleClass,
  31. ]
  32. })
  33. </script>
  34. <template>
  35. <header
  36. v-if="title || backUrl || (onAction && actionTitle)"
  37. ref="headerElement"
  38. class="grid h-[64px] shrink-0 grid-cols-[75px_auto_75px] border-b-[0.5px] border-white/10 bg-black px-4"
  39. data-test-id="appHeader"
  40. >
  41. <div class="flex items-center justify-self-start text-base">
  42. <CommonBackButton
  43. v-if="backUrl"
  44. :fallback="backUrl"
  45. :label="backTitle"
  46. :ignore="backIgnore"
  47. :avoid-home-button="backAvoidHomeButton"
  48. />
  49. </div>
  50. <div class="flex flex-1 items-center justify-center">
  51. <CommonRefetch :refetch="refetch">
  52. <h1 :class="headerClass">
  53. {{ $t(title) }}
  54. </h1>
  55. </CommonRefetch>
  56. </div>
  57. <div class="flex cursor-pointer items-center justify-self-end text-base">
  58. <CommonButton
  59. v-if="onAction && actionTitle && !actionHidden"
  60. variant="primary"
  61. transparent-background
  62. @click="onAction?.()"
  63. >
  64. {{ $t(actionTitle) }}
  65. </CommonButton>
  66. </div>
  67. </header>
  68. </template>