summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/selection/Selectable.svelte
diff options
context:
space:
mode:
authorWolfgang Müller2025-02-13 17:52:16 +0100
committerWolfgang Müller2025-02-13 17:52:16 +0100
commitdc4db405d2991d3ec6a114f3b08d3fccd057d3ee (patch)
tree2c620c9af2062ba09fa591f8b3ed961664adab58 /frontend/src/lib/selection/Selectable.svelte
parent4df870d793123be95c8af031a340a39b5b8402ac (diff)
downloadhircine-dc4db405d2991d3ec6a114f3b08d3fccd057d3ee.tar.gz
frontend: Migrate to Svelte 5
Diffstat (limited to 'frontend/src/lib/selection/Selectable.svelte')
-rw-r--r--frontend/src/lib/selection/Selectable.svelte26
1 files changed, 14 insertions, 12 deletions
diff --git a/frontend/src/lib/selection/Selectable.svelte b/frontend/src/lib/selection/Selectable.svelte
index 48b6ac7..4705f44 100644
--- a/frontend/src/lib/selection/Selectable.svelte
+++ b/frontend/src/lib/selection/Selectable.svelte
@@ -1,18 +1,20 @@
<script lang="ts">
- import { getSelectionContext } from '$lib/Selection';
+ import type { Snippet } from 'svelte';
+ import { getSelectionContext } from './Selection.svelte';
- export let id: number;
- export let index: number;
+ interface Props {
+ id: number;
+ index: number;
+ edit?: ((id: number) => void) | undefined;
+ children?: Snippet<[{ onclick: (event: MouseEvent) => void; selected: boolean }]>;
+ }
- export let edit: ((id: number) => void) | undefined = undefined;
+ let { id, index, edit = undefined, children }: Props = $props();
+ let selection = getSelectionContext();
- const selection = getSelectionContext();
-
- $: selected = $selection.contains(id);
-
- const handle = (event: MouseEvent) => {
- if ($selection.active) {
- $selection = $selection.update(index, event.shiftKey);
+ const onclick = (event: MouseEvent) => {
+ if (selection.active) {
+ selection.update(index, event.shiftKey);
event.preventDefault();
} else if (edit) {
edit(id);
@@ -21,4 +23,4 @@
};
</script>
-<slot {handle} {selected} />
+{@render children?.({ onclick, selected: selection.contains(id) })}