@glasshome/ui 1.19.0 → 1.21.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 (45) hide show
  1. package/SPEC.md +2 -1
  2. package/dist/index.js +2 -2
  3. package/dist/lib/anchor-placement.d.ts +5 -0
  4. package/dist/lib/button-variants.d.ts +1 -1
  5. package/dist/lib/motion-classes.d.ts +1 -0
  6. package/dist/solid/color-disc.d.ts +33 -0
  7. package/dist/solid/dashboard-preview.d.ts +24 -0
  8. package/dist/solid/dialog-parts.d.ts +1 -0
  9. package/dist/solid/dialog.d.ts +3 -0
  10. package/dist/solid/image-picker.d.ts +3 -0
  11. package/dist/solid/index.d.ts +3 -1
  12. package/dist/solid/index.js +5931 -5537
  13. package/dist/solid/media-store.d.ts +10 -0
  14. package/dist/solid/option-card.d.ts +1 -0
  15. package/dist/solid/page-header.d.ts +2 -2
  16. package/dist/solid/preview-tile.d.ts +2 -0
  17. package/dist/solid/responsive-dialog.d.ts +2 -0
  18. package/dist/solid/schema-form.d.ts +6 -1
  19. package/dist/solid/sliding-indicator.d.ts +2 -0
  20. package/dist/solid/toggle-group.d.ts +4 -1
  21. package/dist/tokens/index.js +2 -1
  22. package/dist/{utils-CV6G6fr8.js → utils-CMk7R3zM.js} +413 -413
  23. package/package.json +1 -1
  24. package/scripts/check-ui-drift.mjs +5 -0
  25. package/src/lib/anchor-placement.ts +30 -0
  26. package/src/lib/button-variants.ts +12 -12
  27. package/src/lib/motion-classes.ts +5 -0
  28. package/src/solid/bottom-sheet/bottom-sheet.tsx +8 -1
  29. package/src/solid/color-disc.tsx +253 -0
  30. package/src/solid/dashboard-preview.tsx +128 -0
  31. package/src/solid/dialog-parts.tsx +5 -1
  32. package/src/solid/dialog.tsx +47 -5
  33. package/src/solid/entity-selector.tsx +2 -2
  34. package/src/solid/image-picker.tsx +232 -147
  35. package/src/solid/index.ts +9 -0
  36. package/src/solid/media-store.ts +20 -1
  37. package/src/solid/option-card.tsx +2 -0
  38. package/src/solid/page-header.tsx +9 -16
  39. package/src/solid/preview-tile.tsx +10 -0
  40. package/src/solid/responsive-dialog.tsx +10 -2
  41. package/src/solid/schema-form.tsx +30 -4
  42. package/src/solid/sliding-indicator.tsx +21 -5
  43. package/src/solid/toggle-group.tsx +18 -5
  44. package/src/styles/theme.css +12 -3
  45. package/src/tokens/presets.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.19.0",
