Menu bar.
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<html lang="en" class="bg-neutral-950 font-sans text-neutral-100 scheme-dark">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
<script lang="ts">
|
||||
import './layout.css';
|
||||
import favicon from '#lib/assets/favicon.svg';
|
||||
import { resolve } from '$app/paths';
|
||||
import { page } from '$app/state';
|
||||
import type { LayoutProps } from './$types';
|
||||
|
||||
let { children }: LayoutProps = $props();
|
||||
|
||||
const menuItems = [
|
||||
{ label: 'Dashboard', href: '/' },
|
||||
{ label: 'Accounts', href: '/accounts' },
|
||||
{ label: 'Scheduled transactions', href: '/scheduled-transactions' },
|
||||
{ label: 'Transaction history', href: '/transaction-history' }
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<link rel="icon" href={favicon} />
|
||||
</svelte:head>
|
||||
|
||||
{@render children()}
|
||||
<div class="grid min-h-dvh grid-cols-[min(16rem,48vw)_minmax(0,1fr)]">
|
||||
<aside class="sticky top-0 h-dvh overflow-y-auto px-4 py-8">
|
||||
<div class="mx-3 mb-8 text-2xl font-normal">Expenses</div>
|
||||
<nav aria-label="Main navigation">
|
||||
<ul class="grid gap-2">
|
||||
{#each menuItems as item (item.href)}
|
||||
<li>
|
||||
<a
|
||||
href={resolve(item.href)}
|
||||
aria-current={page.url.pathname === resolve(item.href) ? 'page' : undefined}
|
||||
class="flex px-3 py-[0.3175rem] text-sm wrap-anywhere text-neutral-400 no-underline hover:text-neutral-100 focus-visible:text-neutral-100 focus-visible:underline focus-visible:underline-offset-2 focus-visible:outline-none aria-[current=page]:text-neutral-100 aria-[current=page]:not-italic"
|
||||
>
|
||||
{item.label}
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<main id="main-content" tabindex="-1" class="min-w-0">
|
||||
{@render children()}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
<h1>Welcome to SvelteKit</h1>
|
||||
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p>
|
||||
<svelte:head>
|
||||
<title>Dashboard | Expenses</title>
|
||||
</svelte:head>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<svelte:head>
|
||||
<title>Accounts | Expenses</title>
|
||||
</svelte:head>
|
||||
@@ -0,0 +1,59 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
const routes = [
|
||||
{ label: 'Dashboard', path: '/' },
|
||||
{ label: 'Accounts', path: '/accounts' },
|
||||
{ label: 'Scheduled transactions', path: '/scheduled-transactions' },
|
||||
{ label: 'Transaction history', path: '/transaction-history' }
|
||||
];
|
||||
|
||||
for (const viewport of [
|
||||
{ width: 1280, height: 800 },
|
||||
{ width: 375, height: 812 }
|
||||
]) {
|
||||
test.describe(`${viewport.width}px navigation`, () => {
|
||||
test.use({ viewport });
|
||||
|
||||
for (const route of routes) {
|
||||
test(`${route.label} loads directly with an empty main view`, async ({ page }) => {
|
||||
await page.goto(`http://localhost:4173${route.path}`);
|
||||
|
||||
await expect(page).toHaveTitle(`${route.label} | Expenses`);
|
||||
await expect(page.getByRole('main')).toBeEmpty();
|
||||
|
||||
const navigation = page.getByRole('navigation', { name: 'Main navigation' });
|
||||
await expect(navigation.getByRole('link')).toHaveCount(4);
|
||||
await expect(navigation.locator('[aria-current="page"]')).toHaveText(route.label);
|
||||
|
||||
const sidebar = await page.getByRole('complementary').boundingBox();
|
||||
expect(sidebar?.x).toBe(0);
|
||||
expect(sidebar?.y).toBe(0);
|
||||
expect(sidebar?.height).toBe(viewport.height);
|
||||
expect(
|
||||
await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)
|
||||
).toBe(true);
|
||||
});
|
||||
}
|
||||
|
||||
test('menu links navigate between pages', async ({ page }) => {
|
||||
await page.goto('http://localhost:4173/');
|
||||
|
||||
for (const route of [...routes.slice(1), routes[0]]) {
|
||||
await page.getByRole('link', { name: route.label, exact: true }).click();
|
||||
await expect(page).toHaveURL(`http://localhost:4173${route.path}`);
|
||||
await expect(page).toHaveTitle(`${route.label} | Expenses`);
|
||||
await expect(page.getByRole('navigation').locator('[aria-current="page"]')).toHaveText(
|
||||
route.label
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('keyboard users can skip navigation', async ({ page }) => {
|
||||
await page.goto('http://localhost:4173/');
|
||||
await page.keyboard.press('Tab');
|
||||
await expect(page.getByRole('link', { name: 'Skip to main content' })).toBeFocused();
|
||||
await page.keyboard.press('Enter');
|
||||
await expect(page.getByRole('main')).toBeFocused();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<svelte:head>
|
||||
<title>Scheduled transactions | Expenses</title>
|
||||
</svelte:head>
|
||||
@@ -0,0 +1,3 @@
|
||||
<svelte:head>
|
||||
<title>Transaction history | Expenses</title>
|
||||
</svelte:head>
|
||||
Reference in New Issue
Block a user