Add menu sections, icons and order, and the simple view
This commit is contained in:
1 parent
362a5bce2e
commit
6f31a54818
23 files changed
+393
-45
No files matched your search
+11
-1
@@ -11,6 +11,14 @@ export class ApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export interface NavItem {
|
||||
label: string;
|
||||
href: string;
|
||||
section?: string;
|
||||
icon?: string;
|
||||
new_tab?: boolean;
|
||||
}
|
||||
|
||||
/** What the page was started with (see resources/views/shell.blade.php). */
|
||||
export interface Boot {
|
||||
base: string;
|
||||
@@ -19,7 +27,9 @@ export interface Boot {
|
||||
locale: string;
|
||||
user: { name: string; email: string; is_super_admin: boolean } | null;
|
||||
permissions: string[];
|
||||
navigation: { label: string; href: string }[];
|
||||
navigation: NavItem[];
|
||||
view: 'full' | 'simple';
|
||||
can_switch: boolean;
|
||||
theme: string;
|
||||
can_login: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
// A small set of line icons for the menu; an unknown name draws nothing.
|
||||
defineProps<{ name?: string }>();
|
||||
|
||||
const paths: Record<string, string> = {
|
||||
home: 'M3 11l9-8 9 8v9a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z',
|
||||
file: 'M7 3h7l5 5v13H7zM14 3v5h5',
|
||||
image: 'M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M9 9h.01',
|
||||
users: 'M16 20v-1a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v1M10 11a3 3 0 1 0 0-6 3 3 0 0 0 0 6M20 20v-1a3 3 0 0 0-2-2.8M16 5.2a3 3 0 0 1 0 5.6',
|
||||
group: 'M3 7h18v12H3zM8 7V5h8v2',
|
||||
chart: 'M4 20V10M10 20V4M16 20v-8M22 20H2',
|
||||
shield: 'M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z',
|
||||
star: 'M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.5l6.1-.9z',
|
||||
tag: 'M3 12V4h8l10 10-8 8zM7.5 8h.01',
|
||||
link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1',
|
||||
cog: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6M19 12a7 7 0 0 0-.1-1.2l2-1.5-2-3.4-2.3.9a7 7 0 0 0-2-1.2L14.2 3h-4l-.4 2.6a7 7 0 0 0-2 1.2l-2.3-.9-2 3.4 2 1.5A7 7 0 0 0 5 12c0 .4 0 .8.1 1.2l-2 1.5 2 3.4 2.3-.9a7 7 0 0 0 2 1.2l.4 2.6h4l.4-2.6a7 7 0 0 0 2-1.2l2.3.9 2-3.4-2-1.5c.1-.4.1-.8.1-1.2',
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg
|
||||
v-if="name && paths[name]"
|
||||
class="h-4 w-4 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path :d="paths[name]" />
|
||||
</svg>
|
||||
</template>
|
||||
@@ -1,12 +1,31 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { api, boot } from '../api';
|
||||
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 items = computed(() => [{ label: 'Dashboard', href: boot.base }, ...boot.navigation]);
|
||||
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];
|
||||
@@ -38,22 +57,38 @@ watch(() => state.path, () => (open.value = false));
|
||||
<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">
|
||||
<Link
|
||||
v-for="item in items"
|
||||
:key="item.href"
|
||||
:href="item.href"
|
||||
class="block 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"
|
||||
>
|
||||
{{ t(item.label) }}
|
||||
</Link>
|
||||
<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>
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ const nl: Record<string, string> = {
|
||||
'Put online': 'Online zetten', 'Take offline': 'Offline halen', 'Draft': 'Concept', 'Scheduled': 'Ingepland', 'Published': 'Gepubliceerd',
|
||||
'Are you sure?': 'Weet je het zeker?', 'No posts yet.': 'Nog geen berichten.', 'Address (slug)': 'Adres (slug)', 'Summary': 'Samenvatting',
|
||||
'Text (Markdown)': 'Tekst (Markdown)', 'Cover image': 'Omslagafbeelding', 'Tags (comma separated)': 'Tags (met komma\'s)',
|
||||
'Featured': 'Uitgelicht', 'Publish': 'Publiceren', 'Publish at': 'Publiceren op', 'Menu': 'Menu', 'Loading…': 'Laden…',
|
||||
'Featured': 'Uitgelicht', 'Publish': 'Publiceren', 'Publish at': 'Publiceren op', 'Menu': 'Menu', 'Show everything': 'Alles tonen', 'Simple view': 'Simpele weergave', 'Loading…': 'Laden…',
|
||||
'You may not open this page.': 'Je mag deze pagina niet openen.', 'Something went wrong. Try again.': 'Er ging iets mis. Probeer het opnieuw.',
|
||||
'This page has no screen in the manager yet.': 'Deze pagina heeft nog geen scherm in de manager.', 'Go to the dashboard': 'Naar het dashboard',
|
||||
'The page expired. Reload it and try again.': 'De pagina is verlopen. Laad hem opnieuw en probeer het nog eens.', 'Back': 'Terug',
|
||||
|
||||
Reference in new issue
Block a user