Files
laravel-manager/ui/src/components/Layout.vue
T
Matthijs Iriks 6f31a54818
PR CI / ledger (pull_request) Successful in 4s
PR CI / flow (pull_request) Successful in 4s
PR CI / ui (pull_request) Successful in 16s
PR CI / security (pull_request) Failing after 38s
PR CI / test (lowest) (pull_request) Successful in 42s
PR CI / test (stable) (pull_request) Successful in 43s
PR CI / pr-ci (pull_request) Failing after 1s
PR CI / release-automerge (pull_request) Skipped
Add menu sections, icons and order, and the simple view
2026-12-04 05:16:06 +01:00

103 lines
4.6 KiB
Vue

<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { api, boot, type NavItem } from '../api';
import { t } from '../i18n';
import { state } from '../state';
import Icon from './Icon.vue';
import Link from './Link.vue';
const open = ref(false);
const groups = computed(() => {
const list: { title: string; items: NavItem[] }[] = [];
for (const item of [{ label: 'Dashboard', href: boot.base, icon: 'home' } as NavItem, ...boot.navigation]) {
const title = item.section ?? '';
const last = list[list.length - 1];
last && last.title === title ? last.items.push(item) : list.push({ title, items: [item] });
}
return list;
});
const view = ref(boot.view);
async function switchView(): Promise<void> {
await api.put(boot.base + '/profile/view', { view: view.value === 'simple' ? 'full' : 'simple' });
window.location.assign(boot.base);
}
function active(href: string): boolean {
const path = state.path.split('?')[0];
return href === boot.base ? path === href : path === href || path.startsWith(href + '/');
}
async function logout(): Promise<void> {
const { redirect } = await api.post(boot.base + '/logout');
window.location.assign(redirect);
}
watch(() => state.path, () => (open.value = false));
</script>
<template>
<div class="min-h-screen">
<header class="fixed inset-x-0 top-0 z-40 flex h-14 items-center justify-between border-b border-line bg-panel px-4 md:hidden">
<span class="font-display font-bold">{{ boot.name }}</span>
<button type="button" class="m-btn m-btn-secondary" :aria-expanded="open" @click="open = !open">{{ t('Menu') }}</button>
</header>
<aside
class="fixed inset-y-0 left-0 z-30 flex w-60 flex-col border-r border-line bg-panel pt-14 transition-transform md:translate-x-0 md:pt-0"
:class="open ? 'translate-x-0' : '-translate-x-full'"
>
<div class="hidden h-16 items-center gap-2 px-5 md:flex">
<img v-if="boot.logo" :src="boot.logo" alt="" class="h-7 w-auto" />
<span class="font-display text-lg font-bold">{{ boot.name }}</span>
</div>
<nav class="flex-1 space-y-0.5 overflow-y-auto px-3 py-3" aria-label="Manager">
<template v-for="group in groups" :key="group.title">
<p v-if="group.title" class="px-3 pb-1 pt-4 text-xs font-semibold uppercase tracking-wide text-muted">{{ t(group.title) }}</p>
<template v-for="item in group.items" :key="item.href">
<a
v-if="item.new_tab"
:href="item.href"
target="_blank"
rel="noopener"
class="flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium text-muted transition hover:bg-text/5 hover:text-text"
>
<Icon :name="item.icon" />{{ t(item.label) }}
</a>
<Link
v-else
:href="item.href"
class="flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition"
:class="active(item.href) ? 'bg-brand/15 text-text' : 'text-muted hover:bg-text/5 hover:text-text'"
:aria-current="active(item.href) ? 'page' : undefined"
>
<Icon :name="item.icon" />{{ t(item.label) }}
</Link>
</template>
</template>
</nav>
<div class="border-t border-line p-4">
<Link :href="boot.base + '/profile'" class="group block">
<p class="truncate text-sm font-semibold group-hover:text-brand">{{ boot.user?.name }}</p>
<p class="truncate text-xs text-muted">{{ boot.user?.email }}</p>
</Link>
<button v-if="boot.can_switch" type="button" class="m-btn m-btn-secondary mt-3 w-full justify-center" @click="switchView">
{{ view === 'simple' ? t('Show everything') : t('Simple view') }}
</button>
<button type="button" class="m-btn m-btn-secondary mt-3 w-full justify-center" @click="logout">{{ t('Log out') }}</button>
</div>
</aside>
<div v-if="open" class="fixed inset-0 z-20 bg-black/60 md:hidden" @click="open = false" />
<main class="px-4 pb-16 pt-20 md:ml-60 md:px-8 md:pt-8">
<div class="mx-auto max-w-5xl"><slot /></div>
</main>
</div>
</template>