summaryrefslogtreecommitdiffstatshomepage
path: root/frontend/src/lib/toolbar/SelectionControls.svelte
blob: f0026c8d91c598dc7ad6a0e45c0c7bb89b7c933b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<script lang="ts">
	import Badge from '$lib/components/Badge.svelte';
	import { getSelectionContext } from '$lib/selection/Selection.svelte';
	import { accelerator } from '$lib/Shortcuts';
	import { fadeDefault, slideXFast } from '$lib/Transitions';
	import { onDestroy, type Snippet } from 'svelte';
	import { fade, slide } from 'svelte/transition';

	let { page = false, children }: { page?: boolean; children?: Snippet } = $props();
	let selection = getSelectionContext();

	onDestroy(selection.clear);
</script>

<div class="rounded-group flex">
	<button
		type="button"
		class="btn-slate relative"
		class:toggled={selection.active}
		title={`${selection.active ? 'Exit' : 'Enter'} ${page ? 'page ' : ' '}selection mode`}
		onclick={selection.toggle}
		use:accelerator={'s'}
	>
		{#if selection.active}
			{#if page}
				<span class="icon-base icon-[material-symbols--edit-document]"></span>
			{:else}
				<span class="icon-base icon-[material-symbols--remove-selection]"></span>
			{/if}
		{:else if page}
			<span class="icon-base icon-[material-symbols--edit-document-outline]"></span>
		{:else}
			<span class="icon-base icon-[material-symbols--select]"></span>
		{/if}
		<Badge number={selection.size} />
	</button>
	{#if selection.active}
		<div class="rounded-group-end flex" transition:slide={slideXFast}>
			<button
				type="button"
				class="btn-slate"
				title="Select all"
				aria-label="Select all"
				onclick={selection.all}
			>
				<span class="icon-base icon-[material-symbols--select-all]"></span>
			</button>
			<button
				type="button"
				class="btn-slate"
				title="Select none"
				aria-label="Select all"
				onclick={selection.none}
			>
				<span class="icon-base icon-[material-symbols--deselect]"></span>
			</button>
		</div>
	{/if}
</div>
{#if selection.size > 0}
	<div class="rounded-group flex" transition:fade={fadeDefault}>
		{@render children?.()}
	</div>
{/if}