Might be better DX.
This commit is contained in:
@@ -27,7 +27,8 @@
|
|||||||
}[keyof T];
|
}[keyof T];
|
||||||
|
|
||||||
export type Style = 'highlight';
|
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> = {
|
export type TableProps<T> = {
|
||||||
columns: Column<T>[];
|
columns: Column<T>[];
|
||||||
@@ -89,7 +90,7 @@
|
|||||||
<thead class="col-span-full grid grid-cols-subgrid">
|
<thead class="col-span-full grid grid-cols-subgrid">
|
||||||
<tr 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)}
|
{#each sizedColumns as { column: c, sizing: s } (c.key)}
|
||||||
{@const styles = style?.(c.key) ?? []}
|
{@const styles = style?.({ key: c.key }) ?? []}
|
||||||
<th
|
<th
|
||||||
class={'px-4 py-3 text-sm font-bold text-neutral-400' +
|
class={'px-4 py-3 text-sm font-bold text-neutral-400' +
|
||||||
(c.wrap ? ' wrap-break-words' : ' truncate') +
|
(c.wrap ? ' wrap-break-words' : ' truncate') +
|
||||||
@@ -109,7 +110,7 @@
|
|||||||
{#each data as d (d.id)}
|
{#each data as d (d.id)}
|
||||||
<tr class="col-span-full grid grid-cols-subgrid hover:bg-neutral-900">
|
<tr class="col-span-full grid grid-cols-subgrid hover:bg-neutral-900">
|
||||||
{#each sizedColumns as { column: c, sizing: s } (c.key)}
|
{#each sizedColumns as { column: c, sizing: s } (c.key)}
|
||||||
{@const styles = style?.(c.key, d) ?? []}
|
{@const styles = style?.({ key: c.key, row: d }) ?? []}
|
||||||
<td
|
<td
|
||||||
class={'border-t border-neutral-700 px-4 py-2.5 tabular-nums' +
|
class={'border-t border-neutral-700 px-4 py-2.5 tabular-nums' +
|
||||||
(c.wrap ? ' wrap-break-words' : ' truncate') +
|
(c.wrap ? ' wrap-break-words' : ' truncate') +
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
<title>Scheduled transactions | Expenses</title>
|
<title>Scheduled transactions | Expenses</title>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Table {columns} {data} style={(_key, row) => (row?.checked ? ['highlight'] : [])}>
|
<Table {columns} {data} style={({ row }) => (row?.checked ? ['highlight'] : [])}>
|
||||||
{#snippet header({ key, label })}
|
{#snippet header({ key, label })}
|
||||||
{#if key === 'checked'}
|
{#if key === 'checked'}
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in New Issue
Block a user