Skip to content

Modern Docker Management, Designed for Everyone

1.3 KB
Raw Blame
<script lang="ts">
	import { ArcaneButton } from '#lib/components/arcane-button/index.js';
	import { useSidebar } from '#lib/components/ui/sidebar/context.svelte.js';
	import { PinOnIcon, PinOffIcon } from '#lib/icons/index.js';
	import { m } from '#lib/paraglide/messages.js';
	import { cn } from '#lib/utils.js';

	let {
		ref = $bindable(null),
		class: className,
		...restProps
	}: {
		ref?: HTMLElement | null;
		class?: string;
		[key: string]: any;
	} = $props();

	const sidebar = useSidebar();
	const isPinned = $derived(sidebar.isPinned);
</script>

<ArcaneButton
	bind:ref
	data-sidebar="pin-button"
	data-slot="sidebar-pin-button"
	action="base"
	tone="ghost"
	size="icon"
	class={cn('size-7 text-muted-foreground hover:text-foreground', className)}
	type="button"
	disabled={sidebar.isTablet}
	title={isPinned ? m.common_unpin_sidebar() : m.common_pin_sidebar()}
	onclick={(e) => {
		e.preventDefault();
		e.stopPropagation();
		if (!sidebar.isTablet) {
			// Always toggle the pinning preference
			sidebar.toggle();
			// Clear hover state when explicitly pinning/unpinning
			if (sidebar.isHovered) {
				sidebar.setHovered(false);
			}
		}
	}}
	{...restProps}
>
	{#if isPinned}
		<PinOnIcon />
		<span class="sr-only">{m.common_unpin_sidebar()}</span>
	{:else}
		<PinOffIcon />
		<span class="sr-only">{m.common_pin_sidebar()}</span>
	{/if}
</ArcaneButton>