Loheide-eu-mitarbeiterplatt.../resources/js/layouts/AppLayout.vue
Friederich Loheide 23c36d28b5
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m33s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m9s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
Menü: Symbole je Menüpunkt, gemeinsame Symbolauswahl
- Optionales Symbol für jeden Menü- und Unterpunkt (Kopfzeile,
  Aufklappmenüs, „Mehr“, Handy-Menü)
- Gemeinsame Liste resources/icons/icons.json (66 Lucide-Symbole) für
  Menü, Schnellzugriffe und Pagebuilder; `npm run icons` erzeugt
  Frontend-Zuordnung und SVGs für die Vorschau im Admin
- Admin-Auswahl mit Symbolvorschau und Suche

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 14:14:52 +00:00

317 lines
19 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup>
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { Head, Link, router, usePage } from '@inertiajs/vue3';
import { ChevronDown, LogOut, Menu, Monitor, Moon, Search, Settings, Sun, UserRound, UserRoundPen } from '@lucide/vue';
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Toaster } from '@/components/ui/sonner';
import BrandLogo from '@/components/BrandLogo.vue';
import NotificationBell from '@/components/NotificationBell.vue';
import PersonAvatar from '@/components/PersonAvatar.vue';
import NavLink from '@/components/nav/NavLink.vue';
import { icons } from '@/lib/icons';
import { useThemePreference } from '@/composables/useThemePreference';
defineProps({
title: { type: String, default: '' },
});
const page = usePage();
const user = computed(() => page.props.auth.user);
const branding = computed(() => page.props.branding);
const headerStyle = computed(() => branding.value.header_style ?? 'light');
const navigation = computed(() => page.props.navigation);
// Was nicht in die Kopfzeile passt, kommt unter „Mehr“. Gemessen wird an einer
// unsichtbaren Kopie der Menüpunkte – so passt es bei jeder Breite und Beschriftung.
const navBox = ref(null);
const navMeasure = ref(null);
const navFit = ref(navigation.value.length);
const MORE_WIDTH = 84;
function measureNav() {
const box = navBox.value;
const items = navMeasure.value ? [...navMeasure.value.children] : [];
if (!box || !items.length) return;
const widths = items.map((el) => el.getBoundingClientRect().width + 4);
const available = box.clientWidth;
if (widths.reduce((sum, w) => sum + w, 0) <= available) {
navFit.value = widths.length;
return;
}
let used = MORE_WIDTH;
let fit = 0;
for (const width of widths) {
if (used + width > available) break;
used += width;
fit++;
}
navFit.value = Math.max(1, fit);
}
let navObserver;
onMounted(() => {
navObserver = new ResizeObserver(measureNav);
if (navBox.value) navObserver.observe(navBox.value);
nextTick(measureNav);
document.fonts?.ready.then(measureNav);
});
onBeforeUnmount(() => navObserver?.disconnect());
watch(navigation, () => nextTick(measureNav));
const navVisible = computed(() => navigation.value.slice(0, navFit.value));
const navMore = computed(() => navigation.value.slice(navFit.value));
const { preference, setPreference } = useThemePreference();
const mobileNavOpen = ref(false);
// Nur im Personenverzeichnis vorbelegen – andere Seiten nutzen ?q= für ihre eigene Suche.
const search = ref(page.url.startsWith('/personen?') ? (new URLSearchParams(page.url.split('?')[1]).get('q') ?? '') : '');
function submitSearch() {
router.get('/personen', search.value ? { q: search.value } : {});
}
const themeOptions = [
{ value: 'system', label: 'Wie im System', icon: Monitor },
{ value: 'light', label: 'Hell', icon: Sun },
{ value: 'dark', label: 'Dunkel', icon: Moon },
];
</script>
<template>
<Head v-if="title" :title="title" />
<div class="flex min-h-screen flex-col">
<div v-if="branding.preview" class="flex flex-wrap items-center justify-center gap-x-3 gap-y-1 bg-amber-400 px-4 py-1.5 text-center text-[13px] font-medium text-amber-950">
Vorschau des Entwurfs – so sieht das Portal nach dem Veröffentlichen aus.
<a href="?vorschau=aus" class="underline">Vorschau beenden</a>
</div>
<header
class="sticky top-0 z-40 border-b"
:class="headerStyle === 'light' ? 'bg-card/95 backdrop-blur supports-[backdrop-filter]:bg-card/85' : ''"
:data-header="headerStyle"
>
<div class="mx-auto flex h-16 max-w-[1440px] items-center gap-2 px-4 lg:gap-6 lg:px-6">
<Sheet v-model:open="mobileNavOpen">
<SheetTrigger class="-ml-2 grid size-10 place-items-center rounded-md text-foreground/80 hover:bg-accent lg:hidden" aria-label="Menü öffnen">
<Menu class="size-5" />
</SheetTrigger>
<SheetContent side="left" class="w-72 p-0">
<SheetHeader class="border-b px-5 py-4">
<SheetTitle class="text-left"><BrandLogo /></SheetTitle>
</SheetHeader>
<nav class="grid gap-1 overflow-y-auto p-3" aria-label="Hauptnavigation">
<template v-for="item in navigation" :key="item.key">
<NavLink
v-if="item.href"
:item="item"
class="flex items-center gap-2.5 rounded-md px-3 py-2.5 text-[15px] font-medium"
:class="item.active && !item.children.some((c) => c.active) ? 'bg-brand-soft text-brand-soft-foreground' : 'text-foreground/80 hover:bg-accent'"
@click="mobileNavOpen = false"
>
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-[18px] opacity-80" />{{ item.label }}
</NavLink>
<p v-else class="px-3 pt-3 pb-1 text-xs font-semibold tracking-wide text-muted-foreground uppercase">{{ item.label }}</p>
<div v-if="item.children.length" class="mb-1 ml-3 grid gap-0.5 border-l pl-2">
<NavLink
v-for="child in item.children"
:key="child.key"
:item="child"
class="flex items-center gap-2 rounded-md px-3 py-2 text-sm"
:class="child.active ? 'bg-brand-soft font-medium text-brand-soft-foreground' : 'text-foreground/75 hover:bg-accent'"
@click="mobileNavOpen = false"
>
<component :is="icons[child.icon]" v-if="icons[child.icon]" class="size-4 opacity-70" />{{ child.label }}
</NavLink>
</div>
</template>
</nav>
</SheetContent>
</Sheet>
<Link href="/" class="shrink-0 text-foreground" aria-label="Startseite">
<BrandLogo :inverted="headerStyle !== 'light'" compact />
</Link>
<nav ref="navBox" class="relative hidden h-full min-w-0 flex-1 lg:block" aria-label="Hauptnavigation">
<!-- Unsichtbare Kopie zum Messen der Breiten -->
<ul ref="navMeasure" class="pointer-events-none invisible absolute flex gap-1" aria-hidden="true">
<li v-for="item in navigation" :key="item.key" class="flex items-center gap-1.5 px-3 text-sm font-medium whitespace-nowrap">
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-4" />{{ item.label }}<ChevronDown v-if="item.children.length" class="size-4" />
</li>
</ul>
<ul class="flex h-full items-stretch gap-1">
<li v-for="item in navVisible" :key="item.key" class="flex">
<DropdownMenu v-if="item.children.length">
<DropdownMenuTrigger
class="relative flex items-center gap-1.5 px-3 text-sm font-medium whitespace-nowrap transition-colors outline-none"
:class="item.active ? 'text-foreground' : 'text-foreground/70 hover:text-foreground'"
>
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-4 opacity-80" />{{ item.label }} <ChevronDown class="size-4 opacity-70" />
<span v-if="item.active" class="nav-underline absolute inset-x-3 bottom-0 h-[3px] rounded-t-full bg-brand" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start" class="min-w-56">
<template v-if="item.href">
<DropdownMenuItem as-child>
<NavLink :item="item" :class="item.active && !item.children.some((c) => c.active) ? 'font-semibold text-brand-text' : 'font-medium'">{{ item.label }} – Übersicht</NavLink>
</DropdownMenuItem>
<DropdownMenuSeparator />
</template>
<DropdownMenuItem v-for="child in item.children" :key="child.key" as-child>
<NavLink :item="child" :class="child.active ? 'font-semibold text-brand-text' : ''">
<component :is="icons[child.icon]" v-if="icons[child.icon]" class="size-4 text-muted-foreground" />{{ child.label }}
</NavLink>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<NavLink
v-else
:item="item"
class="relative flex items-center gap-1.5 px-3 text-sm font-medium whitespace-nowrap transition-colors"
:class="item.active ? 'text-foreground' : 'text-foreground/70 hover:text-foreground'"
:aria-current="item.active ? 'page' : undefined"
>
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-4 opacity-80" />{{ item.label }}
<span v-if="item.active" class="nav-underline absolute inset-x-3 bottom-0 h-[3px] rounded-t-full bg-brand" />
</NavLink>
</li>
<li v-if="navMore.length" class="flex">
<DropdownMenu>
<DropdownMenuTrigger
class="relative flex items-center gap-1 px-3 text-sm font-medium whitespace-nowrap transition-colors outline-none"
:class="navMore.some((i) => i.active) ? 'text-foreground' : 'text-foreground/70 hover:text-foreground'"
>
Mehr <ChevronDown class="size-4" />
<span v-if="navMore.some((i) => i.active)" class="nav-underline absolute inset-x-3 bottom-0 h-[3px] rounded-t-full bg-brand" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start" class="min-w-48">
<template v-for="(item, index) in navMore" :key="item.key">
<template v-if="item.children.length">
<DropdownMenuSeparator v-if="index" />
<DropdownMenuLabel class="text-xs text-muted-foreground">{{ item.label }}</DropdownMenuLabel>
<DropdownMenuItem v-if="item.href" as-child><NavLink :item="item">Übersicht</NavLink></DropdownMenuItem>
<DropdownMenuItem v-for="child in item.children" :key="child.key" as-child>
<NavLink :item="child" :class="child.active ? 'font-semibold text-brand-text' : ''">
<component :is="icons[child.icon]" v-if="icons[child.icon]" class="size-4 text-muted-foreground" />{{ child.label }}
</NavLink>
</DropdownMenuItem>
</template>
<DropdownMenuItem v-else as-child>
<NavLink :item="item" :class="item.active ? 'font-semibold text-brand-text' : ''">
<component :is="icons[item.icon]" v-if="icons[item.icon]" class="size-4 text-muted-foreground" />{{ item.label }}
</NavLink>
</DropdownMenuItem>
</template>
</DropdownMenuContent>
</DropdownMenu>
</li>
</ul>
</nav>
<div class="ml-auto flex shrink-0 items-center gap-1">
<form class="mr-2 hidden w-64 md:block xl:w-80" role="search" @submit.prevent="submitSearch">
<label class="relative block">
<span class="sr-only">Personen suchen</span>
<Search class="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground" />
<input
v-model="search"
type="search"
placeholder="Personen suchen …"
class="h-10 w-full rounded-md border border-input bg-card pr-3 pl-9 text-sm shadow-xs placeholder:text-muted-foreground focus-visible:border-brand-400 focus-visible:ring-3 focus-visible:ring-ring/30 focus-visible:outline-none"
/>
</label>
</form>
<Link href="/personen" class="grid size-10 place-items-center rounded-md text-foreground/70 hover:bg-accent hover:text-foreground md:hidden" aria-label="Personen suchen">
<Search class="size-5" />
</Link>
<NotificationBell />
<a
v-if="user.can_admin"
href="/admin"
class="grid size-10 place-items-center rounded-md text-foreground/70 hover:bg-accent hover:text-foreground"
aria-label="Administration"
title="Administration"
>
<Settings class="size-5" />
</a>
<DropdownMenu>
<DropdownMenuTrigger
class="ml-1 flex items-center gap-1.5 rounded-full py-1 pr-1.5 pl-1 hover:bg-accent focus-visible:ring-3 focus-visible:ring-ring/40 focus-visible:outline-none"
:aria-label="`Menü für ${user.name}`"
>
<PersonAvatar :person="user" class="size-9" />
<ChevronDown class="size-4 text-muted-foreground" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end" class="w-72">
<DropdownMenuLabel class="flex items-center gap-3 py-2 font-normal">
<PersonAvatar :person="user" class="size-10" />
<div class="min-w-0">
<div class="truncate text-sm font-semibold">{{ user.name }}</div>
<div class="truncate text-xs text-muted-foreground">{{ user.email }}</div>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem as-child>
<Link :href="`/personen/${user.id}`"><UserRound /> Mein Profil</Link>
</DropdownMenuItem>
<DropdownMenuItem as-child>
<Link href="/profil/bearbeiten"><UserRoundPen /> Profil bearbeiten</Link>
</DropdownMenuItem>
<DropdownMenuItem v-if="user.can_admin" as-child>
<a href="/admin"><Settings /> Administration</a>
</DropdownMenuItem>
<template v-if="!branding.color_mode">
<DropdownMenuSeparator />
<DropdownMenuLabel class="text-xs font-medium text-muted-foreground">Darstellung</DropdownMenuLabel>
<DropdownMenuRadioGroup :model-value="preference" @update:model-value="setPreference">
<DropdownMenuRadioItem v-for="option in themeOptions" :key="option.value" :value="option.value">
<component :is="option.icon" class="size-4 text-muted-foreground" />
{{ option.label }}
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</template>
<DropdownMenuSeparator />
<DropdownMenuItem as-child>
<Link href="/logout" method="post" as="button" class="w-full"><LogOut /> Abmelden</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</header>
<main class="mx-auto w-full max-w-[1440px] flex-1 px-4 py-6 lg:px-6 lg:py-7">
<slot />
</main>
<footer v-if="branding.footer.text || branding.footer.links.length" class="border-t">
<div class="mx-auto flex max-w-[1440px] flex-wrap items-center justify-between gap-x-6 gap-y-2 px-4 py-5 text-[13px] text-muted-foreground lg:px-6">
<p v-if="branding.footer.text">{{ branding.footer.text }}</p>
<nav v-if="branding.footer.links.length" class="flex flex-wrap gap-x-5 gap-y-1" aria-label="Fußzeile">
<a v-for="link in branding.footer.links" :key="link.url" :href="link.url" class="hover:text-foreground hover:underline">{{ link.label }}</a>
</nav>
</div>
</footer>
</div>
<Toaster position="bottom-right" />
</template>