Skip to content

Modern Docker Management, Designed for Everyone

2.1 KB
Raw Blame
<script lang="ts">
	import { Dialog as DialogPrimitive } from 'bits-ui';
	import type { Snippet } from 'svelte';

	import { CloseIcon } from '#lib/icons/index.js';
	import { m } from '#lib/paraglide/messages.js';
	import { cn, type WithoutChildrenOrChild } from '#lib/utils.js';

	import Overlay from './dialog-overlay.svelte';

	let {
		ref = $bindable(null),
		class: className,
		portalProps,
		children,
		showCloseButton = true,
		overlayClass,
		sectioned = false,
		...restProps
	}: WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
		portalProps?: DialogPrimitive.PortalProps;
		children: Snippet;
		showCloseButton?: boolean;
		overlayClass?: string;
		/** Flush layout for dialogs built from full-bleed sections; the footer becomes a ruled section. */
		sectioned?: boolean;
	} = $props();
</script>

<DialogPrimitive.Portal {...portalProps}>
	<Overlay class={overlayClass} />
	<DialogPrimitive.Content
		bind:ref
		data-sectioned={sectioned || undefined}
		data-slot="dialog-content"
		class={cn(
			'fixed top-[50%] left-[50%] z-(--arcane-z-surface) grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] grid-cols-[minmax(0,1fr)] gap-4 rounded-2xl border border-border/30 bg-white p-6 text-foreground shadow-lg backdrop-blur-md animation-duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:fill-mode-forwards data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:rounded-2xl dark:border-border/80 dark:bg-surface/10',
			sectioned && 'gap-0 p-0',
			className
		)}
		{...restProps}
	>
		{@render children?.()}
		{#if showCloseButton}
			<DialogPrimitive.Close
				class="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
			>
				<CloseIcon />
				<span class="sr-only">{m.common_close()}</span>
			</DialogPrimitive.Close>
		{/if}
	</DialogPrimitive.Content>
</DialogPrimitive.Portal>