Component mockups.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
<link rel="icon" href={favicon} />
|
||||
</svelte:head>
|
||||
|
||||
<div class="grid min-h-dvh grid-cols-[min(16rem,48vw)_minmax(0,1fr)]">
|
||||
<div class="grid min-h-dvh grid-cols-[max-content_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">
|
||||
@@ -29,7 +29,7 @@
|
||||
<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"
|
||||
class="flex px-3 py-[0.3175rem] text-sm whitespace-nowrap 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>
|
||||
@@ -39,7 +39,9 @@
|
||||
</nav>
|
||||
</aside>
|
||||
|
||||
<main id="main-content" tabindex="-1" class="min-w-0">
|
||||
{@render children()}
|
||||
<main id="main-content" tabindex="-1" class="min-w-0 px-4 py-8 focus:outline-none sm:px-10">
|
||||
<div class="mx-auto max-w-6xl">
|
||||
{@render children()}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,99 @@
|
||||
<script lang="ts">
|
||||
import ActivityRow from '#lib/components/ActivityRow.svelte';
|
||||
import Amount from '#lib/components/Amount.svelte';
|
||||
import Button from '#lib/components/Button.svelte';
|
||||
import Card from '#lib/components/Card.svelte';
|
||||
import EmptyState from '#lib/components/EmptyState.svelte';
|
||||
import Link from '#lib/components/Link.svelte';
|
||||
import Notice from '#lib/components/Notice.svelte';
|
||||
import PageHeader from '#lib/components/PageHeader.svelte';
|
||||
import { formatDate } from '#lib/format.ts';
|
||||
import { accounts, transactions } from '#lib/mock/data.ts';
|
||||
|
||||
let selectedId = $state(accounts[0].id);
|
||||
let showNotice = $state(true);
|
||||
|
||||
const selected = $derived(accounts.find((account) => account.id === selectedId) ?? accounts[0]);
|
||||
const activity = $derived(
|
||||
transactions
|
||||
.filter((transaction) => transaction.accountId === selected.id)
|
||||
.toSorted((a, b) => b.date.localeCompare(a.date))
|
||||
.slice(0, 5)
|
||||
);
|
||||
|
||||
function lastActivity(accountId: string) {
|
||||
const dates = transactions.filter((t) => t.accountId === accountId).map((t) => t.date);
|
||||
return dates.length ? formatDate(dates.toSorted().at(-1)!) : 'none yet';
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Accounts | Expenses</title>
|
||||
</svelte:head>
|
||||
|
||||
<PageHeader title="Accounts" description={`${accounts.length} accounts`}>
|
||||
{#snippet actions()}
|
||||
<Button variant="primary" icon="plus">New account</Button>
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
{#if showNotice}
|
||||
<div class="mb-8">
|
||||
<Notice onclose={() => (showNotice = false)}>Checking Account reconciled on 19 Oct 2026.</Notice
|
||||
>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<ul class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{#each accounts as account (account.id)}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
aria-pressed={account.id === selectedId}
|
||||
onclick={() => (selectedId = account.id)}
|
||||
class="block h-full w-full rounded border border-neutral-600 bg-neutral-950 p-5 text-left hover:border-neutral-400 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-300 aria-pressed:border-neutral-300"
|
||||
>
|
||||
<span class="block text-sm text-neutral-400">{account.name}</span>
|
||||
<Amount
|
||||
cents={account.balanceCents}
|
||||
showCurrency
|
||||
class="mt-3 block text-xl wrap-anywhere sm:text-2xl"
|
||||
/>
|
||||
<span class="mt-4 block text-sm text-neutral-500">
|
||||
{account.memberCount === 1 ? '1 member' : `${account.memberCount} members`} / Last activity:
|
||||
{lastActivity(account.id)}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
<h2 class="mt-12 mb-4 text-2xl font-normal">{selected.name}</h2>
|
||||
<Card title="Recent activity">
|
||||
{#snippet actions()}
|
||||
<Link href="/transaction-history">View all</Link>
|
||||
{/snippet}
|
||||
{#if activity.length}
|
||||
<ul class="divide-y divide-neutral-700 border-t border-neutral-700">
|
||||
{#each activity as transaction (transaction.id)}
|
||||
<ActivityRow
|
||||
title={transaction.description}
|
||||
subtitle={formatDate(transaction.date)}
|
||||
cents={transaction.amountCents}
|
||||
direction={transaction.direction}
|
||||
/>
|
||||
{/each}
|
||||
</ul>
|
||||
{:else}
|
||||
<div class="border-t border-neutral-700 px-5 py-8">
|
||||
<EmptyState
|
||||
title="No transactions yet"
|
||||
description="New transactions for this account will appear here."
|
||||
>
|
||||
{#snippet action()}
|
||||
<Link href="/transaction-history">Add a transaction</Link>
|
||||
{/snippet}
|
||||
</EmptyState>
|
||||
</div>
|
||||
{/if}
|
||||
</Card>
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,150 @@
|
||||
<script lang="ts">
|
||||
import Amount from '#lib/components/Amount.svelte';
|
||||
import Button from '#lib/components/Button.svelte';
|
||||
import Card from '#lib/components/Card.svelte';
|
||||
import DataTable, { type Column } from '#lib/components/DataTable.svelte';
|
||||
import EmptyState from '#lib/components/EmptyState.svelte';
|
||||
import Notice from '#lib/components/Notice.svelte';
|
||||
import PageHeader from '#lib/components/PageHeader.svelte';
|
||||
import SearchInput from '#lib/components/SearchInput.svelte';
|
||||
import SegmentedControl from '#lib/components/SegmentedControl.svelte';
|
||||
import StatusDot from '#lib/components/StatusDot.svelte';
|
||||
import {
|
||||
formatDate,
|
||||
formatRecurrence,
|
||||
formatWeekendAdjustment,
|
||||
monthlyCents,
|
||||
signedCents
|
||||
} from '#lib/format.ts';
|
||||
import { accounts, scheduledTransactions } from '#lib/mock/data.ts';
|
||||
import type { ScheduledTransaction, ScheduleStatus } from '#lib/types.ts';
|
||||
|
||||
const columns: Column[] = [
|
||||
{ key: 'name', label: 'Name' },
|
||||
{ key: 'account', label: 'Account' },
|
||||
{ key: 'recurrence', label: 'Recurrence' },
|
||||
{ key: 'nextDue', label: 'Next due' },
|
||||
{ key: 'status', label: 'Status' },
|
||||
{ key: 'amount', label: 'Amount / EUR', align: 'right' }
|
||||
];
|
||||
|
||||
const statuses: Record<
|
||||
ScheduleStatus,
|
||||
{ kind: 'solid' | 'hollow' | 'dash' | 'alert'; label: string }
|
||||
> = {
|
||||
active: { kind: 'solid', label: 'Active' },
|
||||
'due-soon': { kind: 'alert', label: 'Due soon' },
|
||||
paused: { kind: 'hollow', label: 'Paused' },
|
||||
ended: { kind: 'dash', label: 'Ended' }
|
||||
};
|
||||
|
||||
let direction = $state('all');
|
||||
let query = $state('');
|
||||
|
||||
const accountName = (id: string) => accounts.find((account) => account.id === id)?.name ?? '';
|
||||
|
||||
const rows = $derived(
|
||||
scheduledTransactions.filter(
|
||||
(item) =>
|
||||
(direction === 'all' || item.direction === direction) &&
|
||||
item.name.toLowerCase().includes(query.trim().toLowerCase())
|
||||
)
|
||||
);
|
||||
|
||||
const monthlyNet = $derived(
|
||||
rows
|
||||
.filter((item) => item.status === 'active' || item.status === 'due-soon')
|
||||
.reduce((sum, item) => sum + signedCents(monthlyCents(item), item.direction), 0)
|
||||
);
|
||||
|
||||
const upcoming = scheduledTransactions
|
||||
.filter((item) => item.status === 'due-soon' && item.nextDue)
|
||||
.toSorted((a, b) => a.nextDue!.localeCompare(b.nextDue!))[0];
|
||||
|
||||
function recurrenceNotes(item: ScheduledTransaction) {
|
||||
return [
|
||||
formatWeekendAdjustment(item.weekendAdjustment),
|
||||
item.endsAt && `Until ${formatDate(item.endsAt)}`
|
||||
].filter((note): note is string => Boolean(note));
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Scheduled transactions | Expenses</title>
|
||||
</svelte:head>
|
||||
|
||||
<PageHeader
|
||||
title="Scheduled transactions"
|
||||
description="Recurring income and expenses, booked automatically."
|
||||
>
|
||||
{#snippet actions()}
|
||||
<Button variant="primary" icon="plus">New schedule</Button>
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
{#if upcoming}
|
||||
<div class="mb-8">
|
||||
<Notice variant="warning">
|
||||
{upcoming.name} is due on {formatDate(upcoming.nextDue!)}.
|
||||
{#snippet action()}
|
||||
<span class="text-neutral-400">{formatWeekendAdjustment(upcoming.weekendAdjustment)}</span>
|
||||
{/snippet}
|
||||
</Notice>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="mb-6 flex flex-wrap items-center gap-4">
|
||||
<SearchInput
|
||||
bind:value={query}
|
||||
label="Search scheduled transactions"
|
||||
placeholder="Search schedules..."
|
||||
class="w-full sm:w-auto sm:min-w-64 sm:flex-1"
|
||||
/>
|
||||
<SegmentedControl
|
||||
bind:value={direction}
|
||||
label="Direction"
|
||||
options={[
|
||||
{ value: 'all', label: 'All' },
|
||||
{ value: 'in', label: 'Income' },
|
||||
{ value: 'out', label: 'Expenses' }
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<DataTable caption="Scheduled transactions" {columns} {rows} rowId={(item) => item.id}>
|
||||
{#snippet cell(item, column)}
|
||||
{#if column.key === 'name'}
|
||||
{item.name}
|
||||
{:else if column.key === 'account'}
|
||||
<span class="text-neutral-400">{accountName(item.accountId)}</span>
|
||||
{:else if column.key === 'recurrence'}
|
||||
{formatRecurrence(item.every, item.unit)}
|
||||
{#each recurrenceNotes(item) as note (note)}
|
||||
<span class="block text-sm text-neutral-500">{note}</span>
|
||||
{/each}
|
||||
{:else if column.key === 'nextDue'}
|
||||
<span class="text-neutral-400 tabular-nums">
|
||||
{item.nextDue ? formatDate(item.nextDue) : '-'}
|
||||
</span>
|
||||
{:else if column.key === 'status'}
|
||||
<StatusDot {...statuses[item.status]} muted={item.status !== 'due-soon'} />
|
||||
{:else}
|
||||
<Amount cents={item.amountCents} direction={item.direction} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet empty()}
|
||||
<EmptyState
|
||||
title="No scheduled transactions"
|
||||
description="Try a different search or filter."
|
||||
/>
|
||||
{/snippet}
|
||||
{#snippet footer()}
|
||||
<span class="text-neutral-400">{rows.length} schedules</span>
|
||||
<span>
|
||||
Monthly net
|
||||
<Amount cents={monthlyNet} direction={monthlyNet < 0 ? 'out' : 'in'} showCurrency />
|
||||
</span>
|
||||
{/snippet}
|
||||
</DataTable>
|
||||
</Card>
|
||||
|
||||
@@ -1,3 +1,136 @@
|
||||
<script lang="ts">
|
||||
import Amount from '#lib/components/Amount.svelte';
|
||||
import Button from '#lib/components/Button.svelte';
|
||||
import Card from '#lib/components/Card.svelte';
|
||||
import DataTable, { type Column } from '#lib/components/DataTable.svelte';
|
||||
import EmptyState from '#lib/components/EmptyState.svelte';
|
||||
import PageHeader from '#lib/components/PageHeader.svelte';
|
||||
import Pagination from '#lib/components/Pagination.svelte';
|
||||
import SearchInput from '#lib/components/SearchInput.svelte';
|
||||
import SegmentedControl from '#lib/components/SegmentedControl.svelte';
|
||||
import SelectField from '#lib/components/SelectField.svelte';
|
||||
import { formatDate, signedCents } from '#lib/format.ts';
|
||||
import { accounts, transactions } from '#lib/mock/data.ts';
|
||||
|
||||
const PAGE_SIZE = 8;
|
||||
|
||||
const columns: Column[] = [
|
||||
{ key: 'date', label: 'Date' },
|
||||
{ key: 'description', label: 'Description' },
|
||||
{ key: 'account', label: 'Account' },
|
||||
{ key: 'amount', label: 'Amount / EUR', align: 'right' }
|
||||
];
|
||||
|
||||
let query = $state('');
|
||||
let accountId = $state('all');
|
||||
let direction = $state('all');
|
||||
let page = $state(1);
|
||||
let selected = $state<string[]>([]);
|
||||
|
||||
const accountName = (id: string) => accounts.find((account) => account.id === id)?.name ?? '';
|
||||
|
||||
const filtered = $derived(
|
||||
transactions
|
||||
.filter(
|
||||
(transaction) =>
|
||||
(accountId === 'all' || transaction.accountId === accountId) &&
|
||||
(direction === 'all' || transaction.direction === direction) &&
|
||||
transaction.description.toLowerCase().includes(query.trim().toLowerCase())
|
||||
)
|
||||
.toSorted((a, b) => b.date.localeCompare(a.date))
|
||||
);
|
||||
const rows = $derived(filtered.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE));
|
||||
const selectedTotal = $derived(
|
||||
transactions
|
||||
.filter((transaction) => selected.includes(transaction.id))
|
||||
.reduce((sum, t) => sum + signedCents(t.amountCents, t.direction), 0)
|
||||
);
|
||||
|
||||
// Filters change the result set, so return to the first page.
|
||||
$effect(() => {
|
||||
void [query, accountId, direction];
|
||||
page = 1;
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Transaction history | Expenses</title>
|
||||
</svelte:head>
|
||||
|
||||
<PageHeader title="Transaction history" description="Every payment in and out of your accounts.">
|
||||
{#snippet actions()}
|
||||
<Button icon="download">Export</Button>
|
||||
{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
<div class="mb-4 grid gap-4 md:grid-cols-[minmax(0,1fr)_16rem] md:items-end">
|
||||
<SearchInput
|
||||
bind:value={query}
|
||||
label="Search transactions"
|
||||
placeholder="Search transactions..."
|
||||
/>
|
||||
<SelectField
|
||||
bind:value={accountId}
|
||||
label="Account"
|
||||
options={[
|
||||
{ value: 'all', label: 'All accounts' },
|
||||
...accounts.map((account) => ({ value: account.id, label: account.name }))
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-6">
|
||||
<SegmentedControl
|
||||
bind:value={direction}
|
||||
label="Direction"
|
||||
options={[
|
||||
{ value: 'all', label: 'All' },
|
||||
{ value: 'in', label: 'Money in' },
|
||||
{ value: 'out', label: 'Money out' }
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<DataTable
|
||||
caption="Transaction history"
|
||||
{columns}
|
||||
{rows}
|
||||
rowId={(transaction) => transaction.id}
|
||||
selectable
|
||||
bind:selected
|
||||
>
|
||||
{#snippet cell(transaction, column)}
|
||||
{#if column.key === 'date'}
|
||||
<span class="text-neutral-400 tabular-nums">{formatDate(transaction.date)}</span>
|
||||
{:else if column.key === 'description'}
|
||||
{transaction.description}
|
||||
{:else if column.key === 'account'}
|
||||
<span class="text-neutral-400">{accountName(transaction.accountId)}</span>
|
||||
{:else}
|
||||
<Amount cents={transaction.amountCents} direction={transaction.direction} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet empty()}
|
||||
<EmptyState
|
||||
icon="search"
|
||||
title="No transactions found"
|
||||
description="Try a different search or filter."
|
||||
/>
|
||||
{/snippet}
|
||||
{#snippet footer()}
|
||||
{#if selected.length}
|
||||
<span class="text-neutral-400">{selected.length} selected</span>
|
||||
<span>
|
||||
Total
|
||||
<Amount cents={selectedTotal} direction={selectedTotal < 0 ? 'out' : 'in'} showCurrency />
|
||||
</span>
|
||||
{:else}
|
||||
<span class="text-neutral-500">Select transactions to see their total.</span>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</DataTable>
|
||||
</Card>
|
||||
|
||||
<div class="mt-6">
|
||||
<Pagination bind:page pageSize={PAGE_SIZE} total={filtered.length} noun="transactions" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user