Files
gpx.studio/website/src/lib/components/toolbar/ToolbarItem.svelte

46 lines
1.2 KiB
Svelte
Raw Normal View History

2024-04-09 18:46:01 +02:00
<script lang="ts">
import { Button } from '$lib/components/ui/button';
import * as Tooltip from '$lib/components/ui/tooltip/index.js';
2025-10-17 23:54:45 +02:00
import { tool, Tool } from '$lib/components/toolbar/tools';
2025-06-21 21:07:36 +02:00
import type { Snippet } from 'svelte';
2025-06-21 21:07:36 +02:00
let {
itemTool,
label,
children,
}: {
itemTool: Tool;
label: string;
children: Snippet;
} = $props();
function toggleTool() {
2025-06-21 21:07:36 +02:00
if (tool.current === itemTool) {
tool.current = null;
} else {
tool.current = itemTool;
}
}
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>