@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,294 @@
1
+ import {
2
+ type ComponentProps,
3
+ createEffect,
4
+ createSignal,
5
+ type JSX,
6
+ on,
7
+ onCleanup,
8
+ onMount,
9
+ Show,
10
+ splitProps,
11
+ } from "solid-js";
12
+ import { cn } from "../lib/utils.js";
13
+
14
+ function readTranslate(el: HTMLElement): [number, number] {
15
+ const t = getComputedStyle(el).translate;
16
+ if (!t || t === "none") return [0, 0];
17
+ const [x = "0", y = "0"] = t.split(" ");
18
+ return [Number.parseFloat(x) || 0, Number.parseFloat(y) || 0];
19
+ }
20
+
21
+ /**
22
+ * The sliding "moving background": a tinted indicator that measures the active item
23
+ * among its children and animates its position/size behind it. Reusable across
24
+ * any component with a selected item among siblings (Dock, Tabs, ToggleGroup,
25
+ * segmented controls…). Presentational + controlled — pass the active index.
26
+ *
27
+ * Wrap the items directly; by default it measures each direct child (excluding
28
+ * its own indicator). Give it `indicatorClass` for the look and `orientation` for the axis.
29
+ */
30
+ interface SlidingIndicatorProps extends ComponentProps<"div"> {
31
+ /** Index-based active item among the measured children, or null to hide.
32
+ * Use this when you own the selection (e.g. Dock). */
33
+ active?: number | null;
34
+ /** Attribute-based active item: a selector for the currently-active child
35
+ * (e.g. "[data-selected]"). Use this with libraries that mark the active item
36
+ * in the DOM (Kobalte Tabs/ToggleGroup); a MutationObserver re-slides on change. */
37
+ activeSelector?: string;
38
+ orientation?: "horizontal" | "vertical";
39
+ /** Extra classes for the sliding indicator — radius and any per-surface `--glass-*`
40
+ * knob overrides. The trusted `.glass` material is ALWAYS applied underneath, so
41
+ * this can't flatten the indicator; it only tunes it. Default radius: `rounded-lg`. */
42
+ indicatorClass?: string;
43
+ /** Glass tone that drives the `.glass` material (`--glass-tone`). Defaults to
44
+ * `var(--primary)` — the one trusted look. Pass another CSS color to re-tint. */
45
+ indicatorTone?: string;
46
+ /** Selector for the measurable items. Default: direct children (minus the indicator). */
47
+ itemSelector?: string;
48
+ children: JSX.Element;
49
+ }
50
+
51
+ type Pos = { offset: number; size: number; cross: number };
52
+
53
+ // One duration for both the slide (transform transition) and the scale dip, so
54
+ // they always overlap exactly. Shorter = snappier.
55
+ const SLIDE_MS = 220;
56
+
57
+ // Squash-and-stretch: at mid-flight the indicator stretches ALONG the travel axis
58
+ // and pinches perpendicular, which reads as momentum/speed. Both deforms are a
59
+ // fixed PIXEL budget on their own axis (not a percentage), so a 34px dropdown row
60
+ // and a 300px-wide one deform by the same visible pixels — a big element no longer
61
+ // animates more just because it's big. Each axis measures its own size (`size` =
62
+ // travel, `cross` = perpendicular) to turn the pixel budget into a scale factor.
63
+ // DEFORM_MAX caps the fraction so a very thin item can't collapse.
64
+ const STRETCH_PX = 6; // grow along travel
65
+ const SQUASH_PX = 6; // pinch perpendicular
66
+ const DEFORM_MAX = 0.14;
67
+
68
+ export function SlidingIndicator(props: SlidingIndicatorProps) {
69
+ const [local, rest] = splitProps(props, [
70
+ "active",
71
+ "activeSelector",
72
+ "orientation",
73
+ "indicatorClass",
74
+ "indicatorTone",
75
+ "itemSelector",
76
+ "class",
77
+ "children",
78
+ "ref",
79
+ ]);
80
+ const horizontal = () => (local.orientation ?? "horizontal") === "horizontal";
81
+ let containerRef: HTMLDivElement | undefined;
82
+ // A caller's ref goes through here, not through the spread: `spread()` would
83
+ // hand its own ref to the element and leave containerRef unset, so nothing
84
+ // would ever measure.
85
+ const setContainerRef = (el: HTMLDivElement) => {
86
+ containerRef = el;
87
+ const forwarded = local.ref;
88
+ if (typeof forwarded === "function") forwarded(el);
89
+ };
90
+ const [pos, setPos] = createSignal<Pos | null>(null);
91
+
92
+ // On a real move, play a symmetric squash-and-stretch (1 → peak → 1) over the
93
+ // SAME duration as the slide, so the deform and the travel fully overlap: fastest
94
+ // and most stretched at mid-flight, back to a square at both ends (accelerate in,
95
+ // settle out). At the peak the indicator STRETCHES along the travel axis and
96
+ // PINCHES perpendicular (the reciprocal, so volume is preserved) — the classic
97
+ // speed cue. WAAPI on `scale` composes with the translate transition; it releases
98
+ // back to the base (1) on its own, so nothing can get stuck deformed.
99
+ let indicatorEl: HTMLDivElement | undefined;
100
+ createEffect(
101
+ on(
102
+ pos,
103
+ (p, prev) => {
104
+ // pos is a fresh object on every re-measure (the Select's MutationObserver
105
+ // fires often), so only animate on an actual travel.
106
+ if (!p || !prev || Math.abs(p.offset - prev.offset) < 1 || !indicatorEl) return;
107
+ const stretch = 1 + Math.min(DEFORM_MAX, STRETCH_PX / (p.size || 1));
108
+ const squash = 1 - Math.min(DEFORM_MAX, SQUASH_PX / (p.cross || 1));
109
+ const peak = horizontal() ? `${stretch} ${squash}` : `${squash} ${stretch}`;
110
+ indicatorEl.animate([{ scale: "1 1" }, { scale: peak }, { scale: "1 1" }], {
111
+ duration: SLIDE_MS,
112
+ easing: "ease-in-out",
113
+ });
114
+ },
115
+ { defer: true },
116
+ ),
117
+ );
118
+
119
+ // A zero-size pass is not a resting state, and nothing is guaranteed to fire
120
+ // when it ends: an ancestor dialog's own open animation neither resizes this
121
+ // container nor bubbles its animationend down here.
122
+ const RETRY_FRAMES = 90;
123
+ let retries = 0;
124
+ let retryFrame: number | undefined;
125
+ const remeasureNextFrame = () => {
126
+ if (disposed || retryFrame !== undefined || retries >= RETRY_FRAMES) return;
127
+ retries += 1;
128
+ retryFrame = requestAnimationFrame(() => {
129
+ retryFrame = undefined;
130
+ if (!disposed) measure();
131
+ });
132
+ };
133
+
134
+ const measure = () => {
135
+ if (!containerRef) return;
136
+ syncObservedItems();
137
+ let el: HTMLElement | null | undefined;
138
+ if (local.activeSelector) {
139
+ el = containerRef.querySelector<HTMLElement>(local.activeSelector);
140
+ } else if (local.active != null && local.active >= 0) {
141
+ const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
142
+ el = containerRef.querySelectorAll<HTMLElement>(sel)[local.active];
143
+ }
144
+ if (!el) {
145
+ setPos(null);
146
+ return;
147
+ }
148
+ // Not laid out yet: a hidden/collapsing popover, a display:none tab panel, a
149
+ // portal measured before Kobalte positions it, or a dialog still running its
150
+ // open transform. Measuring then would fling the indicator to a bogus offset
151
+ // (a stray tinted blob a screenshot catches mid-open) or scale it by the
152
+ // ancestor's in-flight transform, so hide until there is real geometry.
153
+ // Rects, not clientWidth: a transformed ancestor leaves layout size intact.
154
+ const er = el.getBoundingClientRect();
155
+ const cr = containerRef.getBoundingClientRect();
156
+ if (er.width === 0 || er.height === 0 || cr.width === 0 || cr.height === 0) {
157
+ setPos(null);
158
+ remeasureNextFrame();
159
+ return;
160
+ }
161
+ retries = 0;
162
+ // Measure relative to the container via bounding rects (not offsetLeft),
163
+ // so the active item can be a deep descendant (Kobalte menu/listbox items),
164
+ // not just a direct child. Add the container's own scroll so the indicator,
165
+ // which scrolls with the content, lands at the content offset; subtract the
166
+ // border so it aligns to the padding box (where the absolute indicator anchors).
167
+ // A row arriving through gh-stagger is still translated: bounding rects
168
+ // include that travel, its resting place does not.
169
+ const [tx, ty] = readTranslate(el);
170
+ setPos(
171
+ horizontal()
172
+ ? {
173
+ offset: er.left - tx - cr.left - containerRef.clientLeft + containerRef.scrollLeft,
174
+ size: er.width,
175
+ cross: er.height,
176
+ }
177
+ : {
178
+ offset: er.top - ty - cr.top - containerRef.clientTop + containerRef.scrollTop,
179
+ size: er.height,
180
+ cross: er.width,
181
+ },
182
+ );
183
+ };
184
+
185
+ // Re-measure whenever the (index) active changes; queueMicrotask lets DOM settle.
186
+ createEffect(() => {
187
+ void local.active;
188
+ queueMicrotask(measure);
189
+ });
190
+
191
+ // The items actually under the ResizeObserver, so entries can be diffed
192
+ // against the freshly-resolved set on every measure() pass.
193
+ let ro: ResizeObserver | undefined;
194
+ const observedItems = new Set<Element>();
195
+ let disposed = false;
196
+
197
+ // Observing only the container missed the case that broke the admin tabs
198
+ // pill: an <iconify-icon> or a webfont finishes loading AFTER first paint and
199
+ // grows the trigger, but a w-full container never itself resizes, so the
200
+ // indicator kept the stale width. Observing the resolved item(s) directly
201
+ // catches that growth.
202
+ function syncObservedItems() {
203
+ if (!containerRef || !ro) return;
204
+ const next = new Set<Element>();
205
+ if (local.activeSelector) {
206
+ const el = containerRef.querySelector(local.activeSelector);
207
+ if (el) next.add(el);
208
+ } else if (local.active != null && local.active >= 0) {
209
+ const sel = local.itemSelector ?? ":scope > :not([data-sliding-indicator])";
210
+ for (const el of containerRef.querySelectorAll(sel)) next.add(el);
211
+ }
212
+ for (const el of observedItems) {
213
+ if (!next.has(el)) {
214
+ ro.unobserve(el);
215
+ observedItems.delete(el);
216
+ }
217
+ }
218
+ for (const el of next) {
219
+ if (!observedItems.has(el)) {
220
+ ro.observe(el);
221
+ observedItems.add(el);
222
+ }
223
+ }
224
+ }
225
+
226
+ onMount(() => {
227
+ if (!containerRef) return;
228
+ ro = new ResizeObserver(() => measure());
229
+ containerRef?.addEventListener("animationend", measure);
230
+ ro.observe(containerRef);
231
+ // Attribute-based selection (e.g. Kobalte's [data-selected]/[data-highlighted]):
232
+ // re-slide when the active child's marker attribute moves, or when items are
233
+ // added/removed, so newly-mounted items land under the same observer.
234
+ const mo = new MutationObserver(() => {
235
+ syncObservedItems();
236
+ queueMicrotask(measure);
237
+ });
238
+ mo.observe(containerRef, {
239
+ childList: true,
240
+ subtree: !!local.activeSelector,
241
+ attributes: !!local.activeSelector,
242
+ });
243
+ // Focus-based selection (e.g. Kobalte menus mark the highlighted item with
244
+ // roving focus, which is not an attribute mutation).
245
+ const onFocusIn = () => queueMicrotask(measure);
246
+ if (local.activeSelector) containerRef.addEventListener("focusin", onFocusIn);
247
+ syncObservedItems();
248
+ queueMicrotask(measure);
249
+ // Web fonts can finish loading after the first measure and grow glyphs
250
+ // (the same class of bug the item-level ResizeObserver above fixes for
251
+ // icons); one extra pass once fonts settle catches that too.
252
+ if (typeof document !== "undefined" && document.fonts) {
253
+ document.fonts.ready.then(() => {
254
+ if (!disposed) measure();
255
+ });
256
+ }
257
+ onCleanup(() => {
258
+ disposed = true;
259
+ if (retryFrame !== undefined) cancelAnimationFrame(retryFrame);
260
+ ro?.disconnect();
261
+ mo.disconnect();
262
+ containerRef?.removeEventListener("focusin", onFocusIn);
263
+ containerRef?.removeEventListener("animationend", measure);
264
+ });
265
+ });
266
+
267
+ return (
268
+ <div ref={setContainerRef} class={cn("relative isolate", local.class)} {...rest}>
269
+ <Show when={pos()}>
270
+ {(p) => (
271
+ <div
272
+ ref={indicatorEl}
273
+ data-sliding-indicator
274
+ aria-hidden="true"
275
+ class={cn(
276
+ "pointer-events-none absolute -z-10",
277
+ horizontal() ? "inset-y-0 left-0" : "inset-x-0 top-0",
278
+ "glass glass-tint",
279
+ local.indicatorClass ?? "rounded-lg",
280
+ )}
281
+ style={{
282
+ transition: `transform ${SLIDE_MS}ms ease-in-out, width ${SLIDE_MS}ms ease-in-out, height ${SLIDE_MS}ms ease-in-out`,
283
+ "--glass-tone": local.indicatorTone ?? "var(--primary)",
284
+ ...(horizontal()
285
+ ? { transform: `translateX(${p().offset}px)`, width: `${p().size}px` }
286
+ : { transform: `translateY(${p().offset}px)`, height: `${p().size}px` }),
287
+ }}
288
+ />
289
+ )}
290
+ </Show>
291
+ {local.children}
292
+ </div>
293
+ );
294
+ }
@@ -0,0 +1,217 @@
1
+ import { type Component, type ComponentProps, type JSX, mergeProps, Show } from "solid-js";
2
+ import { type ExternalToast, Toaster as SolidSonner, toast as sonnerToast } from "solid-sonner";
3
+ import {
4
+ ALERT_CLASS,
5
+ ALERT_CONTENT_CLASS,
6
+ ALERT_DESCRIPTION_CLASS,
7
+ ALERT_ICON_BG_CLASS,
8
+ ALERT_ICON_CLASS,
9
+ ALERT_TITLE_CLASS,
10
+ alertIconBgStyle,
11
+ } from "../lib/alert-tones.js";
12
+ import { glassToneText } from "../lib/glass-tone.js";
13
+ import { createIsMobile } from "../lib/use-is-mobile.js";
14
+ import { cn } from "../lib/utils.js";
15
+ import { Icon } from "./icon.js";
16
+ import { Spinner } from "./spinner.js";
17
+
18
+ type Position = ComponentProps<typeof SolidSonner>["position"];
19
+ type ToastMessage = JSX.Element | string;
20
+
21
+ type ToastKind = "success" | "error" | "warning" | "info" | "loading" | "message";
22
+
23
+ const KIND_TONE: Record<ToastKind, string | null> = {
24
+ success: "var(--success)",
25
+ error: "var(--destructive)",
26
+ warning: "var(--warning)",
27
+ info: "var(--primary)",
28
+ loading: null,
29
+ message: null,
30
+ };
31
+
32
+ const KIND_ICON: Record<ToastKind, string | null> = {
33
+ success: "lucide:circle-check",
34
+ error: "lucide:octagon-alert",
35
+ warning: "lucide:triangle-alert",
36
+ info: "lucide:info",
37
+ loading: null,
38
+ message: null,
39
+ };
40
+
41
+ /* No backdrop-blur on toasts: sonner animates transform, and backdrop-filter on
42
+ * a transform-animated element renders solid black mid-animation in Chromium.
43
+ * The opaque --card base gives the glass look with nothing to blur. Toned and
44
+ * neutral toasts are the same .glass material with a stronger lift. */
45
+ const TONE_TOAST_CLASS = "glass glass-tint [--glass-lift:0.5]";
46
+ const NEUTRAL_TOAST_CLASS =
47
+ "glass [--glass-tone:var(--foreground)] [--glass-wash:6%] [--glass-glow:0%] [--glass-drop:0%] [--glass-edge:color-mix(in_srgb,var(--foreground)_16%,transparent)] [--glass-lift:0.5]";
48
+
49
+ type GlassToastProps = {
50
+ kind: ToastKind;
51
+ title: ToastMessage;
52
+ description?: ToastMessage;
53
+ icon?: JSX.Element;
54
+ action?: JSX.Element;
55
+ };
56
+
57
+ const GlassToast: Component<GlassToastProps> = (props) => {
58
+ const tone = KIND_TONE[props.kind];
59
+ const toneIcon = KIND_ICON[props.kind];
60
+ const watermarkGlyph: JSX.Element | null =
61
+ props.icon ?? (toneIcon ? <Icon icon={toneIcon} width={112} height={112} /> : null);
62
+
63
+ return (
64
+ <div
65
+ data-slot="toast"
66
+ role={props.kind === "error" ? "alert" : "status"}
67
+ class={cn(
68
+ ALERT_CLASS,
69
+ tone ? TONE_TOAST_CLASS : NEUTRAL_TOAST_CLASS,
70
+ "w-[356px] max-w-[calc(100vw-2rem)]",
71
+ )}
72
+ style={tone ? { "--glass-tone": tone, color: "var(--foreground)" } : undefined}
73
+ >
74
+ <Show when={tone && watermarkGlyph}>
75
+ <span
76
+ class={ALERT_ICON_BG_CLASS}
77
+ style={alertIconBgStyle(tone as string)}
78
+ aria-hidden="true"
79
+ >
80
+ {watermarkGlyph}
81
+ </span>
82
+ </Show>
83
+ <Show when={props.kind === "loading"}>
84
+ <span
85
+ class={ALERT_ICON_CLASS}
86
+ style={{
87
+ "background-color": "color-mix(in srgb, var(--foreground) 8%, transparent)",
88
+ color: "var(--foreground)",
89
+ }}
90
+ >
91
+ <Spinner class="size-[18px]" />
92
+ </span>
93
+ </Show>
94
+ <div class={ALERT_CONTENT_CLASS}>
95
+ <Show when={props.title}>
96
+ <p class={ALERT_TITLE_CLASS} style={tone ? { color: glassToneText(tone) } : undefined}>
97
+ {props.title}
98
+ </p>
99
+ </Show>
100
+ <Show when={props.description}>
101
+ <div class={ALERT_DESCRIPTION_CLASS}>{props.description}</div>
102
+ </Show>
103
+ </div>
104
+ <Show when={props.action}>
105
+ <div class="flex shrink-0 items-center">{props.action}</div>
106
+ </Show>
107
+ </div>
108
+ );
109
+ };
110
+
111
+ const show =
112
+ (kind: ToastKind) =>
113
+ (message: ToastMessage, data: ExternalToast = {}): string | number => {
114
+ /* Pull rendered fields out of the sonner options, else sonner renders
115
+ * `description` a second time as loose text under the toast. */
116
+ const { description, icon, action, ...rest } = data;
117
+ return sonnerToast.custom(
118
+ () => (
119
+ <GlassToast
120
+ kind={kind}
121
+ title={message}
122
+ description={description as ToastMessage | undefined}
123
+ icon={icon ?? undefined}
124
+ action={action as JSX.Element | undefined}
125
+ />
126
+ ),
127
+ { unstyled: true, ...rest },
128
+ );
129
+ };
130
+
131
+ type PromiseData<T> = Omit<ExternalToast, "description"> & {
132
+ loading?: ToastMessage;
133
+ success?: ToastMessage | ((data: T) => ToastMessage);
134
+ error?: ToastMessage | ((err: unknown) => ToastMessage);
135
+ finally?: () => void | Promise<void>;
136
+ };
137
+
138
+ const resolveMsg = <T,>(
139
+ m: ToastMessage | ((v: T) => ToastMessage) | undefined,
140
+ v: T,
141
+ ): ToastMessage => (typeof m === "function" ? (m as (v: T) => ToastMessage)(v) : (m ?? ""));
142
+
143
+ function glassPromise<T>(
144
+ promise: Promise<T> | (() => Promise<T>),
145
+ data: PromiseData<T> = {},
146
+ ): { unwrap: () => Promise<T> } {
147
+ const id = sonnerToast.custom(
148
+ () => <GlassToast kind="loading" title={data.loading ?? "Loading"} />,
149
+ {
150
+ unstyled: true,
151
+ duration: Number.POSITIVE_INFINITY,
152
+ },
153
+ );
154
+ const p = typeof promise === "function" ? promise() : promise;
155
+ p.then((v) => {
156
+ sonnerToast.custom(() => <GlassToast kind="success" title={resolveMsg(data.success, v)} />, {
157
+ id,
158
+ unstyled: true,
159
+ });
160
+ })
161
+ .catch((e: unknown) => {
162
+ sonnerToast.custom(() => <GlassToast kind="error" title={resolveMsg(data.error, e)} />, {
163
+ id,
164
+ unstyled: true,
165
+ });
166
+ })
167
+ .finally(() => data.finally?.());
168
+ return { unwrap: () => p };
169
+ }
170
+
171
+ const toast = Object.assign(
172
+ (message: ToastMessage, data?: ExternalToast) => show("message")(message, data),
173
+ {
174
+ success: show("success"),
175
+ error: show("error"),
176
+ warning: show("warning"),
177
+ info: show("info"),
178
+ message: show("message"),
179
+ loading: (message: ToastMessage, data: ExternalToast = {}) => {
180
+ const { description, icon, action, ...rest } = data;
181
+ return sonnerToast.custom(
182
+ () => (
183
+ <GlassToast
184
+ kind="loading"
185
+ title={message}
186
+ description={description as ToastMessage | undefined}
187
+ icon={icon ?? undefined}
188
+ action={action as JSX.Element | undefined}
189
+ />
190
+ ),
191
+ { unstyled: true, duration: Number.POSITIVE_INFINITY, ...rest },
192
+ );
193
+ },
194
+ custom: sonnerToast.custom,
195
+ dismiss: sonnerToast.dismiss,
196
+ promise: glassPromise,
197
+ getHistory: sonnerToast.getHistory,
198
+ getToasts: sonnerToast.getToasts,
199
+ },
200
+ );
201
+
202
+ const Toaster: Component<ComponentProps<typeof SolidSonner>> = (rawProps) => {
203
+ const isMobile = createIsMobile();
204
+ const props = mergeProps({ duration: 3000, gap: 8, visibleToasts: 3 }, rawProps);
205
+ const position = (): Position => props.position ?? (isMobile() ? "top-center" : "bottom-right");
206
+
207
+ return (
208
+ <SolidSonner
209
+ {...props}
210
+ position={position()}
211
+ class="toaster group"
212
+ toastOptions={{ unstyled: true, ...props.toastOptions }}
213
+ />
214
+ );
215
+ };
216
+
217
+ export { GlassToast, Toaster, toast };
@@ -0,0 +1,20 @@
1
+ import { type Component, type ComponentProps, splitProps } from "solid-js";
2
+ import { cn } from "../lib/utils.js";
3
+ import { Icon } from "./icon.js";
4
+
5
+ const Spinner: Component<Omit<ComponentProps<typeof Icon>, "icon">> = (props) => {
6
+ const [local, rest] = splitProps(props, ["class"]);
7
+ return (
8
+ <Icon
9
+ icon="lucide:loader-circle"
10
+ // Sizes the inner svg via the host's CSS box, so `class="size-*"` keeps working.
11
+ height="none"
12
+ role="status"
13
+ aria-label="Loading"
14
+ class={cn("size-4 animate-spin", local.class)}
15
+ {...rest}
16
+ />
17
+ );
18
+ };
19
+
20
+ export { Spinner };
@@ -0,0 +1,30 @@
1
+ import { For } from "solid-js";
2
+ import { POSITION_BAR, POSITION_BAR_LIT } from "../lib/position-bar-classes.js";
3
+ import { cn } from "../lib/utils.js";
4
+
5
+ /**
6
+ * Position inside a multi-step flow: lit bars for the eye, one spoken line for
7
+ * screen readers. The bars carry no text of their own, so the sr-only line is
8
+ * the only place the position is readable.
9
+ */
10
+ export function StepIndicator(props: { count: number; index: number; class?: string }) {
11
+ const steps = () => Array.from({ length: Math.max(props.count, 0) }, (_, step) => step);
12
+
13
+ return (
14
+ <div
15
+ data-slot="step-indicator"
16
+ class={cn("flex items-center justify-center gap-1", props.class)}
17
+ >
18
+ <span class="sr-only">{`Step ${props.index + 1} of ${props.count}`}</span>
19
+ <For each={steps()}>
20
+ {(step) => (
21
+ <span
22
+ data-slot="step-indicator-segment"
23
+ aria-current={step === props.index ? "step" : undefined}
24
+ class={cn(POSITION_BAR, "w-6", step <= props.index && POSITION_BAR_LIT)}
25
+ />
26
+ )}
27
+ </For>
28
+ </div>
29
+ );
30
+ }
@@ -0,0 +1,62 @@
1
+ import { type Component, type ComponentProps, createSignal, splitProps } from "solid-js";
2
+ import { FIELD_CHROME, FOCUS_RING } from "../lib/input-classes.js";
3
+ import { THUMB_CLASS } from "../lib/thumb-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+
6
+ type SwitchProps = Omit<ComponentProps<"button">, "onChange" | "children"> & {
7
+ checked?: boolean;
8
+ defaultChecked?: boolean;
9
+ onChange?: (checked: boolean) => void;
10
+ };
11
+
12
+ const Switch: Component<SwitchProps> = (props) => {
13
+ const [local, rest] = splitProps(props, [
14
+ "class",
15
+ "checked",
16
+ "defaultChecked",
17
+ "onChange",
18
+ "disabled",
19
+ "name",
20
+ ]);
21
+ const [uncontrolled, setUncontrolled] = createSignal(props.defaultChecked ?? false);
22
+ const checked = () => local.checked ?? uncontrolled();
23
+
24
+ return (
25
+ <button
26
+ {...rest}
27
+ type="button"
28
+ role="switch"
29
+ aria-checked={checked()}
30
+ data-slot="switch"
31
+ data-checked={checked() ? "" : undefined}
32
+ disabled={local.disabled}
33
+ class={cn(
34
+ // Unchecked wears the recessed input surface, the same dug-out glass as
35
+ // the slider rail; checked matches the slider fill. A `border-input`
36
+ // utility here would beat `:where(.glass)` and flatten the rim.
37
+ `group/switch peer relative inline-flex h-7 w-14 shrink-0 cursor-pointer items-center rounded-xl transition-glass duration-200 ease-out disabled:cursor-not-allowed disabled:opacity-50 ${FOCUS_RING}`,
38
+ checked() ? "glass glass-tint [--glass-tone:var(--primary)]" : FIELD_CHROME,
39
+ local.class,
40
+ )}
41
+ onClick={() => {
42
+ const next = !checked();
43
+ setUncontrolled(next);
44
+ local.onChange?.(next);
45
+ }}
46
+ >
47
+ <span
48
+ data-slot="switch-thumb"
49
+ class={cn(
50
+ THUMB_CLASS,
51
+ "pointer-events-none transition-transform duration-300 [transition-timing-function:cubic-bezier(0.34,1.56,0.64,1)] group-data-[checked]/switch:translate-x-full",
52
+ )}
53
+ // Off must read quieter than on: the knob dims with the track rather
54
+ // than staying one bright material in both states.
55
+ style={{ background: checked() ? "var(--thumb-face-on)" : "var(--thumb-face-off)" }}
56
+ />
57
+ {local.name && <input type="hidden" name={local.name} value={checked() ? "on" : "off"} />}
58
+ </button>
59
+ );
60
+ };
61
+
62
+ export { Switch };