@glasshome/ui 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/SPEC.md +7 -0
  2. package/dist/index.js +1 -1
  3. package/dist/lib/menu-classes.d.ts +2 -2
  4. package/dist/solid/icon.d.ts +18 -12
  5. package/dist/solid/index.d.ts +1 -0
  6. package/dist/solid/index.js +3692 -3490
  7. package/dist/{utils-CIwpbaOd.js → utils-CdUh67Y9.js} +1 -1
  8. package/package.json +7 -3
  9. package/scripts/check-pack.ts +32 -0
  10. package/src/index.ts +111 -0
  11. package/src/lib/menu-classes.ts +1 -1
  12. package/src/solid/accordion.tsx +60 -0
  13. package/src/solid/alert-dialog.tsx +148 -0
  14. package/src/solid/alert.tsx +118 -0
  15. package/src/solid/area-picker.tsx +225 -0
  16. package/src/solid/aspect-ratio.tsx +21 -0
  17. package/src/solid/avatar.tsx +41 -0
  18. package/src/solid/badge.tsx +74 -0
  19. package/src/solid/bottom-sheet/arbitration.ts +40 -0
  20. package/src/solid/bottom-sheet/bottom-sheet.tsx +457 -0
  21. package/src/solid/bottom-sheet/constants.ts +8 -0
  22. package/src/solid/bottom-sheet/drag-controller.ts +221 -0
  23. package/src/solid/bottom-sheet/focus-trap.ts +56 -0
  24. package/src/solid/bottom-sheet/index.ts +14 -0
  25. package/src/solid/bottom-sheet/keyboard.ts +35 -0
  26. package/src/solid/bottom-sheet/scroll-lock.ts +64 -0
  27. package/src/solid/bottom-sheet/state-machine.ts +40 -0
  28. package/src/solid/bottom-sheet/velocity.ts +42 -0
  29. package/src/solid/breadcrumb.tsx +105 -0
  30. package/src/solid/button-group.tsx +66 -0
  31. package/src/solid/button.tsx +20 -0
  32. package/src/solid/card.tsx +101 -0
  33. package/src/solid/carousel.tsx +302 -0
  34. package/src/solid/charts.tsx +338 -0
  35. package/src/solid/checkbox.tsx +70 -0
  36. package/src/solid/collapsible.tsx +38 -0
  37. package/src/solid/color-slider.tsx +98 -0
  38. package/src/solid/color-wheel.tsx +77 -0
  39. package/src/solid/context-menu.tsx +109 -0
  40. package/src/solid/copy-button.tsx +46 -0
  41. package/src/solid/count-pill.tsx +24 -0
  42. package/src/solid/data-table.tsx +248 -0
  43. package/src/solid/dialog-parts.tsx +242 -0
  44. package/src/solid/dialog.tsx +121 -0
  45. package/src/solid/dock.tsx +186 -0
  46. package/src/solid/dropdown-menu.tsx +130 -0
  47. package/src/solid/empty.tsx +99 -0
  48. package/src/solid/entity-data.ts +78 -0
  49. package/src/solid/entity-selector.tsx +697 -0
  50. package/src/solid/field.tsx +253 -0
  51. package/src/solid/form.tsx +231 -0
  52. package/src/solid/hero-action.tsx +117 -0
  53. package/src/solid/hover-card.tsx +26 -0
  54. package/src/solid/icon-picker.tsx +432 -0
  55. package/src/solid/icon.tsx +126 -0
  56. package/src/solid/image-picker.tsx +380 -0
  57. package/src/solid/index.ts +413 -0
  58. package/src/solid/input-group.tsx +170 -0
  59. package/src/solid/input-otp.tsx +175 -0
  60. package/src/solid/input.tsx +12 -0
  61. package/src/solid/item.tsx +179 -0
  62. package/src/solid/kbd.tsx +30 -0
  63. package/src/solid/label.tsx +19 -0
  64. package/src/solid/list-reorder.ts +148 -0
  65. package/src/solid/logo.tsx +79 -0
  66. package/src/solid/media-copy.ts +37 -0
  67. package/src/solid/media-store.ts +110 -0
  68. package/src/solid/media-tile.tsx +100 -0
  69. package/src/solid/menu-parts.tsx +248 -0
  70. package/src/solid/number-field.tsx +72 -0
  71. package/src/solid/option-card.tsx +218 -0
  72. package/src/solid/ornament.tsx +53 -0
  73. package/src/solid/overlay.tsx +16 -0
  74. package/src/solid/page-header.tsx +102 -0
  75. package/src/solid/pagination.tsx +111 -0
  76. package/src/solid/password-input.tsx +69 -0
  77. package/src/solid/picker-row.tsx +102 -0
  78. package/src/solid/picker-search.tsx +78 -0
  79. package/src/solid/popover.tsx +103 -0
  80. package/src/solid/progress.tsx +31 -0
  81. package/src/solid/radio-group.tsx +60 -0
  82. package/src/solid/resizable.tsx +149 -0
  83. package/src/solid/responsive-dialog.tsx +180 -0
  84. package/src/solid/schema-form.tsx +830 -0
  85. package/src/solid/scope-indicator.tsx +13 -0
  86. package/src/solid/scroll-area.tsx +27 -0
  87. package/src/solid/section-card.tsx +358 -0
  88. package/src/solid/select.tsx +139 -0
  89. package/src/solid/separator.tsx +35 -0
  90. package/src/solid/settings-row.tsx +159 -0
  91. package/src/solid/sheet.tsx +157 -0
  92. package/src/solid/skeleton.tsx +15 -0
  93. package/src/solid/slider.tsx +148 -0
  94. package/src/solid/sliding-indicator.tsx +294 -0
  95. package/src/solid/sonner.tsx +217 -0
  96. package/src/solid/spinner.tsx +20 -0
  97. package/src/solid/step-indicator.tsx +30 -0
  98. package/src/solid/switch.tsx +62 -0
  99. package/src/solid/table.tsx +98 -0
  100. package/src/solid/tabs.tsx +86 -0
  101. package/src/solid/textarea.tsx +16 -0
  102. package/src/solid/toggle-group.tsx +102 -0
  103. package/src/solid/toggle.tsx +57 -0
  104. package/src/solid/tooltip.tsx +38 -0
  105. package/src/solid/widget-card.tsx +117 -0
  106. package/src/solid/widget-identity.tsx +135 -0
  107. package/src/solid/widget-trust-badge.tsx +37 -0
  108. package/src/styles/globals.css +7 -0
  109. package/src/styles/theme.css +8 -0
  110. package/src/tokens/hex.ts +50 -0
  111. package/src/tokens/index.ts +8 -0
  112. package/src/tokens/presets.ts +192 -0
  113. package/src/tokens/theme-colors.ts +147 -0
