All files / apps/developer-portal/app/components PageHeader.vue

100% Statements 19/19
91.66% Branches 11/12
100% Functions 7/7
100% Lines 16/16

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  204x 32x   129x                           32x 32x                 407x           32x 181x                                                       129x 129x 129x   131x   131x   129x 194x   194x              
<template>
    <header class="shrink-0 border-b border-default bg-default pb-5 has-data-tabs:pb-0">
        <div class="flex h-12 items-center gap-2 px-4 surface-ink lg:hidden">
            <NuxtLink to="/" class="font-display text-xl text-highlighted italic">
                {{ $t("pageHeader.wordmark") }}
            </NuxtLink>
            <span v-if="appLabel" class="truncate font-mono text-xs text-muted">
                / {{ appLabel }}
            </span>
            <UDashboardSearchButton
                :collapsed="true"
                color="neutral"
                variant="ghost"
                class="ml-auto text-muted"
            />
            <UDashboardSidebarToggle color="neutral" variant="ghost" class="text-muted" />
        </div>
 
        <div class="flex flex-wrap items-end justify-between gap-x-6 gap-y-3 px-4 pt-5 sm:px-6">
            <div class="min-w-0">
                <nav
                    v-if="trail.length > 1"
                    class="mb-1 flex items-center gap-1.5 font-mono text-xs text-muted"
                    :aria-label="$t('pageHeader.breadcrumb')"
                >
                    <template v-for="(crumb, index) in trail" :key="crumb.label">
                        <span v-if="index > 0" aria-hidden="true">/</span>
                        <NuxtLink v-if="crumb.to" :to="crumb.to" class="hover:text-highlighted">
                            {{ crumb.label }}
                        </NuxtLink>
                        <span v-else class="truncate">{{ crumb.label }}</span>
                    </template>
                </nav>
                <slot name="title">
                    <h1 class="truncate text-2xl font-semibold text-highlighted">{{ title }}</h1>
                </slot>
            </div>
            <div v-if="$slots.actions" class="flex shrink-0 items-center gap-2 pb-1">
                <slot name="actions" />
            </div>
        </div>
 
        <slot name="intro" />
 
        <AppTabs :tabs :title />
    </header>
</template>
 
<script setup lang="ts">
import type { Crumb } from "~/types/Crumb";
import type { PageTab } from "~/types/PageTab";
import { appEntries, locate } from "~/utils/apps";
import type { NavLink } from "~/types/NavLink";
 
interface Props {
    title: string;
    /** The steps below the app, the page's own last. */
    crumbs?: Crumb[];
    tabs?: PageTab[];
}
 
const { title, crumbs = [], tabs } = defineProps<Props>();
 
const { nav }: { nav: Record<string, NavLink | undefined> } = useAppConfig();
const route = useRoute();
const { t } = useI18n();
 
const here = computed(() => locate(appEntries(nav, t), route.path));
 
const appLabel = computed(() => here.value?.app.label.toLowerCase() ?? "");
 
const trail = computed((): Crumb[] => {
    const app = here.value?.app;
 
    return [
        { label: t("pageHeader.wordmark"), to: "/" },
        ...(app && app.id !== "home" ? [{ label: appLabel.value, to: app.entries[0]?.to }] : []),
        ...crumbs,
    ];
});
</script>