@glasshome/ui 1.18.0 → 1.20.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 (78) hide show
  1. package/SPEC.md +84 -2
  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 +4 -1
  5. package/dist/lib/card-classes.d.ts +4 -4
  6. package/dist/lib/motion-classes.d.ts +2 -0
  7. package/dist/lib/overlay-classes.d.ts +4 -2
  8. package/dist/lib/spotlight-geometry.d.ts +22 -0
  9. package/dist/solid/button.d.ts +8 -3
  10. package/dist/solid/color-disc.d.ts +33 -0
  11. package/dist/solid/dashboard-preview.d.ts +24 -0
  12. package/dist/solid/dialog-parts.d.ts +1 -0
  13. package/dist/solid/dialog.d.ts +3 -0
  14. package/dist/solid/dock.d.ts +9 -0
  15. package/dist/solid/docked-panel.d.ts +11 -0
  16. package/dist/solid/image-picker.d.ts +3 -0
  17. package/dist/solid/index.d.ts +9 -3
  18. package/dist/solid/index.js +6254 -5475
  19. package/dist/solid/media-store.d.ts +10 -0
  20. package/dist/solid/option-card.d.ts +2 -1
  21. package/dist/solid/page-header.d.ts +2 -2
  22. package/dist/solid/preview-tile.d.ts +35 -0
  23. package/dist/solid/responsive-dialog.d.ts +2 -0
  24. package/dist/solid/schema-form.d.ts +6 -1
  25. package/dist/solid/sliding-indicator.d.ts +2 -0
  26. package/dist/solid/spotlight.d.ts +14 -0
  27. package/dist/solid/swatch-picker.d.ts +12 -0
  28. package/dist/solid/tabs.d.ts +4 -1
  29. package/dist/solid/toggle-group.d.ts +4 -1
  30. package/dist/solid/widget-identity.d.ts +2 -0
  31. package/dist/tokens/index.d.ts +1 -0
  32. package/dist/tokens/index.js +336 -118
  33. package/dist/tokens/material.d.ts +40 -0
  34. package/dist/tokens/presets.d.ts +3 -0
  35. package/dist/tokens/theme-colors.d.ts +13 -3
  36. package/dist/tokens/theme-recipe.d.ts +8 -0
  37. package/dist/{utils-COITV1s9.js → utils-CMk7R3zM.js} +488 -485
  38. package/package.json +2 -2
  39. package/scripts/check-ui-drift.mjs +5 -0
  40. package/src/lib/anchor-placement.ts +30 -0
  41. package/src/lib/button-variants.ts +13 -12
  42. package/src/lib/card-classes.ts +4 -3
  43. package/src/lib/motion-classes.ts +10 -0
  44. package/src/lib/overlay-classes.ts +10 -2
  45. package/src/lib/spotlight-geometry.ts +90 -0
  46. package/src/solid/bottom-sheet/bottom-sheet.tsx +8 -1
  47. package/src/solid/button.tsx +17 -2
  48. package/src/solid/color-disc.tsx +253 -0
  49. package/src/solid/dashboard-preview.tsx +128 -0
  50. package/src/solid/dialog-parts.tsx +5 -1
  51. package/src/solid/dialog.tsx +47 -5
  52. package/src/solid/dock.tsx +67 -9
  53. package/src/solid/docked-panel.tsx +56 -0
  54. package/src/solid/entity-selector.tsx +2 -2
  55. package/src/solid/hero-action.tsx +2 -2
  56. package/src/solid/image-picker.tsx +232 -147
  57. package/src/solid/index.ts +20 -2
  58. package/src/solid/media-store.ts +20 -1
  59. package/src/solid/option-card.tsx +27 -31
  60. package/src/solid/page-header.tsx +9 -16
  61. package/src/solid/preview-tile.tsx +89 -0
  62. package/src/solid/radio-group.tsx +7 -2
  63. package/src/solid/responsive-dialog.tsx +10 -2
  64. package/src/solid/schema-form.tsx +30 -4
  65. package/src/solid/section-card.tsx +4 -2
  66. package/src/solid/sliding-indicator.tsx +34 -17
  67. package/src/solid/spotlight.tsx +179 -0
  68. package/src/solid/swatch-picker.tsx +47 -0
  69. package/src/solid/tabs.tsx +20 -4
  70. package/src/solid/toggle-group.tsx +43 -8
  71. package/src/solid/widget-identity.tsx +3 -1
  72. package/src/styles/globals.css +166 -14
  73. package/src/styles/theme.css +25 -3
  74. package/src/tokens/index.ts +1 -0
  75. package/src/tokens/material.ts +116 -0
  76. package/src/tokens/presets.ts +195 -56
  77. package/src/tokens/theme-colors.ts +15 -3
  78. package/src/tokens/theme-recipe.ts +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.18.0",
