Added styled check button.

This commit is contained in:
2026-10-24 12:32:32 +02:00
parent 06fc8e3381
commit e0cd2f766e
2 changed files with 38 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
<script lang="ts" module>
import type { ChangeEventHandler } from 'svelte/elements';
export type CheckboxProps = {
label?: string;
checked?: boolean;
onchange?: ChangeEventHandler<HTMLInputElement>;
};
</script>
<script lang="ts">
let { label, checked = $bindable(), onchange }: CheckboxProps = $props();
</script>
<label class="group inline-flex cursor-pointer items-center gap-3 select-none">
<input type="checkbox" class="peer sr-only" bind:checked {onchange} />
<div
class="flex h-4 w-4 items-center justify-center rounded-sm border border-neutral-700 bg-neutral-900 group-hover:border-neutral-500 peer-checked:border-neutral-100 peer-checked:bg-neutral-100 peer-focus-visible:ring-2 peer-focus-visible:ring-neutral-400 peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-black peer-checked:[&>svg]:opacity-100"
>
<svg
class="h-3 w-3 stroke-3 text-neutral-900 opacity-0"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />
</svg>
</div>
{#if label}
<span class="text-sm text-neutral-300 group-hover:text-neutral-100">
{label}
</span>
{/if}
</label>
@@ -18,6 +18,7 @@
</script>
<script lang="ts">
import Checkbox from '#lib/components/checkbox.svelte';
import Table, { type Column } from '#lib/components/table.svelte';
const data: ScheduledTransaction[] = $state([
@@ -55,8 +56,7 @@
<Table {columns} {data} style={({ row }) => (row?.checked ? ['highlight'] : [])}>
{#snippet header({ key, label })}
{#if key === 'checked'}
<input
type="checkbox"
<Checkbox
onchange={(e) => data.forEach((row) => (row.checked = e.currentTarget.checked))}
checked={data.every((row) => row.checked)}
/>
@@ -66,7 +66,7 @@
{/snippet}
{#snippet cell({ key, value, row })}
{#if key === 'checked'}
<input type="checkbox" bind:checked={row.checked} />
<Checkbox bind:checked={row.checked} />
{:else}
{value}
{/if}