Dynamic styling.

This commit is contained in:
2026-10-24 10:31:22 +02:00
parent e0d0631e74
commit 48496f47fc
2 changed files with 53 additions and 16 deletions
@@ -1,7 +1,6 @@
<script lang="ts">
import Table, { type Column } from '#lib/components/table.svelte';
<script lang="ts" module>
type ScheduledTransaction = {
checked: boolean;
id: number;
name: string;
description: string;
@@ -10,12 +9,20 @@
};
const columns: Column<ScheduledTransaction>[] = [
{ key: 'checked' },
{ key: 'id', label: '#' },
{ key: 'name', label: 'Name', ratio: 1 },
{ key: 'account', label: 'Account' },
{ key: 'amount', label: 'Amount' }
];
const data: ScheduledTransaction[] = [
</script>
<script lang="ts">
import Table, { type Column } from '#lib/components/table.svelte';
const data: ScheduledTransaction[] = $state([
{
checked: true,
id: 1,
name: 'Some transaction',
description: 'Some description',
@@ -23,6 +30,7 @@
amount: 100
},
{
checked: false,
id: 2,
name: 'Another transaction',
description: 'Another description',
@@ -30,17 +38,37 @@
amount: 200
},
{
checked: true,
id: 3,
name: 'Yet another transaction',
description: 'Yet another description, but longer than the others',
account: 'Yet another account',
amount: 300
}
];
]);
</script>
<svelte:head>
<title>Scheduled transactions | Expenses</title>
</svelte:head>
<Table {columns} {data} />
<Table {columns} {data} style={(_key, row) => (row?.checked ? ['highlight'] : [])}>
{#snippet header({ key, label })}
{#if key === 'checked'}
<input
type="checkbox"
onchange={(e) => data.forEach((row) => (row.checked = e.currentTarget.checked))}
checked={data.every((row) => row.checked)}
/>
{:else}
{label}
{/if}
{/snippet}
{#snippet cell({ key, value, row })}
{#if key === 'checked'}
<input type="checkbox" bind:checked={row.checked} />
{:else}
{value}
{/if}
{/snippet}
</Table>