Redesign app shell: adaptive nav, skip link, focus on screen change
This commit is contained in:
1 parent
adb3ff170c
commit
90c93a9891
1 file changed
+123
-70
+123
-70
@@ -1,4 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte';
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
import CircleAlert from '@lucide/svelte/icons/circle-alert';
|
||||
import Info from '@lucide/svelte/icons/info';
|
||||
import Sandwich from '@lucide/svelte/icons/sandwich';
|
||||
import ScanLine from '@lucide/svelte/icons/scan-line';
|
||||
import Settings from '@lucide/svelte/icons/settings';
|
||||
import { app, loadHousehold } from './lib/state.svelte';
|
||||
import Home from './routes/Home.svelte';
|
||||
import NewScan from './routes/NewScan.svelte';
|
||||
@@ -13,87 +20,133 @@
|
||||
const path = $derived(app.route.replace(/^#/, '') || '/');
|
||||
const scanId = $derived(path.match(/^\/scan\/(\d+)$/)?.[1]);
|
||||
const tabs = [
|
||||
{ href: '#/', label: 'Scans', match: (p: string) => p === '/' || p === '/new' || p.startsWith('/scan/'),
|
||||
icon: 'M4 7V5a1 1 0 0 1 1-1h2M17 4h2a1 1 0 0 1 1 1v2M20 17v2a1 1 0 0 1-1 1h-2M7 20H5a1 1 0 0 1-1-1v-2M8 12h8' },
|
||||
{ href: '#/calendar', label: 'Calendar', match: (p: string) => p === '/calendar',
|
||||
icon: 'M5 6h14a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1zM4 10h16M8 3v4M16 3v4' },
|
||||
{ href: '#/lunch', label: 'Lunch', match: (p: string) => p === '/lunch',
|
||||
icon: 'M6 3v8a2 2 0 0 0 2 2v8M10 3v8M8 3v8M16 21V3c2 1 3 4 3 8h-3' },
|
||||
{ href: '#/settings', label: 'Settings', match: (p: string) => p === '/settings',
|
||||
icon: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z' },
|
||||
{ href: '#/', label: 'Scans', icon: ScanLine, match: (p: string) => p === '/' || p === '/new' || p.startsWith('/scan/') },
|
||||
{ href: '#/calendar', label: 'Calendar', icon: CalendarDays, match: (p: string) => p === '/calendar' },
|
||||
{ href: '#/lunch', label: 'Lunch', icon: Sandwich, match: (p: string) => p === '/lunch' },
|
||||
{ href: '#/settings', label: 'Settings', icon: Settings, match: (p: string) => p === '/settings' },
|
||||
];
|
||||
|
||||
// After a screen change, move focus to its title so screen readers announce the new screen.
|
||||
let first = true;
|
||||
$effect(() => {
|
||||
void path;
|
||||
if (first) {
|
||||
first = false;
|
||||
return;
|
||||
}
|
||||
tick().then(() => (document.querySelector('main h1') as HTMLElement | null)?.focus({ preventScroll: true }));
|
||||
});
|
||||
</script>
|
||||
|
||||
<main>
|
||||
{#if error}
|
||||
<p class="error">Can't reach the ParentCalendar server: {error}</p>
|
||||
{:else if !app.household}
|
||||
<p class="muted">Loading…</p>
|
||||
{:else if path === '/new'}
|
||||
<NewScan />
|
||||
{:else if scanId}
|
||||
{#key scanId}<ScanPage id={Number(scanId)} />{/key}
|
||||
{:else if path === '/calendar'}
|
||||
<CalendarPage />
|
||||
{:else if path === '/lunch'}
|
||||
<LunchPage />
|
||||
{:else if path === '/settings'}
|
||||
<SettingsPage />
|
||||
{:else}
|
||||
<Home />
|
||||
<a class="skip-link" href="#main" onclick={(e) => { e.preventDefault(); document.getElementById('main')?.focus(); }}>Skip to content</a>
|
||||
|
||||
<div class="shell">
|
||||
<nav aria-label="Main">
|
||||
<div class="brand" aria-hidden="true">
|
||||
<img src="/icon.svg" alt="" width="36" height="36" />
|
||||
</div>
|
||||
{#each tabs as tab}
|
||||
<a href={tab.href} aria-current={tab.match(path) ? 'page' : undefined}>
|
||||
<span class="pill"><tab.icon size={22} aria-hidden="true" /></span>
|
||||
<span class="label">{tab.label}</span>
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
<main id="main" tabindex="-1">
|
||||
{#if error}
|
||||
<div class="alert error" role="alert">
|
||||
<CircleAlert size={18} aria-hidden="true" />
|
||||
<span>Can't reach the ParentCalendar server: {error}</span>
|
||||
</div>
|
||||
{:else if !app.household}
|
||||
<div class="stack" aria-busy="true" aria-label="Loading">
|
||||
<div class="skeleton" style="height:40px;width:50%"></div>
|
||||
<div class="skeleton" style="height:120px"></div>
|
||||
<div class="skeleton" style="height:120px"></div>
|
||||
</div>
|
||||
{:else if path === '/new'}
|
||||
<NewScan />
|
||||
{:else if scanId}
|
||||
{#key scanId}<ScanPage id={Number(scanId)} />{/key}
|
||||
{:else if path === '/calendar'}
|
||||
<CalendarPage />
|
||||
{:else if path === '/lunch'}
|
||||
<LunchPage />
|
||||
{:else if path === '/settings'}
|
||||
<SettingsPage />
|
||||
{:else}
|
||||
<Home />
|
||||
{/if}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div class="toast-region" aria-live="polite">
|
||||
{#if app.toast}
|
||||
<div class="toast"><Info size={18} aria-hidden="true" /><span>{app.toast}</span></div>
|
||||
{/if}
|
||||
</main>
|
||||
|
||||
<nav aria-label="Main">
|
||||
{#each tabs as tab}
|
||||
<a href={tab.href} aria-current={tab.match(path) ? 'page' : undefined}>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path d={tab.icon} /></svg>
|
||||
<span>{tab.label}</span>
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
{#if app.toast}
|
||||
<div class="toast" role="status">{app.toast}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
main {
|
||||
max-width: 1120px;
|
||||
margin: 0 auto;
|
||||
padding: var(--s5) var(--gutter) calc(var(--nav-h) + var(--s6) + env(safe-area-inset-bottom));
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Phones and tablets: bottom tab bar */
|
||||
nav {
|
||||
position: fixed;
|
||||
inset: auto 0 0 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
background: var(--surface);
|
||||
position: fixed; inset: auto 0 0 0; z-index: var(--z-nav);
|
||||
display: flex; justify-content: space-around;
|
||||
height: calc(var(--nav-h) + env(safe-area-inset-bottom));
|
||||
padding: 0 var(--s2) env(safe-area-inset-bottom);
|
||||
background: color-mix(in srgb, var(--surface) 92%, transparent);
|
||||
backdrop-filter: saturate(1.4) blur(12px);
|
||||
border-top: 1px solid var(--border);
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
z-index: 10;
|
||||
}
|
||||
.brand { display: none; }
|
||||
nav a {
|
||||
flex: 1;
|
||||
max-width: 160px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
padding: 8px 4px;
|
||||
min-height: 56px;
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
font-size: 0.75rem;
|
||||
flex: 1; max-width: 120px;
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
|
||||
color: var(--text-2); text-decoration: none; font-size: var(--fs-xs); font-weight: 600;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
nav a[aria-current='page'] { color: var(--accent); font-weight: 600; }
|
||||
nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
||||
.pill {
|
||||
display: grid; place-items: center; width: 56px; height: 30px; border-radius: var(--r-full);
|
||||
transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
|
||||
}
|
||||
nav a:hover .pill { background: var(--surface-2); }
|
||||
nav a[aria-current='page'] { color: var(--primary-text); }
|
||||
nav a[aria-current='page'] .pill { background: var(--primary-soft); }
|
||||
nav a:focus-visible { outline: none; }
|
||||
nav a:focus-visible .pill { outline: 3px solid var(--primary); outline-offset: 2px; }
|
||||
|
||||
/* Wide screens: side rail */
|
||||
@media (min-width: 1024px) {
|
||||
.shell { padding-left: var(--rail-w); }
|
||||
nav {
|
||||
inset: 0 auto 0 0; width: var(--rail-w); height: auto;
|
||||
flex-direction: column; justify-content: flex-start; gap: var(--s2);
|
||||
padding: var(--s4) var(--s2); border-top: 0; border-right: 1px solid var(--border);
|
||||
}
|
||||
.brand { display: grid; place-items: center; height: 56px; margin-bottom: var(--s3); }
|
||||
nav a { flex: none; max-width: none; height: 64px; }
|
||||
main { padding-bottom: var(--s7); }
|
||||
}
|
||||
|
||||
.toast-region {
|
||||
position: fixed; z-index: var(--z-toast); left: 50%; transform: translateX(-50%);
|
||||
bottom: calc(var(--nav-h) + var(--s3) + env(safe-area-inset-bottom));
|
||||
width: max-content; max-width: calc(100vw - 2 * var(--gutter));
|
||||
}
|
||||
@media (min-width: 1024px) { .toast-region { bottom: var(--s5); } }
|
||||
.toast {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: calc(72px + env(safe-area-inset-bottom));
|
||||
transform: translateX(-50%);
|
||||
background: var(--text);
|
||||
color: var(--bg);
|
||||
padding: 10px 16px;
|
||||
border-radius: 10px;
|
||||
max-width: calc(100vw - 32px);
|
||||
z-index: 20;
|
||||
box-shadow: var(--shadow);
|
||||
display: flex; align-items: center; gap: var(--s2);
|
||||
padding: var(--s3) var(--s4); border-radius: var(--r-md);
|
||||
background: var(--text); color: var(--bg); box-shadow: var(--shadow-3);
|
||||
font-size: var(--fs-sm); font-weight: 600;
|
||||
animation: toast-in var(--dur) var(--ease);
|
||||
}
|
||||
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
|
||||
</style>
|
||||
Reference in new issue
Block a user