@@ -0,0 +1,56 @@
1
+ const FOCUSABLE_SELECTOR =
2
+ 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
3
+
4
+ export type InitialFocus = "container" | "first" | ((root: HTMLElement) => HTMLElement | null);
5
+
6
+ interface TrapHandle {
7
+ release: () => void;
8
+ }
9
+
10
+ export function trapFocus(root: HTMLElement, initial: InitialFocus = "container"): TrapHandle {
11
+ const previouslyFocused = (document.activeElement as HTMLElement | null) ?? null;
12
+
13
+ const focusTarget: HTMLElement | null =
14
+ initial === "container"
15
+ ? root
16
+ : initial === "first"
17
+ ? (root.querySelector<HTMLElement>(FOCUSABLE_SELECTOR) ?? root)
18
+ : initial(root);
19
+
20
+ focusTarget?.focus({ preventScroll: true });
21
+
22
+ const onKeyDown = (e: KeyboardEvent) => {
23
+ if (e.key !== "Tab") return;
24
+ const focusable = Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(
25
+ (el) => !el.hasAttribute("disabled") && el.offsetParent !== null,
26
+ );
27
+ if (focusable.length === 0) {
28
+ e.preventDefault();
29
+ root.focus({ preventScroll: true });
30
+ return;
31
+ }
32
+ const first = focusable[0];
33
+ const last = focusable[focusable.length - 1];
34
+ const active = document.activeElement as HTMLElement | null;
35
+ if (e.shiftKey) {
36
+ if (active === first || active === root || !root.contains(active)) {
37
+ e.preventDefault();
38
+ last?.focus({ preventScroll: true });
39
+ }
40
+ } else {
41
+ if (active === last) {
42
+ e.preventDefault();
43
+ first?.focus({ preventScroll: true });
44
+ }
45
+ }
46
+ };
47
+
48
+ document.addEventListener("keydown", onKeyDown);
49
+
50
+ return {
51
+ release() {
52
+ document.removeEventListener("keydown", onKeyDown);
53
+ previouslyFocused?.focus?.({ preventScroll: true });
54
+ },
55
+ };
56
+ }
@@ -0,0 +1,14 @@
1
+ export {
2
+ BottomSheet,
3
+ BottomSheetBody,
4
+ BottomSheetClose,
5
+ BottomSheetContent,
6
+ BottomSheetDescription,
7
+ BottomSheetFooter,
8
+ BottomSheetHandle,
9
+ BottomSheetHeader,
10
+ BottomSheetOverlay,
11
+ BottomSheetPortal,
12
+ BottomSheetTitle,
13
+ BottomSheetTrigger,
14
+ } from "./bottom-sheet.js";
@@ -0,0 +1,35 @@
1
+ const KEYBOARD_THRESHOLD_PX = 100;
2
+
3
+ export interface KeyboardWatchHandle {
4
+ destroy: () => void;
5
+ }
6
+
7
+ export function watchKeyboard(el: HTMLElement): KeyboardWatchHandle {
8
+ if (typeof window === "undefined") return { destroy: () => {} };
9
+ const vv = window.visualViewport;
10
+ if (!vv) return { destroy: () => {} };
11
+
12
+ const update = () => {
13
+ const offset = Math.max(0, window.innerHeight - vv.height - vv.offsetTop);
14
+ if (offset > KEYBOARD_THRESHOLD_PX) {
15
+ el.style.setProperty("--bs-keyboard-offset", `${offset}px`);
16
+ el.setAttribute("data-keyboard-open", "");
17
+ } else {
18
+ el.style.removeProperty("--bs-keyboard-offset");
19
+ el.removeAttribute("data-keyboard-open");
20
+ }
21
+ };
22
+
23
+ vv.addEventListener("resize", update);
24
+ vv.addEventListener("scroll", update);
25
+ update();
26
+
27
+ return {
28
+ destroy() {
29
+ vv.removeEventListener("resize", update);
30
+ vv.removeEventListener("scroll", update);
31
+ el.style.removeProperty("--bs-keyboard-offset");
32
+ el.removeAttribute("data-keyboard-open");
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,64 @@
1
+ let refcount = 0;
2
+ let savedScrollY = 0;
3
+ let savedBodyStyles: {
4
+ position: string;
5
+ top: string;
6
+ left: string;
7
+ right: string;
8
+ width: string;
9
+ overflow: string;
10
+ } | null = null;
11
+
12
+ function isIOS(): boolean {
13
+ if (typeof navigator === "undefined") return false;
14
+ const ua = navigator.userAgent;
15
+ return /iP(ad|hone|od)/.test(ua) || (ua.includes("Mac") && "ontouchend" in document);
16
+ }
17
+
18
+ export function acquireScrollLock(): void {
19
+ refcount++;
20
+ if (refcount > 1) return;
21
+ if (typeof document === "undefined") return;
22
+
23
+ const body = document.body;
24
+ savedBodyStyles = {
25
+ position: body.style.position,
26
+ top: body.style.top,
27
+ left: body.style.left,
28
+ right: body.style.right,
29
+ width: body.style.width,
30
+ overflow: body.style.overflow,
31
+ };
32
+
33
+ if (isIOS()) {
34
+ savedScrollY = window.scrollY;
35
+ body.style.position = "fixed";
36
+ body.style.top = `-${savedScrollY}px`;
37
+ body.style.left = "0";
38
+ body.style.right = "0";
39
+ body.style.width = "100%";
40
+ } else {
41
+ body.style.overflow = "hidden";
42
+ }
43
+ }
44
+
45
+ export function releaseScrollLock(): void {
46
+ refcount = Math.max(0, refcount - 1);
47
+ if (refcount > 0) return;
48
+ if (typeof document === "undefined" || !savedBodyStyles) return;
49
+
50
+ const body = document.body;
51
+ const wasIOS = body.style.position === "fixed";
52
+
53
+ body.style.position = savedBodyStyles.position;
54
+ body.style.top = savedBodyStyles.top;
55
+ body.style.left = savedBodyStyles.left;
56
+ body.style.right = savedBodyStyles.right;
57
+ body.style.width = savedBodyStyles.width;
58
+ body.style.overflow = savedBodyStyles.overflow;
59
+ savedBodyStyles = null;
60
+
61
+ if (wasIOS) {
62
+ window.scrollTo(0, savedScrollY);
63
+ }
64
+ }
@@ -0,0 +1,40 @@
1
+ export type SheetState =
2
+ | "closed"
3
+ | "opening"
4
+ | "open"
5
+ | "pressing"
6
+ | "dragging"
7
+ | "snapping"
8
+ | "closing";
9
+
10
+ type Transition = { from: SheetState; to: SheetState };
11
+
12
+ const VALID: Transition[] = [
13
+ { from: "closed", to: "opening" },
14
+ { from: "opening", to: "open" },
15
+ { from: "opening", to: "closing" },
16
+ { from: "open", to: "pressing" },
17
+ { from: "open", to: "closing" },
18
+ { from: "pressing", to: "dragging" },
19
+ { from: "pressing", to: "open" },
20
+ { from: "pressing", to: "closing" },
21
+ { from: "dragging", to: "snapping" },
22
+ { from: "dragging", to: "closing" },
23
+ { from: "snapping", to: "open" },
24
+ { from: "snapping", to: "closing" },
25
+ { from: "closing", to: "closed" },
26
+ { from: "closing", to: "opening" },
27
+ ];
28
+
29
+ export function canTransition(from: SheetState, to: SheetState): boolean {
30
+ return VALID.some((t) => t.from === from && t.to === to);
31
+ }
32
+
33
+ export function assertTransition(from: SheetState, to: SheetState): void {
34
+ if (from === to) return;
35
+ if (!canTransition(from, to)) {
36
+ if (typeof process !== "undefined" && process.env?.NODE_ENV !== "production") {
37
+ throw new Error(`[Sheet] invalid transition: ${from} → ${to}`);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,42 @@
1
+ import { VELOCITY_WINDOW_MS } from "./constants.js";
2
+
3
+ interface Sample {
4
+ y: number;
5
+ t: number;
6
+ }
7
+
8
+ const MAX_SAMPLES = 16;
9
+
10
+ export class VelocityTracker {
11
+ private samples: Sample[] = [];
12
+
13
+ reset(): void {
14
+ this.samples.length = 0;
15
+ }
16
+
17
+ add(y: number, t: number): void {
18
+ this.samples.push({ y, t });
19
+ if (this.samples.length > MAX_SAMPLES) this.samples.shift();
20
+ }
21
+
22
+ /** Weighted velocity over the last VELOCITY_WINDOW_MS, in px/ms. */
23
+ compute(now: number): number {
24
+ const recent = this.samples.filter((s) => now - s.t <= VELOCITY_WINDOW_MS);
25
+ if (recent.length < 2) return 0;
26
+
27
+ let weightedDy = 0;
28
+ let weightedDt = 0;
29
+ for (let i = 1; i < recent.length; i++) {
30
+ const prev = recent[i - 1];
31
+ const cur = recent[i];
32
+ if (!prev || !cur) continue;
33
+ const dy = cur.y - prev.y;
34
+ const dt = cur.t - prev.t || 1;
35
+ const w = i / recent.length;
36
+ weightedDy += dy * w;
37
+ weightedDt += dt * w;
38
+ }
39
+ if (weightedDt === 0) return 0;
40
+ return weightedDy / weightedDt;
41
+ }
42
+ }
@@ -0,0 +1,105 @@
1
+ import {
2
+ type Component,
3
+ type ComponentProps,
4
+ type ParentComponent,
5
+ splitProps,
6
+ type ValidComponent,
7
+ } from "solid-js";
8
+ import { Dynamic } from "solid-js/web";
9
+ import { cn } from "../lib/utils.js";
10
+ import { Icon } from "./icon.js";
11
+
12
+ const Breadcrumb: Component<ComponentProps<"nav">> = (props) => {
13
+ return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />;
14
+ };
15
+
16
+ const BreadcrumbList: Component<ComponentProps<"ol">> = (props) => {
17
+ const [local, rest] = splitProps(props, ["class"]);
18
+ return (
19
+ <ol
20
+ data-slot="breadcrumb-list"
21
+ class={cn(
22
+ "flex flex-wrap items-center gap-1.5 break-words text-muted-foreground text-sm sm:gap-2.5",
23
+ local.class,
24
+ )}
25
+ {...rest}
26
+ />
27
+ );
28
+ };
29
+
30
+ const BreadcrumbItem: Component<ComponentProps<"li">> = (props) => {
31
+ const [local, rest] = splitProps(props, ["class"]);
32
+ return (
33
+ <li
34
+ data-slot="breadcrumb-item"
35
+ class={cn("inline-flex items-center gap-1.5", local.class)}
36
+ {...rest}
37
+ />
38
+ );
39
+ };
40
+
41
+ const BreadcrumbLink: Component<ComponentProps<"a"> & { as?: ValidComponent }> = (props) => {
42
+ const [local, rest] = splitProps(props, ["class", "as"]);
43
+ const Comp = () => local.as || "a";
44
+ return (
45
+ <Dynamic
46
+ component={Comp()}
47
+ data-slot="breadcrumb-link"
48
+ class={cn("transition-colors hover:text-foreground", local.class)}
49
+ {...rest}
50
+ />
51
+ );
52
+ };
53
+
54
+ const BreadcrumbPage: Component<ComponentProps<"span">> = (props) => {
55
+ const [local, rest] = splitProps(props, ["class"]);
56
+ return (
57
+ <span
58
+ data-slot="breadcrumb-page"
59
+ aria-current="page"
60
+ class={cn("font-normal text-foreground", local.class)}
61
+ {...rest}
62
+ />
63
+ );
64
+ };
65
+
66
+ const BreadcrumbSeparator: ParentComponent<ComponentProps<"li">> = (props) => {
67
+ const [local, rest] = splitProps(props, ["children", "class"]);
68
+ return (
69
+ <li
70
+ data-slot="breadcrumb-separator"
71
+ role="presentation"
72
+ aria-hidden="true"
73
+ class={cn("[&>svg]:size-3.5", local.class)}
74
+ {...rest}
75
+ >
76
+ {local.children ?? <Icon icon="lucide:chevron-right" width={14} height={14} />}
77
+ </li>
78
+ );
79
+ };
80
+
81
+ const BreadcrumbEllipsis: Component<ComponentProps<"span">> = (props) => {
82
+ const [local, rest] = splitProps(props, ["class"]);
83
+ return (
84
+ <span
85
+ data-slot="breadcrumb-ellipsis"
86
+ role="presentation"
87
+ aria-hidden="true"
88
+ class={cn("flex size-9 items-center justify-center", local.class)}
89
+ {...rest}
90
+ >
91
+ <Icon icon="lucide:ellipsis" width={16} height={16} class="size-4" />
92
+ <span class="sr-only">More</span>
93
+ </span>
94
+ );
95
+ };
96
+
97
+ export {
98
+ Breadcrumb,
99
+ BreadcrumbEllipsis,
100
+ BreadcrumbItem,
101
+ BreadcrumbLink,
102
+ BreadcrumbList,
103
+ BreadcrumbPage,
104
+ BreadcrumbSeparator,
105
+ };
@@ -0,0 +1,66 @@
1
+ import { cva, type VariantProps } from "cva";
2
+ import { type Component, type ComponentProps, splitProps, type ValidComponent } from "solid-js";
3
+ import { Dynamic } from "solid-js/web";
4
+ import { cn } from "../lib/utils.js";
5
+ import { Separator } from "./separator.js";
6
+
7
+ const buttonGroupVariants = cva({
8
+ base: "flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
9
+ variants: {
10
+ orientation: {
11
+ horizontal:
12
+ "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
13
+ vertical:
14
+ "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
15
+ },
16
+ },
17
+ defaultVariants: {
18
+ orientation: "horizontal",
19
+ },
20
+ });
21
+
22
+ const ButtonGroup: Component<ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>> = (
23
+ props,
24
+ ) => {
25
+ const [local, rest] = splitProps(props, ["class", "orientation"] as const);
26
+ return (
27
+ <div
28
+ data-slot="button-group"
29
+ data-orientation={local.orientation}
30
+ class={cn(buttonGroupVariants({ orientation: local.orientation }), local.class)}
31
+ {...rest}
32
+ />
33
+ );
34
+ };
35
+
36
+ const ButtonGroupText: Component<ComponentProps<"div"> & { as?: ValidComponent }> = (props) => {
37
+ const [local, rest] = splitProps(props, ["class", "as"] as const);
38
+ const Comp = () => local.as || "div";
39
+ return (
40
+ <Dynamic
41
+ component={Comp()}
42
+ class={cn(
43
+ "glass flex items-center gap-2 rounded-md px-4 font-medium text-muted-foreground text-sm [--glass-edge:var(--border)] [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",
44
+ local.class,
45
+ )}
46
+ {...rest}
47
+ />
48
+ );
49
+ };
50
+
51
+ const ButtonGroupSeparator: Component<ComponentProps<typeof Separator>> = (props) => {
52
+ const [local, rest] = splitProps(props, ["class", "orientation"] as const);
53
+ return (
54
+ <Separator
55
+ data-slot="button-group-separator"
56
+ orientation={local.orientation ?? "vertical"}
57
+ class={cn(
58
+ "!m-0 relative self-stretch bg-input data-[orientation=vertical]:h-auto",
59
+ local.class,
60
+ )}
61
+ {...rest}
62
+ />
63
+ );
64
+ };
65
+
66
+ export { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, buttonGroupVariants };
@@ -0,0 +1,20 @@
1
+ import { Button as KobalteButton } from "@kobalte/core/button";
2
+ import type { VariantProps } from "cva";
3
+ import { type ComponentProps, splitProps } from "solid-js";
4
+ import { buttonVariants } from "../lib/button-variants.js";
5
+ import { cn } from "../lib/utils.js";
6
+
7
+ type ButtonProps = ComponentProps<typeof KobalteButton> & VariantProps<typeof buttonVariants>;
8
+
9
+ function Button(props: ButtonProps) {
10
+ const [local, others] = splitProps(props, ["class", "variant", "size"] as const);
11
+ return (
12
+ <KobalteButton
13
+ data-slot="button"
14
+ class={cn(buttonVariants({ variant: local.variant, size: local.size }), local.class)}
15
+ {...others}
16
+ />
17
+ );
18
+ }
19
+
20
+ export { Button, buttonVariants };
@@ -0,0 +1,101 @@
1
+ import {
2
+ type Component,
3
+ type ComponentProps,
4
+ Show,
5
+ splitProps,
6
+ type ValidComponent,
7
+ } from "solid-js";
8
+ import { Dynamic } from "solid-js/web";
9
+ import {
10
+ CARD_ACTION_CLASS,
11
+ CARD_CONTENT_CLASS,
12
+ CARD_DESCRIPTION_CLASS,
13
+ CARD_FOOTER_CLASS,
14
+ CARD_HEADER_CLASS,
15
+ CARD_INTERACTIVE,
16
+ CARD_PADDING,
17
+ CARD_SURFACE,
18
+ CARD_SURFACE_OPAQUE,
19
+ CARD_TITLE_CLASS,
20
+ type CardPadding,
21
+ } from "../lib/card-classes.js";
22
+ import { cn } from "../lib/utils.js";
23
+ import { Ornament } from "./ornament.js";
24
+
25
+ // `as` picks the tag at the call site, so the attributes of the tags a card is
26
+ // rendered as (link, details, button) ride along with the div base.
27
+ type CardProps = ComponentProps<"div"> &
28
+ Partial<Pick<ComponentProps<"a">, "href" | "target" | "rel">> &
29
+ Partial<Pick<ComponentProps<"details">, "name" | "open">> & {
30
+ interactive?: boolean;
31
+ opaque?: boolean;
32
+ padding?: CardPadding;
33
+ as?: ValidComponent;
34
+ type?: "button" | "submit" | "reset";
35
+ /** The corner glyph of a go-somewhere ("arrow") or picked ("check") card. */
36
+ ornament?: "arrow" | "check";
37
+ };
38
+
39
+ const Card: Component<CardProps> = (props) => {
40
+ const [local, others] = splitProps(props, [
41
+ "class",
42
+ "interactive",
43
+ "opaque",
44
+ "padding",
45
+ "as",
46
+ "ornament",
47
+ "children",
48
+ ]);
49
+ return (
50
+ <Dynamic
51
+ component={local.as ?? "div"}
52
+ data-slot="card"
53
+ class={cn(
54
+ local.opaque ? CARD_SURFACE_OPAQUE : CARD_SURFACE,
55
+ "rounded-[var(--radius)]",
56
+ CARD_PADDING[local.padding ?? "none"],
57
+ local.interactive && CARD_INTERACTIVE,
58
+ local.ornament && "group relative overflow-hidden",
59
+ local.class,
60
+ )}
61
+ {...others}
62
+ >
63
+ <Show when={local.ornament}>{(kind) => <Ornament kind={kind()} />}</Show>
64
+ {local.children}
65
+ </Dynamic>
66
+ );
67
+ };
68
+
69
+ const CardHeader: Component<ComponentProps<"div">> = (props) => {
70
+ const [local, others] = splitProps(props, ["class"]);
71
+ return <div data-slot="card-header" class={cn(CARD_HEADER_CLASS, local.class)} {...others} />;
72
+ };
73
+
74
+ const CardTitle: Component<ComponentProps<"div">> = (props) => {
75
+ const [local, others] = splitProps(props, ["class"]);
76
+ return <div data-slot="card-title" class={cn(CARD_TITLE_CLASS, local.class)} {...others} />;
77
+ };
78
+
79
+ const CardDescription: Component<ComponentProps<"div">> = (props) => {
80
+ const [local, others] = splitProps(props, ["class"]);
81
+ return (
82
+ <div data-slot="card-description" class={cn(CARD_DESCRIPTION_CLASS, local.class)} {...others} />
83
+ );
84
+ };
85
+
86
+ const CardAction: Component<ComponentProps<"div">> = (props) => {
87
+ const [local, others] = splitProps(props, ["class"]);
88
+ return <div data-slot="card-action" class={cn(CARD_ACTION_CLASS, local.class)} {...others} />;
89
+ };
90
+
91
+ const CardContent: Component<ComponentProps<"div">> = (props) => {
92
+ const [local, others] = splitProps(props, ["class"]);
93
+ return <div data-slot="card-content" class={cn(CARD_CONTENT_CLASS, local.class)} {...others} />;
94
+ };
95
+
96
+ const CardFooter: Component<ComponentProps<"div">> = (props) => {
97
+ const [local, others] = splitProps(props, ["class"]);
98
+ return <div data-slot="card-footer" class={cn(CARD_FOOTER_CLASS, local.class)} {...others} />;
99
+ };
100
+
101
+ export { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };