~james/core

core/web/src/lib/components/settings/SettingsBlock.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
60
61
62
63
64
65
<script lang="ts">
	import type { Snippet } from "svelte";
	import Separator from "#lib/components/ui/Separator.svelte";
	import { toLines } from "#lib/components/settings/descriptionLines.ts";

	interface Props {
		title?: string;
		titleSize?: "regular" | "large";
		description?: string | string[];
		action?: Snippet;
		separator?: boolean;
		children?: Snippet;
	}

	let {
		title,
		titleSize = "regular",
		description,
		action,
		separator = false,
		children
	}: Props = $props();

	const lines = $derived(toLines(description));
</script>

<div class="flex w-full flex-col gap-md">
	{#if title || lines.length > 0 || action}
		<div
			class="flex w-full flex-col gap-xs sm:flex-row sm:items-end sm:justify-between sm:gap-5xl"
		>
			<div class="flex min-w-0 flex-col">
				{#if title}
					<span
						data-testid="settingsBlockTitle"
						class="{titleSize === 'large'
							? 'typography-paragraph-large'
							: 'typography-paragraph-regular'} text-foreground-default"
					>
						{title}
					</span>
				{/if}
				{#each lines as line (line)}
					<p
						data-testid="settingsBlockDescription"
						class="typography-paragraph-regular text-foreground-muted"
					>
						{line}
					</p>
				{/each}
			</div>
			{#if action}
				<div class="flex shrink-0 items-center gap-xs self-end sm:self-auto">
					{@render action()}
				</div>
			{/if}
		</div>
	{/if}
	{#if separator}
		<Separator />
	{/if}
	{#if children}
		{@render children()}
	{/if}
</div>