~james/core

core/web/src/lib/components/ui/Card.svelte -rw-r--r-- 1.3 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
66
<script module lang="ts">
	import { tv, type VariantProps } from "tailwind-variants";

	export const card = tv({
		base: "overflow-clip",
		variants: {
			rounded: {
				true: "rounded-md",
				false: ""
			},
			border: {
				true: "edge-ring ring-border-default",
				false: ""
			},
			background: {
				true: "bg-background-default",
				false: ""
			},
			padding: {
				regular: "p-sm",
				small: "p-xs",
				none: ""
			}
		},
		defaultVariants: {
			rounded: true,
			border: true,
			background: true,
			padding: "regular"
		}
	});

	export type CardVariants = VariantProps<typeof card>;
</script>

<script lang="ts">
	import type { Snippet } from "svelte";
	import type { HTMLAttributes } from "svelte/elements";

	interface Props extends Omit<HTMLAttributes<HTMLDivElement>, "class" | "children"> {
		rounded?: CardVariants["rounded"];
		border?: CardVariants["border"];
		background?: CardVariants["background"];
		padding?: CardVariants["padding"];
		class?: string;
		children?: Snippet;
	}

	let {
		rounded = true,
		border = true,
		background = true,
		padding = "regular",
		class: className,
		children,
		...rest
	}: Props = $props();

	const classes = $derived(card({ rounded, border, background, padding, class: className }));
</script>

<div class={classes} {...rest}>
	{#if children}
		{@render children()}
	{/if}
</div>