3
+ "version": "1.21.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/glasshome/ui#readme",
@@ -23,6 +23,11 @@ const RULES = [
23
23
  /rounded-full[^"'`]*\bborder\b[^"'`]*bg-(?:card|background)\b/,
24
24
  'use <Badge tone> or <Button size="none">',
25
25
  ],
26
+ [
27
+ "hand-rolled icon well",
28
+ /(?=[^"'`]*\brounded-full\b)(?=[^"'`]*\bbg-foreground\/\d+)[^"'`]*\bsize-\d+\b/,
29
+ 'a round well is <SectionIcon icon> (or children), a pressable one <Button size="icon">, a person <Avatar>',
30
+ ],
26
31
  [
27
32
  "raw palette color",
28
33
  /\b(?:bg|text|border)-(?:amber|green|yellow|red|blue|orange|emerald|rose|sky)-\d{3}\b/,
@@ -0,0 +1,30 @@
1
+ import type { JSX } from "solid-js";
2
+
3
+ const EDGE = 16;
4
+
5
+ /** A panel that grows out of the element that opened it: its corner on the element's corner, at
6
+ * least as wide as the element, shifted only as far as the screen needs. The --morph-* values
7
+ * start the panel clipped to the element's box (MORPH_MOTION's keyframes), so it unrolls out of it. */
8
+ export function overAnchor(anchor: HTMLElement, width: number): JSX.CSSProperties {
9
+ const box = anchor.getBoundingClientRect();
10
+ const vw = window.innerWidth;
11
+ const vh = window.innerHeight;
12
+ const w = Math.min(Math.max(width, box.width), vw - 2 * EDGE);
13
+ const x = Math.max(EDGE, Math.min(box.left, vw - EDGE - w));
14
+ const y = Math.max(EDGE, Math.min(box.top, vh - EDGE - Math.max(box.height, 240)));
15
+ const radius = getComputedStyle(anchor).borderTopLeftRadius || "0px";
16
+ return {
17
+ left: `${x}px`,
18
+ top: `${y}px`,
19
+ translate: "none",
20
+ width: `${w}px`,
21
+ "max-width": "none",
22
+ "min-height": `${Math.min(box.height, vh - y - EDGE)}px`,
23
+ "max-height": `${vh - y - EDGE}px`,
24
+ "--morph-x": `${box.left - x}px`,
25
+ "--morph-y": `${box.top - y}px`,
26
+ "--morph-w": `${box.width}px`,
27
+ "--morph-h": `${box.height}px`,
28
+ "--morph-radius": radius,
29
+ } as JSX.CSSProperties;
30
+ }
@@ -1,13 +1,16 @@
1
1
  import { cva } from "cva";
2
2
 
3
+ /* Clear control glass: a see-through card fill over a blur, both scaled from the
4
+ * theme's material tier. `glass-control` lets reduce-blur restore the opaque fill. */
5
+ const CONTROL_GLASS =
6
+ "glass-control [--glass-base:color-mix(in_srgb,var(--card)_calc(var(--material-clarity)*0.6),transparent)] [--glass-light:0.1] backdrop-blur-[calc(var(--material-blur,24px)*0.6)] backdrop-saturate-[1.6] backdrop-brightness-[1.1]";
7
+
3
8
  /* One outline material, worn by the pill and by Toggle: `glass` owns the
4
9
  * element's background and border, so a real border-input box is a no-op. */
5
- export const OUTLINE_SURFACE =
6
- "glass [--glass-edge:var(--border)] hover:[--glass-base:var(--muted)] dark:[--glass-base:var(--input)] dark:hover:[--glass-base:var(--muted)]";
10
+ export const OUTLINE_SURFACE = `glass ${CONTROL_GLASS} [--glass-edge:var(--border)] dark:[--glass-edge:oklch(1_0_0/0.16)] hover:[--glass-light:0.18]`;
7
11
 
8
- /* Buttons are glass pills on an OPAQUE --card base: a translucent fill goes
9
- * muddy over dark heroes/sections. Every class is literal for Tailwind's
10
- * scanner. `size: none` is sizeless for callers that own height/padding. */
12
+ /* Every class is literal for Tailwind's scanner. `size: none` is sizeless for
13
+ * callers that own height/padding. */
11
14
  /* Controls take the theme's corner (rounded-lg is --radius): a capsule at the
12
15
  * roundness every preset but the sharp one ships, square at zero. */
13
16
  export const buttonVariants = cva({
@@ -17,15 +20,12 @@ export const buttonVariants = cva({
17
20
  base: "inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-lg font-medium text-sm outline-none transition-glass focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 active:scale-[0.97] disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
18
21
  variants: {
19
22
  variant: {
20
- default:
21
- "glass glass-tint [--glass-text:0%] [--glass-tone:var(--primary)] [--glass-wash:55%] hover:[--glass-edge:color-mix(in_srgb,var(--primary)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--primary)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]",
22
- destructive:
23
- "glass glass-tint [--glass-text:0%] [--glass-tone:var(--destructive)] [--glass-wash:55%] focus-visible:ring-destructive/30 hover:[--glass-edge:color-mix(in_srgb,var(--destructive)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--destructive)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]",
24
- secondary:
25
- "glass glass-tint [--glass-text:0%] [--glass-tone:var(--accent)] [--glass-wash:55%] hover:[--glass-edge:color-mix(in_srgb,var(--accent)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--accent)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]",
23
+ default: `glass glass-tint ${CONTROL_GLASS} [--glass-text:0%] [--glass-tone:var(--primary)] [--glass-wash:55%] hover:[--glass-edge:color-mix(in_srgb,var(--primary)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--primary)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]`,
24
+ destructive: `glass glass-tint ${CONTROL_GLASS} [--glass-text:0%] [--glass-tone:var(--destructive)] [--glass-wash:55%] focus-visible:ring-destructive/30 hover:[--glass-edge:color-mix(in_srgb,var(--destructive)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--destructive)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]`,
25
+ secondary: `glass glass-tint ${CONTROL_GLASS} [--glass-text:0%] [--glass-tone:var(--accent)] [--glass-wash:55%] hover:[--glass-edge:color-mix(in_srgb,var(--accent)_60%,transparent)] hover:[--glass-wash:65%] dark:[--glass-tone:oklch(from_var(--accent)_calc(l_+_clamp(0,(l_-_0.74)*10,0.1))_c_h)] dark:[--glass-wash:62%] dark:[color:oklch(from_var(--glass-tone)_calc((0.74_-_l)*100)_0_0)] dark:hover:[--glass-wash:62%]`,
26
26
  outline: OUTLINE_SURFACE,
27
27
  ghost: "hover:bg-muted hover:text-foreground dark:hover:bg-muted/50",
28
- link: "text-primary underline-offset-4 hover:underline",
28
+ link: "text-primary-tint-foreground underline-offset-4 hover:underline",
29
29
  },
30
30
  size: {
31
31
  default: "h-9 px-4 py-2 has-[>svg]:px-3",
@@ -23,6 +23,11 @@ export const FIELD_MOTION = "data-[closed]:animate-select-out data-[expanded]:an
23
23
  export const MORPH_MOTION =
24
24
  "[--morph-w:var(--kb-popper-anchor-width)] min-w-[var(--kb-popper-anchor-width)] data-[expanded]:animate-morph-in data-[closed]:animate-morph-out";
25
25
 
26
+ /* A dialog anchored on the element that opened it (a tile): it unrolls out of
27
+ * that element's box and rolls back into it, on MORPH_MOTION's keyframes. */
28
+ export const ANCHORED_MOTION =
29
+ "data-[expanded]:animate-anchored-in data-[closed]:animate-morph-out";
30
+
26
31
  /* Children of a panel arrive staggered through the `gh-stagger` class
27
32
  * (globals.css): one door, no per-row index, mount-only. */
28
33
  export const STAGGER = "gh-stagger";
@@ -188,7 +188,13 @@ interface BottomSheetContentProps extends ComponentProps<"div"> {
188
188
  }
189
189
 
190
190
  const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) => {
191
- const [local, rest] = splitProps(props, ["class", "children", "initialFocus", "ariaLabel"]);
191
+ const [local, rest] = splitProps(props, [
192
+ "class",
193
+ "children",
194
+ "initialFocus",
195
+ "ariaLabel",
196
+ "style",
197
+ ]);
192
198
  const ctx = useBottomSheetContext();
193
199
  const labels = createModalLabels();
194
200
  let el: HTMLDivElement | undefined;
@@ -349,6 +355,7 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
349
355
  onAnimationEnd={onAnimationEnd}
350
356
  onTransitionEnd={onTransitionEnd}
351
357
  style={{
358
+ ...(typeof local.style === "object" ? local.style : {}),
352
359
  "z-index": Z.sheet,
353
360
  "--bs-duration": `${TRANSITION_MS}ms`,
354
361
  "--bs-ease": EASE,
@@ -0,0 +1,253 @@
1
+ import type { Color } from "@kobalte/core/colors";
2
+ import { parseColor } from "@kobalte/core/colors";
3
+ import { type Component, createSignal, type JSX } from "solid-js";
4
+ import { FOCUS_RING } from "../lib/input-classes.js";
5
+ import { THUMB_COLOR_RING } from "../lib/thumb-classes.js";
6
+ import { cn } from "../lib/utils.js";
7
+
8
+ const PIN = 34;
9
+ const WHITE = parseColor("hsb(0, 0%, 100%)");
10
+ const THUMB = 38;
11
+ /* The bar keeps its thumb this far from each end, so a press maps to the same span. */
12
+ const THUMB_INSET = 28;
13
+ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
14
+
15
+ /* Hue 0 at three o'clock, turning clockwise, the direction the conic gradient paints. */
16
+ const discBackground =
17
+ "radial-gradient(closest-side, #fff, rgb(255 255 255 / 0) 100%), conic-gradient(from 90deg, hsl(0 100% 50%), hsl(60 100% 50%), hsl(120 100% 50%), hsl(180 100% 50%), hsl(240 100% 50%), hsl(300 100% 50%), hsl(360 100% 50%))";
18
+
19
+ interface ColorDiscProps {
20
+ /** The colour shown and moved: its hue is the direction from the centre, its saturation the distance. */
21
+ value?: Color;
22
+ onChange?: (value: Color) => void;
23
+ onChangeEnd?: (value: Color) => void;
24
+ /** Diameter in px. */
25
+ size?: number;
26
+ disabled?: boolean;
27
+ class?: string;
28
+ "aria-label"?: string;
29
+ }
30
+
31
+ /**
32
+ * A colour disc: hue around it, saturation from the white centre to the rim, one thumb for both.
33
+ */
34
+ const ColorDisc: Component<ColorDiscProps> = (props) => {
35
+ const size = () => props.size ?? 260;
36
+ const radius = () => size() / 2;
37
+ const value = () => props.value ?? WHITE;
38
+ const hsb = () => value().toFormat("hsb");
39
+ const place = (hue: number, saturation: number) => {
40
+ const a = (hue * Math.PI) / 180;
41
+ const r = (clamp(saturation, 0, 100) / 100) * (radius() - PIN / 2);
42
+ return { x: radius() + r * Math.cos(a), y: radius() + r * Math.sin(a) };
43
+ };
44
+ const thumb = () => place(hsb().getChannelValue("hue"), hsb().getChannelValue("saturation"));
45
+ const [dragging, setDragging] = createSignal(false);
46
+ let last: Color | undefined;
47
+ const colourAt = (e: PointerEvent, el: HTMLElement): Color => {
48
+ const box = el.getBoundingClientRect();
49
+ const dx = e.clientX - (box.left + box.width / 2);
50
+ const dy = e.clientY - (box.top + box.height / 2);
51
+ const hue = ((Math.atan2(dy, dx) * 180) / Math.PI + 360) % 360;
52
+ const saturation = clamp((Math.hypot(dx, dy) / (box.width / 2 - PIN / 2)) * 100, 0, 100);
53
+ last = hsb()
54
+ .withChannelValue("hue", Math.round(hue))
55
+ .withChannelValue("saturation", Math.round(saturation));
56
+ return last;
57
+ };
58
+
59
+ const onKeyDown = (e: KeyboardEvent) => {
60
+ if (props.disabled) return;
61
+ const step = e.shiftKey ? 10 : 2;
62
+ const h = hsb().getChannelValue("hue");
63
+ const s = hsb().getChannelValue("saturation");
64
+ const next =
65
+ e.key === "ArrowLeft"
66
+ ? hsb().withChannelValue("hue", (h - step + 360) % 360)
67
+ : e.key === "ArrowRight"
68
+ ? hsb().withChannelValue("hue", (h + step) % 360)
69
+ : e.key === "ArrowUp"
70
+ ? hsb().withChannelValue("saturation", clamp(s + step, 0, 100))
71
+ : e.key === "ArrowDown"
72
+ ? hsb().withChannelValue("saturation", clamp(s - step, 0, 100))
73
+ : undefined;
74
+ if (!next) return;
75
+ e.preventDefault();
76
+ props.onChange?.(next);
77
+ props.onChangeEnd?.(next);
78
+ };
79
+
80
+ return (
81
+ <div
82
+ data-slot="color-disc"
83
+ class={cn(
84
+ "relative touch-none select-none rounded-full",
85
+ props.disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer",
86
+ props.class,
87
+ )}
88
+ style={{
89
+ width: `${size()}px`,
90
+ height: `${size()}px`,
91
+ background: discBackground,
92
+ "box-shadow": "inset 0 0 0 1px rgb(255 255 255 / 0.15)",
93
+ }}
94
+ onPointerDown={(e) => {
95
+ if (props.disabled || e.button !== 0) return;
96
+ const el = e.currentTarget;
97
+ el.setPointerCapture?.(e.pointerId);
98
+ setDragging(true);
99
+ props.onChange?.(colourAt(e, el));
100
+ }}
101
+ onPointerMove={(e) => {
102
+ if (dragging()) props.onChange?.(colourAt(e, e.currentTarget));
103
+ }}
104
+ onPointerUp={(e) => {
105
+ if (!dragging()) return;
106
+ setDragging(false);
107
+ props.onChangeEnd?.(colourAt(e, e.currentTarget));
108
+ }}
109
+ onPointerCancel={() => {
110
+ if (!dragging()) return;
111
+ setDragging(false);
112
+ if (last) props.onChangeEnd?.(last);
113
+ }}
114
+ >
115
+ <div
116
+ role="slider"
117
+ tabIndex={props.disabled ? -1 : 0}
118
+ aria-label={props["aria-label"] ?? "Colour"}
119
+ aria-valuemin={0}
120
+ aria-valuemax={360}
121
+ aria-valuenow={Math.round(hsb().getChannelValue("hue"))}
122
+ aria-valuetext={`Hue ${Math.round(hsb().getChannelValue("hue"))}, saturation ${Math.round(hsb().getChannelValue("saturation"))}%`}
123
+ data-slot="color-disc-thumb"
124
+ class={cn(
125
+ "absolute rounded-full shadow-[0_2px_8px_rgb(0_0_0/0.45)]",
126
+ THUMB_COLOR_RING,
127
+ FOCUS_RING,
128
+ )}
129
+ style={{
130
+ left: `${thumb().x}px`,
131
+ top: `${thumb().y}px`,
132
+ width: `${THUMB}px`,
133
+ height: `${THUMB}px`,
134
+ translate: "-50% -50%",
135
+ background: value().toString("css"),
136
+ "pointer-events": "none",
137
+ }}
138
+ onKeyDown={onKeyDown}
139
+ />
140
+ </div>
141
+ );
142
+ };
143
+
144
+ interface TemperatureBarProps {
145
+ /** The white shown, in Kelvin. */
146
+ value: number;
147
+ min?: number;
148
+ max?: number;
149
+ onChange?: (kelvin: number) => void;
150
+ onChangeEnd?: (kelvin: number) => void;
151
+ disabled?: boolean;
152
+ class?: string;
153
+ "aria-label"?: string;
154
+ }
155
+
156
+ /** Kelvin to a display colour, for the bar's paint only. */
157
+ export function kelvinToCss(kelvin: number): string {
158
+ const t = clamp((kelvin - 2000) / 4500, 0, 1);
159
+ const warm = parseColor("#ff9f3f").toFormat("rgb");
160
+ const mid = parseColor("#fff4e6").toFormat("rgb");
161
+ const cool = parseColor("#d6e6ff").toFormat("rgb");
162
+ const [a, b, u] = t < 0.5 ? [warm, mid, t * 2] : [mid, cool, (t - 0.5) * 2];
163
+ const mix = (ch: "red" | "green" | "blue") =>
164
+ Math.round(a.getChannelValue(ch) + (b.getChannelValue(ch) - a.getChannelValue(ch)) * u);
165
+ return `rgb(${mix("red")} ${mix("green")} ${mix("blue")})`;
166
+ }
167
+
168
+ /** Warm to cool white on one bar, in Kelvin, over the span the lamps can reach. */
169
+ const TemperatureBar: Component<TemperatureBarProps> = (props) => {
170
+ const min = () => props.min ?? 2000;
171
+ const max = () => props.max ?? 6500;
172
+ const span = () => Math.max(max() - min(), 1);
173
+ const pos = (k: number) => ((clamp(k, min(), max()) - min()) / span()) * 100;
174
+ const [dragging, setDragging] = createSignal(false);
175
+ let last: number | undefined;
176
+ const kelvinAt = (e: PointerEvent, el: HTMLElement) => {
177
+ const box = el.getBoundingClientRect();
178
+ const t = clamp(
179
+ (e.clientX - box.left - THUMB_INSET) / Math.max(box.width - 2 * THUMB_INSET, 1),
180
+ 0,
181
+ 1,
182
+ );
183
+ last = clamp(Math.round((min() + t * span()) / 50) * 50, min(), max());
184
+ return last;
185
+ };
186
+ const gradient = (): JSX.CSSProperties => ({
187
+ background: `linear-gradient(90deg, ${kelvinToCss(min())}, ${kelvinToCss((min() + max()) / 2)}, ${kelvinToCss(max())})`,
188
+ });
189
+ return (
190
+ <div
191
+ data-slot="temperature-bar"
192
+ class={cn(
193
+ "relative h-14 w-full touch-none select-none rounded-full",
194
+ props.disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer",
195
+ props.class,
196
+ )}
197
+ style={gradient()}
198
+ onPointerDown={(e) => {
199
+ if (props.disabled || e.button !== 0) return;
200
+ e.currentTarget.setPointerCapture?.(e.pointerId);
201
+ setDragging(true);
202
+ props.onChange?.(kelvinAt(e, e.currentTarget));
203
+ }}
204
+ onPointerMove={(e) => {
205
+ if (dragging()) props.onChange?.(kelvinAt(e, e.currentTarget));
206
+ }}
207
+ onPointerUp={(e) => {
208
+ if (!dragging()) return;
209
+ setDragging(false);
210
+ props.onChangeEnd?.(kelvinAt(e, e.currentTarget));
211
+ }}
212
+ onPointerCancel={() => {
213
+ if (!dragging()) return;
214
+ setDragging(false);
215
+ if (last !== undefined) props.onChangeEnd?.(last);
216
+ }}
217
+ >
218
+ <div
219
+ role="slider"
220
+ tabIndex={props.disabled ? -1 : 0}
221
+ aria-label={props["aria-label"] ?? "White"}
222
+ aria-valuemin={min()}
223
+ aria-valuemax={max()}
224
+ aria-valuenow={props.value}
225
+ aria-valuetext={`${props.value} Kelvin`}
226
+ data-slot="temperature-bar-thumb"
227
+ class={cn(
228
+ "pointer-events-none absolute top-1/2 rounded-full",
229
+ THUMB_COLOR_RING,
230
+ FOCUS_RING,
231
+ )}
232
+ style={{
233
+ left: `calc(${THUMB_INSET}px + (100% - ${2 * THUMB_INSET}px) * ${pos(props.value) / 100})`,
234
+ width: `${THUMB}px`,
235
+ height: `${THUMB}px`,
236
+ translate: "-50% -50%",
237
+ background: kelvinToCss(props.value),
238
+ }}
239
+ onKeyDown={(e) => {
240
+ const step = e.shiftKey ? 500 : 100;
241
+ const d = e.key === "ArrowRight" ? step : e.key === "ArrowLeft" ? -step : 0;
242
+ if (!d || props.disabled) return;
243
+ e.preventDefault();
244
+ const k = clamp(props.value + d, min(), max());
245
+ props.onChange?.(k);
246
+ props.onChangeEnd?.(k);
247
+ }}
248
+ />
249
+ </div>
250
+ );
251
+ };
252
+
253
+ export { ColorDisc, TemperatureBar };
@@ -0,0 +1,128 @@
1
+ import { For, type JSX, Show } from "solid-js";
2
+ import { SECTION_ROW_SURFACE } from "../lib/card-classes.js";
3
+ import { FIELD_CHROME } from "../lib/input-classes.js";
4
+ import { cn } from "../lib/utils.js";
5
+ import { Icon } from "./icon.js";
6
+
7
+ /** Dash's lattice: the grid a widget render is shot on. */
8
+ const CELL = { w: 90, h: 70, gap: 16 } as const;
9
+
10
+ export interface DashboardPreviewTile {
11
+ key: string;
12
+ x: number;
13
+ y: number;
14
+ w: number;
15
+ h: number;
16
+ /** A render shot at exactly this w x h; never a render of another size. */
17
+ src?: string;
18
+ icon: string;
19
+ label: string;
20
+ description?: string;
21
+ }
22
+
23
+ const span = (n: number, cell: number) => n * cell + (n - 1) * CELL.gap;
24
+
25
+ /** A dashboard drawn from widget renders at their true grid positions, scaled to its box. */
26
+ export function DashboardPreview(props: {
27
+ columns: number;
28
+ tiles: DashboardPreviewTile[];
29
+ /** Rows shown at most; the rest is cut at the bottom edge. */
30
+ maxRows?: number;
31
+ /** Sit the dashboard in a recessed well, the ground it would stand on. */
32
+ stage?: boolean;
33
+ class?: string;
34
+ style?: JSX.CSSProperties;
35
+ }) {
36
+ const rows = () => {
37
+ const used = Math.max(1, ...props.tiles.map((t) => t.y + t.h));
38
+ return props.maxRows ? Math.min(used, props.maxRows) : used;
39
+ };
40
+ const width = () => span(props.columns, CELL.w);
41
+ const height = () => span(rows(), CELL.h);
42
+ const pct = (value: number, of: number) => `${(value / of) * 100}%`;
43
+
44
+ const board = () => (
45
+ <div
46
+ data-slot="dashboard-preview"
47
+ class={cn("@container relative w-full overflow-hidden", props.class)}
48
+ style={{ "aspect-ratio": `${width()} / ${height()}`, ...props.style }}
49
+ >
50
+ <div
51
+ class="absolute inset-0"
52
+ style={{ "--dp-unit": `calc(100cqw / ${width()})` } as JSX.CSSProperties}
53
+ >
54
+ <For each={props.tiles}>
55
+ {(tile) => (
56
+ <div
57
+ data-slot="dashboard-preview-tile"
58
+ class="absolute"
59
+ style={{
60
+ left: pct(tile.x * (CELL.w + CELL.gap), width()),
61
+ top: pct(tile.y * (CELL.h + CELL.gap), height()),
62
+ width: pct(span(tile.w, CELL.w), width()),
63
+ height: pct(span(tile.h, CELL.h), height()),
64
+ }}
65
+ >
66
+ <Show when={tile.src} fallback={<IconTile tile={tile} />}>
67
+ {(src) => (
68
+ <img
69
+ src={src()}
70
+ alt={tile.label}
71
+ loading="lazy"
72
+ decoding="async"
73
+ class="block h-full w-full"
74
+ />
75
+ )}
76
+ </Show>
77
+ </div>
78
+ )}
79
+ </For>
80
+ </div>
81
+ </div>
82
+ );
83
+ return (
84
+ <Show when={props.stage} fallback={board()}>
85
+ <div
86
+ data-slot="dashboard-preview-stage"
87
+ class={cn(FIELD_CHROME, "flex justify-center rounded-xl p-3")}
88
+ >
89
+ {board()}
90
+ </div>
91
+ </Show>
92
+ );
93
+ }
94
+
95
+ const u = (n: number) => `calc(var(--dp-unit) * ${n})`;
96
+
97
+ function IconTile(props: { tile: DashboardPreviewTile }) {
98
+ const roomy = () => props.tile.w >= 2 && props.tile.h >= 2;
99
+ return (
100
+ <div
101
+ data-slot="dashboard-preview-icon-tile"
102
+ class={cn(
103
+ SECTION_ROW_SURFACE,
104
+ "flex h-full w-full items-center overflow-hidden text-muted-foreground",
105
+ roomy() ? "flex-col justify-center text-center" : "justify-center",
106
+ )}
107
+ style={{ "border-radius": u(20), gap: u(roomy() ? 8 : 10), padding: u(12) }}
108
+ >
109
+ <Icon
110
+ icon={props.tile.icon}
111
+ width="1em"
112
+ height="1em"
113
+ style={{ "font-size": u(roomy() ? 32 : 22) }}
114
+ class="shrink-0 text-foreground/80"
115
+ />
116
+ <div class="flex min-w-0 flex-col" style={{ gap: u(4) }}>
117
+ <span class="truncate font-medium text-foreground/90" style={{ "font-size": u(13) }}>
118
+ {props.tile.label}
119
+ </span>
120
+ <Show when={roomy() && props.tile.description}>
121
+ <span class="line-clamp-2" style={{ "font-size": u(11), "line-height": 1.3 }}>
122
+ {props.tile.description}
123
+ </span>
124
+ </Show>
125
+ </div>
126
+ </div>
127
+ );
128
+ }
@@ -18,7 +18,7 @@ import {
18
18
  } from "solid-js";
19
19
  import { Dynamic } from "solid-js/web";
20
20
  import { Z_CLASS } from "../lib/layers.js";
21
- import { MODAL_MOTION, SCRIM_MOTION } from "../lib/motion-classes.js";
21
+ import { ANCHORED_MOTION, MODAL_MOTION, SCRIM_MOTION } from "../lib/motion-classes.js";
22
22
  import { OVERLAY_SURFACE, SCRIM_CLASS } from "../lib/overlay-classes.js";
23
23
  import { cn } from "../lib/utils.js";
24
24
  import { acquireScrollLock, releaseScrollLock } from "./bottom-sheet/scroll-lock.js";
@@ -61,6 +61,10 @@ export const MODAL_ANCHOR: Record<ModalSize, string> = {
61
61
  * panel edge instead of under the header. */
62
62
  export const MODAL_PANEL = `${OVERLAY_SURFACE} ${MODAL_MOTION} fixed left-1/2 flex ${MODAL_MAX_H} w-[calc(100%-2rem)] -translate-x-1/2 flex-col overflow-hidden rounded-lg outline-none ${Z_CLASS.overlay}`;
63
63
 
64
+ /* A panel anchored on the element that opened it: placed and sized inline (lib/anchor-placement),
65
+ * so it drops the centring, and it unrolls out of that element instead of rising in. */
66
+ export const ANCHORED_PANEL = `${OVERLAY_SURFACE} ${ANCHORED_MOTION} fixed flex ${MODAL_MAX_H} flex-col overflow-hidden rounded-lg outline-none ${Z_CLASS.overlay}`;
67
+
64
68
  export const MODAL_SCRIM = `${SCRIM_MOTION} fixed inset-0 ${Z_CLASS.overlay} ${SCRIM_CLASS}`;
65
69
 
66
70
  const MODAL_HEADER = "flex shrink-0 items-start gap-4 px-6 pt-6 pb-3";
@@ -1,9 +1,19 @@
1
1
  import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
2
2
  import type { VariantProps } from "cva";
3
- import { type Component, type ComponentProps, type ParentComponent, splitProps } from "solid-js";
3
+ import {
4
+ type Component,
5
+ type ComponentProps,
6
+ createEffect,
7
+ createSignal,
8
+ onCleanup,
9
+ type ParentComponent,
10
+ splitProps,
11
+ } from "solid-js";
12
+ import { overAnchor } from "../lib/anchor-placement.js";
4
13
  import { buttonVariants } from "../lib/button-variants.js";
5
14
  import { cn } from "../lib/utils.js";
6
15
  import {
16
+ ANCHORED_PANEL,
7
17
  createModalDismiss,
8
18
  createModalParts,
9
19
  MODAL_ANCHOR,
@@ -55,11 +65,42 @@ type DialogContentProps = ComponentProps<typeof DialogPrimitive.Content> & {
55
65
  size?: ModalSize;
56
66
  /** Names a panel that has no `DialogTitle`. A registered Title wins. */
57
67
  ariaLabel?: string;
68
+ /** Opens the panel out of this element (the tile it came from): it grows from the element's box
69
+ * over it instead of appearing centred, and closes back into it. */
70
+ anchor?: HTMLElement;
71
+ };
72
+
73
+ /* Pixel widths of the sizes an anchored panel keeps (Tailwind's max-w-sm/md/lg/3xl/5xl). */
74
+ const ANCHORED_WIDTH: Record<ModalSize, number> = {
75
+ sm: 384,
76
+ md: 448,
77
+ lg: 512,
78
+ xl: 768,
79
+ full: 1024,
58
80
  };
59
81
 
60
82
  const DialogContent: ParentComponent<DialogContentProps> = (props) => {
61
- const [local, others] = splitProps(props, ["class", "children", "size", "ariaLabel"]);
83
+ const [local, others] = splitProps(props, [
84
+ "class",
85
+ "children",
86
+ "size",
87
+ "ariaLabel",
88
+ "anchor",
89
+ "style",
90
+ ]);
62
91
  const context = useDialogContext();
92
+ const [viewport, setViewport] = createSignal(0);
93
+ createEffect(() => {
94
+ if (!local.anchor || !context.isOpen()) return;
95
+ const measure = () => setViewport((n) => n + 1);
96
+ window.addEventListener("resize", measure);
97
+ onCleanup(() => window.removeEventListener("resize", measure));
98
+ });
99
+ const placement = () => {
100
+ viewport();
101
+ const a = local.anchor;
102
+ return a ? overAnchor(a, ANCHORED_WIDTH[local.size ?? "lg"]) : undefined;
103
+ };
63
104
  return (
64
105
  <DialogPrimitive.Portal>
65
106
  <ModalScrollLock />
@@ -69,11 +110,12 @@ const DialogContent: ParentComponent<DialogContentProps> = (props) => {
69
110
  role="dialog"
70
111
  aria-label={context.titleId() ? undefined : local.ariaLabel}
71
112
  class={cn(
72
- MODAL_PANEL,
73
- MODAL_WIDTH[local.size ?? "lg"],
74
- MODAL_ANCHOR[local.size ?? "lg"],
113
+ local.anchor ? ANCHORED_PANEL : MODAL_PANEL,
114
+ !local.anchor && MODAL_WIDTH[local.size ?? "lg"],
115
+ !local.anchor && MODAL_ANCHOR[local.size ?? "lg"],
75
116
  local.class,
76
117
  )}
118
+ style={{ ...(typeof local.style === "object" ? local.style : {}), ...placement() }}
77
119
  {...others}
78
120
  >
79
121
  {local.children}
@@ -507,7 +507,7 @@ export function EntitySelector(props: EntitySelectorProps) {
507
507
  </span>
508
508
  <button
509
509
  type="button"
510
- class="text-primary text-sm hover:underline"
510
+ class="text-primary-tint-foreground text-sm hover:underline"
511
511
  onClick={() => setShowDiagnostics(true)}
512
512
  >
513
513
  Show diagnostic entities
@@ -520,7 +520,7 @@ export function EntitySelector(props: EntitySelectorProps) {
520
520
  </span>
521
521
  <button
522
522
  type="button"
523
- class="text-primary text-sm hover:underline"
523
+ class="text-primary-tint-foreground text-sm hover:underline"
524
524
  onClick={() => setSearch("")}
525
525
  >
526
526
  Clear search