Ditched component mockups. I'd like to build them myself.
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Direction } from '../types';
|
|
||||||
import Amount from './Amount.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
cents,
|
|
||||||
direction
|
|
||||||
}: { title: string; subtitle: string; cents: number; direction: Direction } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<li class="flex items-center justify-between gap-4 px-5 py-3">
|
|
||||||
<div class="min-w-0">
|
|
||||||
<p class="truncate">{title}</p>
|
|
||||||
<p class="truncate text-sm text-neutral-400">{subtitle}</p>
|
|
||||||
</div>
|
|
||||||
<Amount {cents} {direction} showCurrency />
|
|
||||||
</li>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { CURRENCY, formatMoney } from '../format';
|
|
||||||
import type { Direction } from '../types';
|
|
||||||
|
|
||||||
let {
|
|
||||||
cents,
|
|
||||||
direction,
|
|
||||||
showCurrency = false,
|
|
||||||
class: className = ''
|
|
||||||
}: { cents: number; direction?: Direction; showCurrency?: boolean; class?: string } = $props();
|
|
||||||
|
|
||||||
const sign = $derived(direction === 'in' ? '+' : direction === 'out' ? '-' : '');
|
|
||||||
const label = $derived(
|
|
||||||
[sign, showCurrency ? CURRENCY : '', formatMoney(cents)].filter(Boolean).join(' ')
|
|
||||||
);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<span class={['whitespace-nowrap tabular-nums', className]}>{label}</span>
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { resolve } from '$app/paths';
|
|
||||||
import type { RouteId } from '$app/types';
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
||||||
import Icon, { type IconName } from './Icon.svelte';
|
|
||||||
|
|
||||||
type Props = Omit<HTMLButtonAttributes, 'children'> & {
|
|
||||||
variant?: 'primary' | 'secondary' | 'icon';
|
|
||||||
icon?: IconName;
|
|
||||||
href?: RouteId;
|
|
||||||
children?: Snippet;
|
|
||||||
};
|
|
||||||
|
|
||||||
let {
|
|
||||||
variant = 'secondary',
|
|
||||||
icon,
|
|
||||||
href,
|
|
||||||
children,
|
|
||||||
class: className = '',
|
|
||||||
disabled,
|
|
||||||
...rest
|
|
||||||
}: Props = $props();
|
|
||||||
|
|
||||||
const classes = $derived([
|
|
||||||
'inline-flex h-11.5 items-center justify-center gap-3 rounded text-base whitespace-nowrap focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-300',
|
|
||||||
variant === 'icon' ? 'w-11.5' : 'px-4',
|
|
||||||
disabled
|
|
||||||
? 'pointer-events-none border border-neutral-800 text-neutral-500'
|
|
||||||
: variant === 'primary'
|
|
||||||
? 'bg-neutral-100 text-neutral-950 hover:bg-white'
|
|
||||||
: 'border border-neutral-600 bg-neutral-950 hover:border-neutral-400',
|
|
||||||
variant === 'secondary' && 'italic',
|
|
||||||
className
|
|
||||||
]);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if href && !disabled}
|
|
||||||
<a href={resolve(href)} class={classes} aria-label={rest['aria-label']}>
|
|
||||||
{#if icon}<Icon name={icon} />{/if}
|
|
||||||
{@render children?.()}
|
|
||||||
</a>
|
|
||||||
{:else}
|
|
||||||
<button type="button" {disabled} class={classes} {...rest}>
|
|
||||||
{#if icon}<Icon name={icon} class={variant === 'icon' ? 'text-neutral-400' : ''} />{/if}
|
|
||||||
{@render children?.()}
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
title,
|
|
||||||
actions,
|
|
||||||
children,
|
|
||||||
class: className = ''
|
|
||||||
}: { title?: string; actions?: Snippet; children: Snippet; class?: string } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<section class={['rounded border border-neutral-600 bg-neutral-950', className]}>
|
|
||||||
{#if title}
|
|
||||||
<header class="flex items-center justify-between gap-4 px-5 py-4">
|
|
||||||
<h2 class="text-base font-normal">{title}</h2>
|
|
||||||
{#if actions}<div class="text-sm">{@render actions()}</div>{/if}
|
|
||||||
</header>
|
|
||||||
{/if}
|
|
||||||
{@render children()}
|
|
||||||
</section>
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import Icon from './Icon.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
checked = false,
|
|
||||||
label,
|
|
||||||
onchange,
|
|
||||||
class: className = ''
|
|
||||||
}: {
|
|
||||||
checked?: boolean;
|
|
||||||
label: string;
|
|
||||||
onchange?: (checked: boolean) => void;
|
|
||||||
class?: string;
|
|
||||||
} = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<span class={['relative grid size-4 place-items-center', className]}>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
{checked}
|
|
||||||
aria-label={label}
|
|
||||||
onchange={(event) => onchange?.(event.currentTarget.checked)}
|
|
||||||
class="peer size-4 appearance-none rounded-[3px] border-neutral-600 bg-neutral-950 bg-none checked:border-neutral-200 checked:bg-neutral-200 checked:bg-none focus:ring-0 focus:ring-offset-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-300"
|
|
||||||
/>
|
|
||||||
<Icon
|
|
||||||
name="check"
|
|
||||||
size={18}
|
|
||||||
class="pointer-events-none absolute hidden text-neutral-950 peer-checked:block"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
<script lang="ts" module>
|
|
||||||
export type Column = {
|
|
||||||
key: string;
|
|
||||||
label: string;
|
|
||||||
align?: 'left' | 'right';
|
|
||||||
class?: string;
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts" generics="T">
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
import Checkbox from './Checkbox.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
caption,
|
|
||||||
columns,
|
|
||||||
rows,
|
|
||||||
rowId,
|
|
||||||
cell,
|
|
||||||
rowActions,
|
|
||||||
empty,
|
|
||||||
footer,
|
|
||||||
selectable = false,
|
|
||||||
selected = $bindable([])
|
|
||||||
}: {
|
|
||||||
caption: string;
|
|
||||||
columns: Column[];
|
|
||||||
rows: T[];
|
|
||||||
rowId: (row: T) => string;
|
|
||||||
cell: Snippet<[T, Column]>;
|
|
||||||
rowActions?: Snippet<[T]>;
|
|
||||||
empty?: Snippet;
|
|
||||||
footer?: Snippet;
|
|
||||||
selectable?: boolean;
|
|
||||||
selected?: string[];
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
const allSelected = $derived(
|
|
||||||
rows.length > 0 && rows.every((row) => selected.includes(rowId(row)))
|
|
||||||
);
|
|
||||||
|
|
||||||
function toggleAll(checked: boolean) {
|
|
||||||
const ids = rows.map(rowId);
|
|
||||||
selected = checked
|
|
||||||
? [...selected, ...ids.filter((id) => !selected.includes(id))]
|
|
||||||
: selected.filter((id) => !ids.includes(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleRow(id: string, checked: boolean) {
|
|
||||||
selected = checked ? [...selected, id] : selected.filter((value) => value !== id);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if rows.length === 0 && empty}
|
|
||||||
<div class="px-5 py-8">{@render empty()}</div>
|
|
||||||
{:else}
|
|
||||||
<div class="overflow-x-auto">
|
|
||||||
<table class="w-full min-w-160 border-collapse text-left">
|
|
||||||
<caption class="sr-only">{caption}</caption>
|
|
||||||
<thead>
|
|
||||||
<tr class="border-b border-neutral-700">
|
|
||||||
{#if selectable}
|
|
||||||
<th scope="col" class="w-12 py-3 pr-0 pl-5">
|
|
||||||
<Checkbox checked={allSelected} label="Select all" onchange={toggleAll} />
|
|
||||||
</th>
|
|
||||||
{/if}
|
|
||||||
{#each columns as column (column.key)}
|
|
||||||
<th
|
|
||||||
scope="col"
|
|
||||||
class={[
|
|
||||||
'px-4 py-3 text-sm font-normal whitespace-nowrap text-neutral-400',
|
|
||||||
column.align === 'right' && 'text-right',
|
|
||||||
column.class
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{column.label}
|
|
||||||
</th>
|
|
||||||
{/each}
|
|
||||||
{#if rowActions}<th scope="col" class="w-14 pr-4"><span class="sr-only">Actions</span></th
|
|
||||||
>{/if}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="divide-y divide-neutral-700">
|
|
||||||
{#each rows as row (rowId(row))}
|
|
||||||
{@const id = rowId(row)}
|
|
||||||
<tr class={[selected.includes(id) && 'bg-neutral-900']}>
|
|
||||||
{#if selectable}
|
|
||||||
<td class="w-12 py-3 pr-0 pl-5">
|
|
||||||
<Checkbox
|
|
||||||
checked={selected.includes(id)}
|
|
||||||
label="Select row"
|
|
||||||
onchange={(checked) => toggleRow(id, checked)}
|
|
||||||
/>
|
|
||||||
</td>
|
|
||||||
{/if}
|
|
||||||
{#each columns as column (column.key)}
|
|
||||||
<td
|
|
||||||
class={[
|
|
||||||
'px-4 py-3 whitespace-nowrap',
|
|
||||||
column.align === 'right' && 'text-right',
|
|
||||||
column.class
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{@render cell(row, column)}
|
|
||||||
</td>
|
|
||||||
{/each}
|
|
||||||
{#if rowActions}<td class="w-14 pr-4 text-right">{@render rowActions(row)}</td>{/if}
|
|
||||||
</tr>
|
|
||||||
{/each}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
{#if footer}
|
|
||||||
<div
|
|
||||||
class="flex flex-wrap items-center justify-between gap-x-6 gap-y-2 border-t border-neutral-700 px-5 py-3 text-sm"
|
|
||||||
>
|
|
||||||
{@render footer()}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
import Icon, { type IconName } from './Icon.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
icon = 'document',
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
action
|
|
||||||
}: { icon?: IconName; title: string; description?: string; action?: Snippet } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="flex flex-wrap items-center justify-between gap-x-6 gap-y-3">
|
|
||||||
<div class="flex items-start gap-4">
|
|
||||||
<Icon name={icon} size={24} class="mt-0.5 text-neutral-400" />
|
|
||||||
<div>
|
|
||||||
<p>{title}</p>
|
|
||||||
{#if description}<p class="mt-1 text-sm text-neutral-400">{description}</p>{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{#if action}<div class="text-sm">{@render action()}</div>{/if}
|
|
||||||
</div>
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<script lang="ts" module>
|
|
||||||
export const icons = {
|
|
||||||
plus: 'M12 5v14M5 12h14',
|
|
||||||
search: 'M17 10.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0Zm-1 5.5 4 4',
|
|
||||||
chevron: 'm8 10 4 4 4-4',
|
|
||||||
return: 'M8 7h8a5 5 0 0 1 0 10H5m4-4-4 4 4 4',
|
|
||||||
check: 'm5 12 4 4L19 6',
|
|
||||||
close: 'm6 6 12 12M6 18 18 6',
|
|
||||||
download: 'M12 3v12m-4-4 4 4 4-4M5 17v4h14v-4',
|
|
||||||
calendar:
|
|
||||||
'M6 5h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2ZM8 3v4m8-4v4M4 11h16',
|
|
||||||
arrow: 'M5 12h14m-5-5 5 5-5 5',
|
|
||||||
more: 'M5 12h.01M12 12h.01M19 12h.01',
|
|
||||||
document: 'M14 3H5v18h14V8Zm0 0v5h5M8 12h8m-8 4h6',
|
|
||||||
mail: 'M5 5h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2Zm-1 1 8 6 8-6',
|
|
||||||
alert: 'M12 7v6m0 4v.01'
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export type IconName = keyof typeof icons;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
let {
|
|
||||||
name,
|
|
||||||
size = 20,
|
|
||||||
class: className = ''
|
|
||||||
}: { name: IconName; size?: number; class?: string } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<svg
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
width={size}
|
|
||||||
height={size}
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="1.6"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
aria-hidden="true"
|
|
||||||
class={['shrink-0', className]}
|
|
||||||
>
|
|
||||||
<path d={icons[name]} />
|
|
||||||
</svg>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import { resolve } from '$app/paths';
|
|
||||||
import type { RouteId } from '$app/types';
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
import Icon from './Icon.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
href,
|
|
||||||
arrow = false,
|
|
||||||
children,
|
|
||||||
class: className = ''
|
|
||||||
}: { href: RouteId; arrow?: boolean; children: Snippet; class?: string } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<a
|
|
||||||
href={resolve(href)}
|
|
||||||
class={[
|
|
||||||
'inline-flex items-center gap-2 text-neutral-400 italic hover:text-neutral-100 focus-visible:text-neutral-100 focus-visible:underline focus-visible:underline-offset-2 focus-visible:outline-none',
|
|
||||||
className
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{@render children()}
|
|
||||||
{#if arrow}<Icon name="arrow" />{/if}
|
|
||||||
</a>
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
import Icon from './Icon.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
variant = 'success',
|
|
||||||
children,
|
|
||||||
action,
|
|
||||||
onclose
|
|
||||||
}: {
|
|
||||||
variant?: 'success' | 'warning';
|
|
||||||
children: Snippet;
|
|
||||||
action?: Snippet;
|
|
||||||
onclose?: () => void;
|
|
||||||
} = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if variant === 'success'}
|
|
||||||
<div
|
|
||||||
role="status"
|
|
||||||
class="flex items-center gap-4 rounded border border-neutral-600 bg-neutral-950 px-4 py-3.5"
|
|
||||||
>
|
|
||||||
<Icon name="check" class="text-neutral-400" />
|
|
||||||
<p class="min-w-0 flex-1 wrap-anywhere">{@render children()}</p>
|
|
||||||
{#if onclose}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
aria-label="Dismiss"
|
|
||||||
onclick={onclose}
|
|
||||||
class="text-neutral-400 hover:text-neutral-100 focus-visible:outline-2 focus-visible:outline-neutral-300"
|
|
||||||
>
|
|
||||||
<Icon name="close" />
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div role="alert" class="border-l-2 border-neutral-300 py-0.5 pl-4">
|
|
||||||
<p>{@render children()}</p>
|
|
||||||
{#if action}<p class="mt-1 text-sm">{@render action()}</p>{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import type { Snippet } from 'svelte';
|
|
||||||
|
|
||||||
let { title, description, actions }: { title: string; description?: string; actions?: Snippet } =
|
|
||||||
$props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<header
|
|
||||||
class="mb-8 flex flex-wrap items-end justify-between gap-x-6 gap-y-4 border-b border-neutral-700 pb-6"
|
|
||||||
>
|
|
||||||
<div class="min-w-0">
|
|
||||||
<h1 class="text-3xl font-normal">{title}</h1>
|
|
||||||
{#if description}<p class="mt-2 text-neutral-400">{description}</p>{/if}
|
|
||||||
</div>
|
|
||||||
{#if actions}<div class="flex flex-wrap items-center gap-3">{@render actions()}</div>{/if}
|
|
||||||
</header>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
let {
|
|
||||||
page = $bindable(1),
|
|
||||||
pageSize,
|
|
||||||
total,
|
|
||||||
noun
|
|
||||||
}: { page?: number; pageSize: number; total: number; noun: string } = $props();
|
|
||||||
|
|
||||||
const pageCount = $derived(Math.max(1, Math.ceil(total / pageSize)));
|
|
||||||
const first = $derived(total === 0 ? 0 : (page - 1) * pageSize + 1);
|
|
||||||
const last = $derived(Math.min(page * pageSize, total));
|
|
||||||
|
|
||||||
const step =
|
|
||||||
'text-sm text-neutral-400 hover:text-neutral-100 focus-visible:outline-2 focus-visible:outline-neutral-300 disabled:text-neutral-500 disabled:hover:text-neutral-500';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<nav aria-label="Pagination" class="flex flex-wrap items-center justify-between gap-x-6 gap-y-2">
|
|
||||||
<p class="text-sm text-neutral-400">Showing {first}-{last} of {total} {noun}</p>
|
|
||||||
<div class="flex items-center gap-4">
|
|
||||||
<button type="button" class={step} disabled={page <= 1} onclick={() => page--}>Previous</button>
|
|
||||||
<ul class="flex items-center gap-3">
|
|
||||||
{#each Array.from({ length: pageCount }, (_, index) => index + 1) as number (number)}
|
|
||||||
<li>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
aria-label={`Page ${number}`}
|
|
||||||
aria-current={number === page ? 'page' : undefined}
|
|
||||||
onclick={() => (page = number)}
|
|
||||||
class="text-sm text-neutral-500 hover:text-neutral-100 focus-visible:outline-2 focus-visible:outline-neutral-300 aria-[current=page]:text-neutral-100"
|
|
||||||
>
|
|
||||||
{number}
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
{/each}
|
|
||||||
</ul>
|
|
||||||
<button type="button" class={step} disabled={page >= pageCount} onclick={() => page++}
|
|
||||||
>Next</button
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import Icon from './Icon.svelte';
|
|
||||||
|
|
||||||
let {
|
|
||||||
value = $bindable(''),
|
|
||||||
label,
|
|
||||||
placeholder = 'Search...',
|
|
||||||
class: className = ''
|
|
||||||
}: { value?: string; label: string; placeholder?: string; class?: string } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<label class={['relative block', className]}>
|
|
||||||
<span class="sr-only">{label}</span>
|
|
||||||
<Icon
|
|
||||||
name="search"
|
|
||||||
class="pointer-events-none absolute top-1/2 left-4 -translate-y-1/2 text-neutral-400"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="search"
|
|
||||||
bind:value
|
|
||||||
{placeholder}
|
|
||||||
class="h-12 w-full rounded border-neutral-600 bg-neutral-950 pr-4 pl-12 text-base text-neutral-100 placeholder:text-neutral-400 placeholder:italic focus:border-neutral-400 focus:ring-0 focus:outline-none"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
let {
|
|
||||||
value = $bindable(),
|
|
||||||
label,
|
|
||||||
options,
|
|
||||||
class: className = ''
|
|
||||||
}: {
|
|
||||||
value?: string;
|
|
||||||
label: string;
|
|
||||||
options: { value: string; label: string }[];
|
|
||||||
class?: string;
|
|
||||||
} = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div
|
|
||||||
role="group"
|
|
||||||
aria-label={label}
|
|
||||||
class={[
|
|
||||||
'inline-flex max-w-full overflow-x-auto rounded border border-neutral-600 bg-neutral-950 p-1',
|
|
||||||
className
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{#each options as option (option.value)}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
aria-pressed={value === option.value}
|
|
||||||
onclick={() => (value = option.value)}
|
|
||||||
class="h-8.5 shrink-0 rounded-sm px-3 text-sm text-neutral-400 hover:text-neutral-100 focus-visible:outline-2 focus-visible:outline-neutral-300 aria-pressed:bg-neutral-800 aria-pressed:text-neutral-100 sm:min-w-20 sm:px-4"
|
|
||||||
>
|
|
||||||
{option.label}
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
import Icon from './Icon.svelte';
|
|
||||||
|
|
||||||
type Option = { value: string; label: string };
|
|
||||||
|
|
||||||
let {
|
|
||||||
value = $bindable(),
|
|
||||||
label,
|
|
||||||
options,
|
|
||||||
class: className = ''
|
|
||||||
}: { value?: string; label: string; options: Option[]; class?: string } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<label class={['block', className]}>
|
|
||||||
<span class="mb-2 block text-sm text-neutral-400">{label}</span>
|
|
||||||
<span class="relative block">
|
|
||||||
<select
|
|
||||||
bind:value
|
|
||||||
class="h-12 w-full appearance-none rounded border-neutral-600 bg-neutral-950 bg-none pr-11 pl-4 text-base text-neutral-100 focus:border-neutral-400 focus:ring-0 focus:outline-none"
|
|
||||||
>
|
|
||||||
{#each options as option (option.value)}
|
|
||||||
<option value={option.value}>{option.label}</option>
|
|
||||||
{/each}
|
|
||||||
</select>
|
|
||||||
<Icon
|
|
||||||
name="chevron"
|
|
||||||
class="pointer-events-none absolute top-1/2 right-4 -translate-y-1/2 text-neutral-400"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
type Kind = 'solid' | 'hollow' | 'dash' | 'alert';
|
|
||||||
|
|
||||||
let { kind, label, muted = false }: { kind: Kind; label: string; muted?: boolean } = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<span class={['flex items-center gap-3 text-sm', muted && 'text-neutral-400']}>
|
|
||||||
{#if kind === 'solid'}
|
|
||||||
<span aria-hidden="true" class="size-1.5 rounded-full bg-neutral-300"></span>
|
|
||||||
{:else if kind === 'hollow'}
|
|
||||||
<span aria-hidden="true" class="size-1.5 rounded-full border border-neutral-400"></span>
|
|
||||||
{:else if kind === 'dash'}
|
|
||||||
<span aria-hidden="true" class="h-px w-2 bg-neutral-400"></span>
|
|
||||||
{:else}
|
|
||||||
<span aria-hidden="true" class="font-medium text-neutral-100">!</span>
|
|
||||||
{/if}
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import type { Direction, ScheduledTransaction, WeekendAdjustment } from './types';
|
|
||||||
|
|
||||||
export const CURRENCY = 'EUR';
|
|
||||||
|
|
||||||
const numberFormat = new Intl.NumberFormat('en-GB', {
|
|
||||||
minimumFractionDigits: 2,
|
|
||||||
maximumFractionDigits: 2
|
|
||||||
});
|
|
||||||
|
|
||||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
||||||
|
|
||||||
export function formatMoney(cents: number): string {
|
|
||||||
return numberFormat.format(Math.abs(cents) / 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function signedCents(cents: number, direction: Direction): number {
|
|
||||||
return direction === 'in' ? cents : -cents;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatDate(iso: string): string {
|
|
||||||
const date = new Date(iso);
|
|
||||||
return `${String(date.getUTCDate()).padStart(2, '0')} ${months[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatRecurrence(every: number, unit: ScheduledTransaction['unit']): string {
|
|
||||||
return every === 1 ? `Every ${unit}` : `Every ${every} ${unit}s`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatWeekendAdjustment(adjustment: WeekendAdjustment | null): string | null {
|
|
||||||
if (adjustment === 'previous_business_day') return 'Previous business day';
|
|
||||||
if (adjustment === 'next_business_day') return 'Next business day';
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const monthsPerUnit = { day: 365 / 12, week: 52 / 12, month: 1, year: 1 / 12 } as const;
|
|
||||||
|
|
||||||
export function monthlyCents(item: Pick<ScheduledTransaction, 'amountCents' | 'every' | 'unit'>) {
|
|
||||||
return Math.round((item.amountCents * monthsPerUnit[item.unit]) / item.every);
|
|
||||||
}
|
|
||||||
@@ -1,253 +0,0 @@
|
|||||||
import type { Account, ScheduledTransaction, Transaction } from '../types';
|
|
||||||
|
|
||||||
export const accounts: Account[] = [
|
|
||||||
{ id: 'checking', name: 'Checking Account', balanceCents: 481240, memberCount: 2 },
|
|
||||||
{ id: 'savings', name: 'Savings Account', balanceCents: 1265000, memberCount: 1 },
|
|
||||||
{ id: 'card', name: 'Studio Card', balanceCents: 0, memberCount: 1 }
|
|
||||||
];
|
|
||||||
|
|
||||||
export const transactions: Transaction[] = [
|
|
||||||
{
|
|
||||||
id: 't01',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 240000,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-10-19T09:41:00Z',
|
|
||||||
description: 'Studio North'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't02',
|
|
||||||
accountId: 'card',
|
|
||||||
amountCents: 1500,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-19T07:12:00Z',
|
|
||||||
description: 'Figma'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't03',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 85000,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-18T08:00:00Z',
|
|
||||||
description: 'Workspace rent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't04',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 50000,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-17T14:20:00Z',
|
|
||||||
description: 'Bank transfer'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't05',
|
|
||||||
accountId: 'savings',
|
|
||||||
amountCents: 50000,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-10-17T14:20:00Z',
|
|
||||||
description: 'Bank transfer'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't06',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 8450,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-15T17:30:00Z',
|
|
||||||
description: 'Groceries'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't07',
|
|
||||||
accountId: 'card',
|
|
||||||
amountCents: 4290,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-14T08:05:00Z',
|
|
||||||
description: 'Train tickets'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't08',
|
|
||||||
accountId: 'card',
|
|
||||||
amountCents: 6400,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-12T12:45:00Z',
|
|
||||||
description: 'Client lunch'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't09',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 12600,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-10T06:00:00Z',
|
|
||||||
description: 'Electricity'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't10',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 160000,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-10-08T10:15:00Z',
|
|
||||||
description: 'Fieldwork'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't11',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 4500,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-05T06:00:00Z',
|
|
||||||
description: 'Mobile phone'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't12',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 320000,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-10-01T09:00:00Z',
|
|
||||||
description: 'Salary'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't13',
|
|
||||||
accountId: 'savings',
|
|
||||||
amountCents: 1840,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-10-01T00:00:00Z',
|
|
||||||
description: 'Interest'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't14',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 125000,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-10-01T09:00:00Z',
|
|
||||||
description: 'Rent'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't15',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 320000,
|
|
||||||
direction: 'in',
|
|
||||||
date: '2026-09-01T09:00:00Z',
|
|
||||||
description: 'Salary'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 't16',
|
|
||||||
accountId: 'savings',
|
|
||||||
amountCents: 8450,
|
|
||||||
direction: 'out',
|
|
||||||
date: '2026-09-18T17:30:00Z',
|
|
||||||
description: 'Groceries'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
export const scheduledTransactions: ScheduledTransaction[] = [
|
|
||||||
{
|
|
||||||
id: 's1',
|
|
||||||
name: 'Salary',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 320000,
|
|
||||||
direction: 'in',
|
|
||||||
every: 1,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-10-01T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: '2026-11-01T09:00:00Z',
|
|
||||||
weekendAdjustment: null,
|
|
||||||
status: 'active'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's2',
|
|
||||||
name: 'Rent',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 125000,
|
|
||||||
direction: 'out',
|
|
||||||
every: 1,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-10-01T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: '2026-10-30T09:00:00Z',
|
|
||||||
weekendAdjustment: 'previous_business_day',
|
|
||||||
status: 'due-soon'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's3',
|
|
||||||
name: 'Studio North retainer',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 240000,
|
|
||||||
direction: 'in',
|
|
||||||
every: 1,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-04-10T09:00:00Z',
|
|
||||||
endsAt: '2027-03-10T09:00:00Z',
|
|
||||||
nextDue: '2026-11-10T09:00:00Z',
|
|
||||||
weekendAdjustment: null,
|
|
||||||
status: 'active'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's4',
|
|
||||||
name: 'Figma',
|
|
||||||
accountId: 'card',
|
|
||||||
amountCents: 1500,
|
|
||||||
direction: 'out',
|
|
||||||
every: 1,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-01-19T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: '2026-11-19T09:00:00Z',
|
|
||||||
weekendAdjustment: null,
|
|
||||||
status: 'active'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's5',
|
|
||||||
name: 'Business insurance',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 28800,
|
|
||||||
direction: 'out',
|
|
||||||
every: 3,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-01-05T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: '2027-01-05T09:00:00Z',
|
|
||||||
weekendAdjustment: 'next_business_day',
|
|
||||||
status: 'active'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's6',
|
|
||||||
name: 'VAT payment',
|
|
||||||
accountId: 'checking',
|
|
||||||
amountCents: 142000,
|
|
||||||
direction: 'out',
|
|
||||||
every: 3,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-01-31T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: '2027-02-01T09:00:00Z',
|
|
||||||
weekendAdjustment: 'next_business_day',
|
|
||||||
status: 'active'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's7',
|
|
||||||
name: 'Savings transfer',
|
|
||||||
accountId: 'savings',
|
|
||||||
amountCents: 50000,
|
|
||||||
direction: 'in',
|
|
||||||
every: 1,
|
|
||||||
unit: 'month',
|
|
||||||
startsAt: '2026-03-17T09:00:00Z',
|
|
||||||
endsAt: null,
|
|
||||||
nextDue: null,
|
|
||||||
weekendAdjustment: null,
|
|
||||||
status: 'paused'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 's8',
|
|
||||||
name: 'Domain renewal',
|
|
||||||
accountId: 'card',
|
|
||||||
amountCents: 1800,
|
|
||||||
direction: 'out',
|
|
||||||
every: 1,
|
|
||||||
unit: 'year',
|
|
||||||
startsAt: '2025-06-01T09:00:00Z',
|
|
||||||
endsAt: '2026-06-01T09:00:00Z',
|
|
||||||
nextDue: null,
|
|
||||||
weekendAdjustment: null,
|
|
||||||
status: 'ended'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
export type Direction = 'in' | 'out';
|
|
||||||
|
|
||||||
export type RecurrenceUnit = 'day' | 'week' | 'month' | 'year';
|
|
||||||
|
|
||||||
export type WeekendAdjustment = 'previous_business_day' | 'next_business_day';
|
|
||||||
|
|
||||||
export type ScheduleStatus = 'active' | 'due-soon' | 'paused' | 'ended';
|
|
||||||
|
|
||||||
export type Account = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
balanceCents: number;
|
|
||||||
memberCount: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Transaction = {
|
|
||||||
id: string;
|
|
||||||
accountId: string;
|
|
||||||
amountCents: number;
|
|
||||||
direction: Direction;
|
|
||||||
date: string;
|
|
||||||
description: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type ScheduledTransaction = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
accountId: string;
|
|
||||||
amountCents: number;
|
|
||||||
direction: Direction;
|
|
||||||
every: number;
|
|
||||||
unit: RecurrenceUnit;
|
|
||||||
startsAt: string;
|
|
||||||
endsAt: string | null;
|
|
||||||
nextDue: string | null;
|
|
||||||
weekendAdjustment: WeekendAdjustment | null;
|
|
||||||
status: ScheduleStatus;
|
|
||||||
};
|
|
||||||
@@ -1,99 +1,6 @@
|
|||||||
<script lang="ts">
|
<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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Accounts | Expenses</title>
|
<title>Accounts | Expenses</title>
|
||||||
</svelte:head>
|
</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,150 +1,6 @@
|
|||||||
<script lang="ts">
|
<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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Scheduled transactions | Expenses</title>
|
<title>Scheduled transactions | Expenses</title>
|
||||||
</svelte:head>
|
</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,136 +1,6 @@
|
|||||||
<script lang="ts">
|
<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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<title>Transaction history | Expenses</title>
|
<title>Transaction history | Expenses</title>
|
||||||
</svelte:head>
|
</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>
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user