~james/core

core/web/src/lib/components/ui/EmptyState.svelte -rw-r--r-- 1.4 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
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
<script lang="ts">
	import Card, { type CardVariants } from "#lib/components/ui/Card.svelte";
	import type { Component, Snippet } from "svelte";
	import type { SvelteHTMLElements } from "svelte/elements";

	interface Props {
		message: string;
		messageDirection?: "horizontal" | "vertical";
		icon?: Component<SvelteHTMLElements["svg"]>;
		border?: CardVariants["border"];
		background?: CardVariants["background"];
		size?: "default" | "inline";
		class?: string;
		children?: Snippet;
	}

	let {
		message,
		messageDirection = "horizontal",
		icon,
		border = true,
		background = true,
		size = "default",
		class: className,
		children
	}: Props = $props();

	const Icon = $derived(icon);
</script>

{#if size === "inline"}
	<p
		data-testid="emptyState"
		class={[
			"flex items-center gap-xs typography-paragraph-regular text-foreground-muted",
			className
		]}
	>
		{message}{@render children?.()}
	</p>
{:else}
	<Card
		data-testid="emptyState"
		{border}
		{background}
		padding="none"
		class={[
			"flex flex-col items-center justify-center gap-xl p-4xl typography-paragraph-large text-foreground-subtle",
			className
		].join(" ")}
	>
		{#if Icon}
			<Icon class="size-16 text-foreground-disabled" aria-hidden="true" />
		{/if}
		<span class="flex items-center gap-sm {messageDirection === 'vertical' && 'flex-col'}"
			>{message}{@render children?.()}</span
		>
	</Card>
{/if}