Might be better DX.

This commit is contained in:
2026-10-24 10:35:10 +02:00
parent 48496f47fc
commit a9866654ac
2 changed files with 5 additions and 4 deletions
+4 -3
View File
@@ -27,7 +27,8 @@
}[keyof T];
export type Style = 'highlight';
export type StyleFn<T> = (key: keyof T, row?: T) => Style[];
export type StyleTarget<T> = { key: keyof T; row?: T };
export type StyleFn<T> = (target: StyleTarget<T>) => Style[];
export type TableProps<T> = {
columns: Column<T>[];
@@ -89,7 +90,7 @@
<thead class="col-span-full grid grid-cols-subgrid">
<tr class="col-span-full grid grid-cols-subgrid">
{#each sizedColumns as { column: c, sizing: s } (c.key)}
{@const styles = style?.(c.key) ?? []}
{@const styles = style?.({ key: c.key }) ?? []}
<th
class={'px-4 py-3 text-sm font-bold text-neutral-400' +
(c.wrap ? ' wrap-break-words' : ' truncate') +
@@ -109,7 +110,7 @@
{#each data as d (d.id)}
<tr class="col-span-full grid grid-cols-subgrid hover:bg-neutral-900">
{#each sizedColumns as { column: c, sizing: s } (c.key)}
{@const styles = style?.(c.key, d) ?? []}
{@const styles = style?.({ key: c.key, row: d }) ?? []}
<td
class={'border-t border-neutral-700 px-4 py-2.5 tabular-nums' +
(c.wrap ? ' wrap-break-words' : ' truncate') +
@@ -52,7 +52,7 @@
<title>Scheduled transactions | Expenses</title>
</svelte:head>
<Table {columns} {data} style={(_key, row) => (row?.checked ? ['highlight'] : [])}>
<Table {columns} {data} style={({ row }) => (row?.checked ? ['highlight'] : [])}>
{#snippet header({ key, label })}
{#if key === 'checked'}
<input