3
+ "version": "1.20.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",
@@ -109,7 +109,7 @@
109
109
  "@tailwindcss/vite": "^4.1.13",
110
110
  "@types/node": "^25.2.2",
111
111
  "fallow": "3.17.0",
112
- "happy-dom": "^20.11.0",
112
+ "happy-dom": "^20.14.0",
113
113
  "playwright": "^1.60.0",
114
114
  "publint": "^0.3.21",
115
115
  "tailwindcss": "^4.1.13",
@@ -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,21 +20,19 @@ 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:70%] [--glass-tone:var(--primary)] [--glass-wash:30%] hover:[--glass-edge:color-mix(in_srgb,var(--primary)_60%,transparent)] hover:[--glass-wash:40%]",
22
- destructive:
23
- "glass glass-tint [--glass-text:61%] [--glass-tone:var(--destructive)] [--glass-wash:30%] focus-visible:ring-destructive/30 hover:[--glass-edge:color-mix(in_srgb,var(--destructive)_60%,transparent)] hover:[--glass-wash:40%]",
24
- secondary:
25
- "glass glass-tint [--glass-tone:var(--accent)] [--glass-wash:30%] hover:[--glass-edge:color-mix(in_srgb,var(--accent)_60%,transparent)] hover:[--glass-wash:40%]",
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",
32
32
  sm: "h-8 gap-1.5 px-3 has-[>svg]:px-2.5",
33
33
  lg: "h-10 px-6 has-[>svg]:px-4",
34
34
  icon: "size-9 p-2",
35
+ xl: "h-[72px] gap-3.5 rounded-full pr-7 pl-3 text-left font-semibold text-[17px] [&_svg:not([class*='size-'])]:size-5",
35
36
  none: "",
36
37
  },
37
38
  },
@@ -3,11 +3,12 @@ import { PRESS_DIP } from "./motion-classes.js";
3
3
  const CARD_KNOBS =
4
4
  "glass [--glass-wash:20%] [--glass-rim:0.3] [--glass-lift:0.45] [--glass-shade:0.05] dark:[--glass-shade:0]";
5
5
 
6
- export const CARD_SURFACE_BASE = `${CARD_KNOBS} [--glass-base:color-mix(in_srgb,var(--card)_60%,transparent)]`;
6
+ export const CARD_SURFACE_BASE = `${CARD_KNOBS} [--glass-base:color-mix(in_srgb,var(--card)_var(--material-clarity),transparent)]`;
7
7
 
8
8
  /* Split from the surface so dash's performant-blur engine can gate it off and
9
9
  * paint a precomputed frost instead. */
10
- export const CARD_BLUR = "backdrop-blur-[var(--glass-blur,24px)] backdrop-saturate-[1.8]";
10
+ export const CARD_BLUR =
11
+ "backdrop-blur-[var(--glass-blur,var(--material-blur,24px))] backdrop-saturate-[1.8]";
11
12
 
12
13
  export const CARD_SURFACE = `${CARD_SURFACE_BASE} ${CARD_BLUR}`;
13
14
 
@@ -18,7 +19,7 @@ export const CARD_SURFACE_OPAQUE = CARD_KNOBS;
18
19
  /* Rows inside a section: the card material again, one step in, so a row never
19
20
  * reads as a flat plate on a glass panel. */
20
21
  export const SECTION_ROW_SURFACE =
21
- "glass [--glass-rim:0.3] [--glass-base:color-mix(in_srgb,var(--card)_60%,transparent)]";
22
+ "glass [--glass-rim:0.3] [--glass-base:color-mix(in_srgb,var(--card)_var(--material-clarity),transparent)]";
22
23
 
