Skip to content

Modern Docker Management, Designed for Everyone

2.2 KB
Raw Blame
<script lang="ts">
	import { m } from '#lib/paraglide/messages.js';

	interface Props {
		active?: boolean;
		delay?: number;
		minDuration?: number;
		thickness?: string;
		class?: string;
	}

	let { active = false, delay = 80, minDuration = 350, thickness = 'h-2', class: className = '' }: Props = $props();

	let visible = $state(false);
	let startedAt = 0;
	let showTO: ReturnType<typeof setTimeout> | undefined;
	let hideTO: ReturnType<typeof setTimeout> | undefined;

	function clearTimers() {
		clearTimeout(showTO);
		clearTimeout(hideTO);
	}

	$effect(() => {
		clearTimers();
		if (active) {
			showTO = setTimeout(() => {
				visible = true;
				startedAt = performance.now();
			}, delay);
		} else {
			const elapsed = performance.now() - startedAt;
			const remaining = Math.max(0, minDuration - elapsed);
			hideTO = setTimeout(() => (visible = false), remaining);
		}
		return clearTimers;
	});
</script>

{#if visible}
	<div
		class={`pointer-events-none fixed inset-x-0 top-0 z-(--arcane-z-loading) ${thickness} ${className}`}
		role="progressbar"
		aria-busy="true"
		aria-label={m.common_loading()}
	>
		<div class="relative h-full w-full overflow-hidden">
			<div class="absolute inset-0 bg-primary/25"></div>

			<div class="bar absolute inset-y-0 left-0 w-1/3">
				<div class="peg absolute top-0 right-0 h-full w-3"></div>
			</div>

			<div class="bar bar-offset absolute inset-y-0 left-0 w-1/3">
				<div class="peg absolute top-0 right-0 h-full w-3"></div>
			</div>

			<span class="sr-only">{m.common_loading()}</span>
		</div>
	</div>
{/if}

<style>
	.bar {
		background: var(--primary);
		animation: arcane-slide 2s linear infinite;
		box-shadow:
			0 0 12px var(--primary),
			0 0 2px var(--primary);
		opacity: 0.95;
	}

	.bar-offset {
		animation-delay: -1s;
	}

	.peg {
		background: linear-gradient(
			to right,
			color-mix(in oklab, var(--primary) 0%, transparent),
			color-mix(in oklab, var(--primary) 90%, transparent)
		);
		filter: blur(2px);
	}

	@keyframes arcane-slide {
		0% {
			transform: translateX(-100%);
		}
		100% {
			transform: translateX(300%);
		}
	}

	@media (prefers-reduced-motion: reduce) {
		.bar {
			animation-duration: 4s;
		}
	}
</style>