All files / apps/huella-legal/app/components/shell SiteHeader.vue

86.84% Statements 33/38
77.77% Branches 7/9
80% Functions 12/15
86.11% Lines 31/36

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  7x                     2x       5x             5x       5x                                               6x     5x                 3x 2x                         2x               4x                 2x                           2x                                   5x   2x   5x 5x 5x 5x   5x         5x   5x 1x 2x       5x 5x   5x 7x     5x   5x 5x            
<template>
    <UHeader
        class="[view-transition-name:site-header]"
        :to="homePath"
        mode="slideover"
        :title="$t('app.header.home')"
        :menu="{
            title: $t('app.header.menu.title'),
            description: $t('app.header.menu.description'),
        }"
    >
        <template #top>
            <div class="hidden border-b border-muted md:block">
                <UContainer
                    class="flex h-9 items-center justify-between font-sans text-xs text-muted"
                >
                    <span>{{ $t("app.header.strip", { issn }) }}</span>
                    <ULink
                        :to="nav.newsletter"
                        raw
                        @click="jumpToNewsletter"
                        class="relative inline-flex h-9 items-center gap-1.5 font-semibold text-primary after:absolute after:inset-x-0 after:top-0 after:-bottom-2 hover:underline focus-visible:rounded-xs"
                    >
                        <UIcon name="i-lucide-mail" class="size-3.5" />
                        {{ $t("app.header.newsletter") }}
                    </ULink>
                </UContainer>
            </div>
        </template>
 
        <template #title>
            <BaseWordmark />
        </template>
 
        <LazyUNavigationMenu
            v-model="openSection"
            :hydrate-on-media-query="WIDE"
            :items="inlineSections"
            content-orientation="vertical"
            variant="link"
            color="neutral"
            highlight
            highlight-color="primary"
            :aria-label="$t('app.header.nav.label')"
        >
            <template #publications-content>
                <LazyNavPublicationsPanel />
            </template>
            <template #subjects-content>
                <LazyNavSubjectsPanel />
            </template>
        </LazyUNavigationMenu>
 
        <template #right>
            <SearchDialog />
            <UButton
                :to="nav.newsletter"
                :label="$t('app.header.subscribe')"
                @click="jumpToNewsletter"
                class="hidden md:inline-flex"
            />
        </template>
 
        <template #content="{ close }">
            <div class="flex min-h-16 shrink-0 items-center border-b border-default px-4">
                <BaseWordmark size="sm" />
                <UButton
                    square
                    variant="ghost"
                    color="neutral"
                    icon="i-lucide-x"
                    :aria-label="$t('app.header.menu.close')"
                    class="ml-auto"
                    @click="close"
                />
            </div>
 
            <div class="overflow-y-auto">
                <LazyUNavigationMenu
                    :items="menuSections"
                    orientation="vertical"
                    variant="link"
                    color="primary"
                    :aria-label="$t('app.header.nav.label')"
                >
                    <template #item-trailing="{ item }">
                        <UIcon
                            v-if="item.children"
                            name="i-lucide-chevron-down"
                            class="size-5 text-dimmed transition-transform group-data-[state=open]:rotate-180 motion-reduce:transition-none"
                        />
                    </template>
                </LazyUNavigationMenu>
 
                <div class="flex flex-col gap-3 p-4">
                    <UButton
                        block
                        :to="nav.newsletter"
                        :label="$t('app.header.menu.subscribe')"
                        @click="jumpFromMenu($event, close)"
                    />
                    <UButton
                        block
                        variant="outline"
                        color="neutral"
                        :to="{ name: 'publish' }"
                        :label="$t('app.header.menu.publish')"
                    />
                    <p class="pt-2 font-sans text-xs text-muted">
                        {{ $t("app.header.strip", { issn }) }}
                    </p>
                </div>
            </div>
        </template>
    </UHeader>
</template>
 
<script setup lang="ts">
import type { NavigationMenuItem } from "@nuxt/ui";
import { useMediaQuery } from "@vueuse/core";
 
interface Props {
    sections: NavigationMenuItem[];
    issn: string;
}
 
const props = defineProps<Props>();
 
const WIDE = "(min-width: 64rem)";
 
const router = useRouter();
const route = useRoute();
const jumpToNewsletter = useNewsletterJump();
const { nav } = useAppConfig();
 
const jumpFromMenu = (event: MouseEvent, close?: () => void): void => {
    close?.();
    jumpToNewsletter(event);
};
 
const homePath = computed(() => router.resolve({ name: "index" }).path);
 
const menuSections = computed<NavigationMenuItem[]>(() =>
    props.sections.map((section) =>
        section.children ? { ...section, type: "trigger" as const } : section,
    ),
);
 
const wide = useMediaQuery(WIDE);
const inlineSections = shallowRef<NavigationMenuItem[]>();
 
watchEffect(() => {
    if (wide.value || !inlineSections.value) inlineSections.value = props.sections;
});
 
const openSection = ref<string>("");
 
watch(
    () => route.fullPath,
    () => {
        openSection.value = "";
    },
);
</script>