23
24
  /* Recessed track frame (tabs, segmented controls). */
24
25
  export const TRACK_SURFACE = "border border-border/50 bg-card/40 backdrop-blur-sm";
@@ -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";
@@ -49,3 +54,8 @@ export const HOLD_MOTION =
49
54
  * ends and leaves the element showing. */
50
55
  export const RISE_MOTION =
51
56
  "origin-bottom transition-[opacity,scale,translate] data-[expanded]:duration-(--duration-expand) data-[expanded]:ease-(--ease-expand) data-[closed]:duration-(--duration-micro) data-[closed]:ease-(--ease-contract) data-[closed]:pointer-events-none data-[closed]:translate-y-2 data-[closed]:scale-95 data-[closed]:opacity-0";
57
+
58
+ /* A mounted surface that follows its subject from place to place (the
59
+ * spotlight's hole and bubble). */
60
+ export const TRAVEL_MOTION =
61
+ "transition-[translate,clip-path] duration-(--duration-morph) ease-(--ease-expand)";
@@ -8,7 +8,8 @@ const OVERLAY_KNOBS =
8
8
 
9
9
  /* Split from the surface the way CARD_BLUR is, so a host can gate it off and
10
10
  * paint a precomputed frost instead. */
11
- export const OVERLAY_BLUR = "backdrop-blur-[var(--glass-blur,24px)] backdrop-saturate-[1.2]";
11
+ export const OVERLAY_BLUR =
12
+ "backdrop-blur-[var(--glass-blur,var(--material-blur,24px))] backdrop-saturate-[1.2]";
12
13
 
13
14
  export const OVERLAY_SURFACE_BASE = `${OVERLAY_KNOBS} [--glass-base:color-mix(in_srgb,var(--popover)_92%,transparent)]`;
14
15
 
