All files / src/components PageLayout.vue

84.21% Statements 16/19
85.71% Branches 12/14
66.66% Functions 2/3
94.11% Lines 16/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168  17x 5x   5x 5x                                                             16x                       16x   16x 16x   16x 16x     2x   2x   2x                 2x                 16x 2x                                                                                                                                                                              
<template>
  <div class="page-content" :class="{ scrollable }">
    <div class="row mb-2 page-header">
      <div :class="actionSlot ? 'col-auto' : 'col-12'">
        <div class="d-flex align-items-center gap-2">
          <h1 class="display-6 page-title mb-0">{{ title }}</h1>
          <button
            v-if="description"
            ref="infoBtnRef"
            type="button"
            class="btn btn-link p-0 page-info-btn"
            data-tour="page-info"
            :aria-label="t('common.moreInfo')"
            @click="showInfo"
          >
            <font-awesome-icon icon="fa-solid fa-info-circle" />
          </button>
        </div>
      </div>
      <div v-if="actionSlot" class="col text-end">
        <slot name="action" />
      </div>
    </div>
 
    <div v-if="scrollable" class="scrollable-content">
      <slot />
    </div>
    <slot v-else />
  </div>
</template>
 
<script setup lang="ts">
import { onUnmounted, ref, useSlots } from 'vue'
import { driver, type Driver } from 'driver.js'
import { useUILanguage } from '@/composables/useUILanguage'
 
const props = withDefaults(
  defineProps<{
    title: string
    description?: string
    // For pages that don't use VirtualCardGrid (which manages its own scroll):
    // pins the header and makes the body scroll independently within the
    // page's fixed height, instead of growing/scrolling the whole document.
    scrollable?: boolean
  }>(),
  { description: undefined, scrollable: false }
)
 
const { t } = useUILanguage()
 
const slots = useSlots()
const actionSlot = !!slots.action
 
const infoBtnRef = ref<HTMLButtonElement | null>(null)
let activeDriver: Driver | null = null
 
function showInfo() {
  Iif (!infoBtnRef.value || !props.description) return
 
  Iif (activeDriver) return
 
  activeDriver = driver({
    showButtons: ['close'],
    overlayOpacity: 0.5,
    popoverClass: 'driver-popover-info',
    onDestroyed: () => {
      activeDriver = null
    }
  })
 
  activeDriver.highlight({
    element: infoBtnRef.value,
    popover: {
      title: props.title,
      description: props.description
    }
  })
}
 
onUnmounted(() => {
  activeDriver?.destroy()
})
</script>
 
<style scoped>
/* One horizontal gutter for every page, whatever its mode, so titles and
   content line up across pages (Profile, Notifications, Members...).
   Pages must not add their own horizontal offset: top-level `.container-fluid`
   blocks, VirtualCardGrid and EmptyState get this gutter from the rules below, and
   useHeaderRowAlignment reads it to align table headers with grid rows. */
.page-content {
  --page-gutter: 2rem;
  width: 100%;
  max-width: 100%;
  padding: 1rem 0 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  box-sizing: border-box;
}
 
/* For pages that don't use VirtualCardGrid: pin content to the viewport
   height so .scrollable-content's overflow-y actually scrolls, instead of
   growing (min-height: 100% above lets the page grow past the viewport). */
.page-content.scrollable {
  height: 100%;
}
 
.page-header {
  padding: 0 var(--page-gutter);
}
 
.page-content.scrollable .page-header {
  flex-shrink: 0;
  margin-bottom: 0;
}
 
.scrollable-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem var(--page-gutter);
}
 
.page-content > :deep(.container-fluid),
.page-content > :deep(.virtual-scroll-wrapper) > .container-fluid,
.page-content > :deep(.empty-state) {
  padding-left: var(--page-gutter);
  padding-right: var(--page-gutter);
}
 
.page-title {
  color: #689909;
}
 
.page-info-btn {
  color: #9a6fff;
  font-size: 1.1rem;
  line-height: 1;
}
 
@media (max-width: 767px) {
  .page-content {
    --page-gutter: 1rem;
  }
 
  .page-content > .row:first-child {
    flex-shrink: 0;
  }
 
  .page-header .text-end {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
  }
 
  .page-header .text-end > .btn,
  .page-header .text-end > a.btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }
 
  .display-6 {
    font-size: 1.5rem;
  }
}
</style>