2024-04-09 18:46:01 +02:00
|
|
|
<script lang="ts">
|
2025-02-02 11:17:22 +01:00
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
|
import * as Tooltip from '$lib/components/ui/tooltip/index.js';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { tool, Tool } from '$lib/components/toolbar/utils.svelte';
|
|
|
|
|
import type { Snippet } from 'svelte';
|
2024-04-28 18:59:31 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
let {
|
|
|
|
|
itemTool,
|
|
|
|
|
label,
|
|
|
|
|
children,
|
|
|
|
|
}: {
|
|
|
|
|
itemTool: Tool;
|
|
|
|
|
label: string;
|
|
|
|
|
children: Snippet;
|
|
|
|
|
} = $props();
|
2024-04-28 18:59:31 +02:00
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
function toggleTool() {
|
2025-06-21 21:07:36 +02:00
|
|
|
if (tool.current === itemTool) {
|
|
|
|
|
tool.current = null;
|
|
|
|
|
} else {
|
|
|
|
|
tool.current = itemTool;
|
|
|
|
|
}
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
2024-04-09 18:46:01 +02:00
|
|
|
</script>
|
|
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
<Tooltip.Provider>
|
|
|
|
|
<Tooltip.Root delayDuration={300}>
|
|
|
|
|
<Tooltip.Trigger>
|
|
|
|
|
{#snippet child({ props })}
|
|
|
|
|
<Button
|
|
|
|
|
{...props}
|
|
|
|
|
variant="ghost"
|
|
|
|
|
class="h-[26px] px-1 py-1.5 {tool.current === itemTool ? 'bg-accent' : ''}"
|
|
|
|
|
onclick={toggleTool}
|
|
|
|
|
aria-label={label}
|
|
|
|
|
>
|
|
|
|
|
{@render children()}
|
|
|
|
|
</Button>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</Tooltip.Trigger>
|
|
|
|
|
<Tooltip.Content side="right">
|
|
|
|
|
<span>{label}</span>
|
|
|
|
|
</Tooltip.Content>
|
|
|
|
|
</Tooltip.Root>
|
|
|
|
|
</Tooltip.Provider>
|