@@ -26,9 +27,16 @@ export const OVERLAY_SURFACE_OPAQUE = `${OVERLAY_KNOBS} [--glass-base:var(--popo
26
27
  * unblurred scrim (backdrop-blur is too slow on mobile). */
27
28
  export const SCRIM_CLASS = "bg-scrim backdrop-blur-md";
28
29
 
30
+ export const PANEL_TAIL = `${Z_CLASS.overlay} rounded-md text-popover-foreground outline-hidden`;
31
+
32
+ /* The floating panel surface, minus positioning: a caller that is not
33
+ * anchor-relative (Spotlight's fixed bubble) composes this instead of
34
+ * FLOATING_PANEL. */
35
+ export const FLOATING_PANEL_SURFACE = `${OVERLAY_SURFACE} ${PANEL_TAIL}`;
36
+
29
37
  /* The floating panel every anchored surface wears. Padding is the caller's:
30
38
  * menus add p-1, popovers p-4, pickers none. */
31
- export const FLOATING_PANEL = `${OVERLAY_SURFACE} relative ${Z_CLASS.overlay} rounded-md text-popover-foreground outline-hidden`;
39
+ export const FLOATING_PANEL = `${OVERLAY_SURFACE} relative ${PANEL_TAIL}`;
32
40
 
33
41
  /* Zero-height rect on the trigger's top edge. With gutter 0 and the panel
34
42
  * width bound to --kb-popper-anchor-width, the panel covers the trigger and
@@ -0,0 +1,90 @@
1
+ export interface Box {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }
7
+
8
+ export interface Viewport {
9
+ width: number;
10
+ height: number;
11
+ }
12
+
13
+ /* Outer rect plus a rounded rect, filled even-odd. With no target the hole
14
+ * collapses to a point at the centre, same commands, so clip-path interpolates. */
15
+ export function holePath(
16
+ viewport: Viewport,
17
+ target: Box | null,
18
+ pad: number,
19
+ radius: number,
20
+ ): string {
21
+ const box = target
22
+ ? {
23
+ x: target.x - pad,
24
+ y: target.y - pad,
25
+ width: target.width + pad * 2,
26
+ height: target.height + pad * 2,
27
+ }
28
+ : { x: viewport.width / 2, y: viewport.height / 2, width: 0, height: 0 };
29
+ const r = Math.max(0, Math.min(radius, box.width / 2, box.height / 2));
30
+ const left = box.x;
31
+ const top = box.y;
32
+ const right = box.x + box.width;
33
+ const bottom = box.y + box.height;
34
+ const outer = `M0 0H${viewport.width}V${viewport.height}H0Z`;
35
+ const hole =
36
+ `M${left + r} ${top}H${right - r}A${r} ${r} 0 0 1 ${right} ${top + r}` +
37
+ `V${bottom - r}A${r} ${r} 0 0 1 ${right - r} ${bottom}` +
38
+ `H${left + r}A${r} ${r} 0 0 1 ${left} ${bottom - r}` +
39
+ `V${top + r}A${r} ${r} 0 0 1 ${left + r} ${top}Z`;
40
+ return outer + hole;
41
+ }
42
+
43
+ const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
44
+
45
+ /* --radius-md (the panel's rounding) at the default 16px root: --radius 22.4px minus 2px. */
46
+ const PANEL_RADIUS = 20.4;
47
+ /* Keeps the tail off the rounded corners it would otherwise sit under. */
48
+ const TAIL_MARGIN = PANEL_RADIUS + 8;
49
+
50
+ export function placeBubble(
51
+ viewport: Viewport,
52
+ target: Box | null,
53
+ bubble: { width: number; height: number },
54
+ gap: number,
55
+ margin: number,
56
+ ): {
57
+ x: number;
58
+ y: number;
59
+ side: "above" | "below" | "center" | "inside";
60
+ tail: { x: number } | null;
61
+ } {
62
+ if (!target) {
63
+ return {
64
+ x: (viewport.width - bubble.width) / 2,
65
+ y: (viewport.height - bubble.height) / 2,
66
+ side: "center",
67
+ tail: null,
68
+ };
69
+ }
70
+ const rawX = target.x + target.width / 2 - bubble.width / 2;
71
+ if (target.height > viewport.height / 2) {
72
+ return {
73
+ x: clamp(rawX, margin, viewport.width - bubble.width - margin),
74
+ y: clamp(target.y + gap, margin, viewport.height - bubble.height - margin),
75
+ side: "inside",
76
+ tail: null,
77
+ };
78
+ }
79
+ const centreY = target.y + target.height / 2;
80
+ const side = centreY > viewport.height / 2 ? "above" : "below";
81
+ const rawY = side === "above" ? target.y - gap - bubble.height : target.y + target.height + gap;
82
+ const x = clamp(rawX, margin, viewport.width - bubble.width - margin);
83
+ const anchorCentre = target.x + target.width / 2;
84
+ return {
85
+ x,
86
+ y: clamp(rawY, margin, viewport.height - bubble.height - margin),
87
+ side,
88
+ tail: { x: clamp(anchorCentre - x, TAIL_MARGIN, bubble.width - TAIL_MARGIN) },
89
+ };
90
+ }
@@ -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,
@@ -1,8 +1,9 @@
1
1
  import { Button as KobalteButton } from "@kobalte/core/button";
2
2
  import type { VariantProps } from "cva";
3
- import { type ComponentProps, splitProps } from "solid-js";
3
+ import { type ComponentProps, type JSX, splitProps } from "solid-js";
4
4
  import { buttonVariants } from "../lib/button-variants.js";
5
5
  import { cn } from "../lib/utils.js";
6
+ import { Icon } from "./icon.js";
6
7
 
7
8
  type ButtonProps = ComponentProps<typeof KobalteButton> & VariantProps<typeof buttonVariants>;
8
9
 
@@ -17,4 +18,18 @@ function Button(props: ButtonProps) {
17
18
  );
18
19
  }
19
20
 
20
- export { Button, buttonVariants };
21
+ function ButtonWell(props: { icon?: string; children?: JSX.Element; class?: string }) {
22
+ return (
23
+ <span
24
+ data-slot="button-well"
25
+ class={cn(
26
+ "grid size-12 shrink-0 place-items-center rounded-full bg-foreground/15",
27
+ props.class,
28
+ )}
29
+ >
30
+ {props.children ?? (props.icon ? <Icon icon={props.icon} /> : null)}
31
+ </span>
32
+ );
33
+ }
34
+
35
+ export { Button, ButtonWell, buttonVariants };
@@ -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 };