File size: 1,465 Bytes
c6c1fff
 
 
 
 
 
 
 
6b57de3
fbef5e8
6b57de3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e24cc70
 
 
 
fbef5e8
6b57de3
e24cc70
6b57de3
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<script lang="ts" module>
	let img = $state<string>();

	export const previewImage = (i: string) => {
		img = i;
	};
</script>

<script lang="ts">
	import { clickOutside } from "$lib/attachments/click-outside.js";
	import { fade, scale } from "svelte/transition";
	import IconCross from "~icons/carbon/close";

	let dialog: HTMLDialogElement | undefined = $state();

	$effect(() => {
		if (img) {
			dialog?.showModal();
		} else {
			setTimeout(() => dialog?.close(), 250);
		}
	});
</script>

<dialog
	class="backdrop:bg-transparent"
	bind:this={dialog}
	onclose={e => {
		e.preventDefault();
		img = undefined;
	}}
>
	{#if img}
		<!-- Backdrop -->
		<div
			class="fixed inset-0 z-50 flex items-center justify-center overflow-hidden bg-black/50 backdrop-blur-sm"
			transition:fade={{ duration: 150 }}
		>
			<!-- Content -->
			<img
				class="max-h-[calc(100vh-120px)] max-w-[calc(100vw-120px)] object-contain"
				src={img}
				alt=""
				{@attach clickOutside(() => (img = undefined))}
				transition:scale={{ start: 0.975, duration: 250 }}
			/>

			<button
				type="button"
				class="absolute top-3 right-3 inline-flex h-8 w-8 items-center justify-center rounded-lg bg-transparent text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-600 dark:hover:text-white"
				onclick={() => (img = undefined)}
				aria-label="Close modal"
			>
				<div class="text-xl">
					<IconCross />
				</div>
			</button>
		</div>
	{/if}
</dialog>