File size: 872 Bytes
4e43408
a1a6daf
 
 
 
 
 
 
 
b104edb
 
 
 
 
 
 
4e43408
 
b104edb
a1a6daf
b104edb
4e43408
b104edb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e43408
 
 
 
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
<script lang="ts">
	interface Props {
		label?: string;
		position?: "top" | "bottom" | "left" | "right";
		TooltipClassNames?: string;
		children?: import("svelte").Snippet;
	}

	let { label = "", position = "bottom", TooltipClassNames = "", children }: Props = $props();

	const positionClasses = {
		top: "bottom-full mb-2",
		bottom: "top-full mt-2",
		left: "right-full mr-2 top-1/2 -translate-y-1/2",
		right: "left-full ml-2 top-1/2 -translate-y-1/2",
	};
</script>

<div class="group/tooltip inline-block md:relative">
	{@render children?.()}

	<div
		class="
		invisible
		absolute
		z-10
		w-64
		whitespace-normal
		rounded-md
		bg-black
		p-2
		text-center
		text-white
		group-hover/tooltip:visible
		group-active/tooltip:visible
		max-sm:left-1/2
		max-sm:-translate-x-1/2
		{positionClasses[position]}
		{TooltipClassNames}
	  "
	>
		{label}
	</div>
</div>