Menu bar.

This commit is contained in:
2026-10-19 17:11:50 +02:00
parent 6c45bd86f4
commit 9771638bfc
8 changed files with 105 additions and 60 deletions
-56
View File
@@ -1,56 +0,0 @@
# sv
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
## Creating a project
If you're seeing this, you've probably already done this step. Congrats!
```sh
# create a new project
npx sv create my-app
```
To recreate this project with the same configuration:
```sh
# recreate this project
pnpm dlx sv@1.1.1 create --template minimal --types ts --add prettier eslint vitest="usages:unit,component" playwright="demo:no" tailwindcss="plugins:typography,forms" --install pnpm web
```
## Adding features
Add features to your project with `sv add`:
```sh
npx sv add
```
For example, to add Tailwind CSS:
```sh
npx sv add tailwindcss
```
## Developing
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```sh
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```sh
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
+1 -1
View File
@@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en" class="bg-neutral-950 font-sans text-neutral-100 scheme-dark">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
+32
View File
@@ -1,13 +1,45 @@
<script lang="ts"> <script lang="ts">
import './layout.css'; import './layout.css';
import favicon from '#lib/assets/favicon.svg'; import favicon from '#lib/assets/favicon.svg';
import { resolve } from '$app/paths';
import { page } from '$app/state';
import type { LayoutProps } from './$types'; import type { LayoutProps } from './$types';
let { children }: LayoutProps = $props(); 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> </script>
<svelte:head> <svelte:head>
<link rel="icon" href={favicon} /> <link rel="icon" href={favicon} />
</svelte:head> </svelte:head>
<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()} {@render children()}
</main>
</div>
+3 -2
View File
@@ -1,2 +1,3 @@
<h1>Welcome to SvelteKit</h1> <svelte:head>
<p>Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation</p> <title>Dashboard | Expenses</title>
</svelte:head>
+3
View File
@@ -0,0 +1,3 @@
<svelte:head>
<title>Accounts | Expenses</title>
</svelte:head>
+59
View File
@@ -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>