@glasshome/ui 1.21.1 → 1.21.2

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 (145) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/use-is-mobile.d.ts +3 -1
  4. package/dist/solid/index.d.ts +9 -9
  5. package/dist/solid/index.js +5431 -5424
  6. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  7. package/package.json +128 -126
  8. package/scripts/check-gallery.ts +142 -142
  9. package/scripts/check-pack.ts +13 -13
  10. package/scripts/check-structural-classes.ts +20 -20
  11. package/scripts/check-tokens.ts +27 -27
  12. package/scripts/check-ui-drift.mjs +103 -103
  13. package/src/index.ts +75 -80
  14. package/src/lib/alert-tones.ts +41 -41
  15. package/src/lib/anchor-placement.ts +21 -21
  16. package/src/lib/button-variants.ts +28 -28
  17. package/src/lib/card-classes.ts +9 -9
  18. package/src/lib/carousel-classes.ts +14 -14
  19. package/src/lib/glass-tone.ts +11 -11
  20. package/src/lib/input-classes.ts +6 -6
  21. package/src/lib/layers.ts +4 -4
  22. package/src/lib/logo-lockup.ts +8 -8
  23. package/src/lib/menu-classes.ts +2 -2
  24. package/src/lib/motion-classes.ts +8 -8
  25. package/src/lib/motion-window.ts +24 -24
  26. package/src/lib/overlay-classes.ts +6 -6
  27. package/src/lib/pill-classes.ts +3 -3
  28. package/src/lib/position-bar-classes.ts +1 -1
  29. package/src/lib/spotlight-geometry.ts +67 -67
  30. package/src/lib/thumb-classes.ts +2 -2
  31. package/src/lib/tier-badge.ts +16 -16
  32. package/src/lib/use-is-mobile.ts +17 -14
  33. package/src/lib/utils.ts +1 -1
  34. package/src/solid/accordion.tsx +41 -41
  35. package/src/solid/alert-dialog.tsx +95 -95
  36. package/src/solid/alert.tsx +88 -88
  37. package/src/solid/area-picker.tsx +204 -204
  38. package/src/solid/aspect-ratio.tsx +13 -13
  39. package/src/solid/avatar.tsx +27 -27
  40. package/src/solid/badge.tsx +49 -49
  41. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  42. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  43. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  44. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  45. package/src/solid/bottom-sheet/index.ts +12 -12
  46. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  47. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  48. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  49. package/src/solid/bottom-sheet/velocity.ts +29 -29
  50. package/src/solid/breadcrumb.tsx +76 -76
  51. package/src/solid/button-group.tsx +46 -46
  52. package/src/solid/button.tsx +19 -19
  53. package/src/solid/card.tsx +67 -67
  54. package/src/solid/carousel.tsx +246 -246
  55. package/src/solid/charts.tsx +253 -253
  56. package/src/solid/checkbox.tsx +51 -51
  57. package/src/solid/collapsible.tsx +22 -22
  58. package/src/solid/color-disc.tsx +213 -213
  59. package/src/solid/color-slider.tsx +81 -81
  60. package/src/solid/color-wheel.tsx +61 -61
  61. package/src/solid/context-menu.tsx +63 -63
  62. package/src/solid/copy-button.tsx +31 -31
  63. package/src/solid/count-pill.tsx +11 -11
  64. package/src/solid/dashboard-preview.tsx +104 -104
  65. package/src/solid/data-table.tsx +228 -228
  66. package/src/solid/dialog-parts.tsx +127 -127
  67. package/src/solid/dialog.tsx +113 -113
  68. package/src/solid/dock-paging.ts +9 -9
  69. package/src/solid/dock.tsx +339 -339
  70. package/src/solid/docked-panel.tsx +35 -35
  71. package/src/solid/dropdown-menu.tsx +77 -77
  72. package/src/solid/empty.tsx +70 -70
  73. package/src/solid/entity-data.ts +38 -38
  74. package/src/solid/entity-selector.tsx +634 -634
  75. package/src/solid/field.tsx +205 -205
  76. package/src/solid/form.tsx +159 -159
  77. package/src/solid/hero-action.tsx +85 -85
  78. package/src/solid/hover-card.tsx +11 -11
  79. package/src/solid/icon-picker.tsx +401 -401
  80. package/src/solid/icon.tsx +101 -78
  81. package/src/solid/image-picker.tsx +416 -414
  82. package/src/solid/index.ts +265 -304
  83. package/src/solid/input-group.tsx +123 -123
  84. package/src/solid/input-otp.tsx +143 -143
  85. package/src/solid/input.tsx +4 -4
  86. package/src/solid/item.tsx +130 -130
  87. package/src/solid/kbd.tsx +20 -20
  88. package/src/solid/label.tsx +12 -12
  89. package/src/solid/list-reorder.ts +122 -122
  90. package/src/solid/logo.tsx +60 -60
  91. package/src/solid/media-copy.ts +21 -21
  92. package/src/solid/media-store.ts +56 -56
  93. package/src/solid/media-tile.tsx +85 -85
  94. package/src/solid/menu-parts.tsx +164 -164
  95. package/src/solid/number-field.tsx +56 -56
  96. package/src/solid/option-card.tsx +164 -164
  97. package/src/solid/ornament.tsx +43 -43
  98. package/src/solid/overlay.tsx +4 -4
  99. package/src/solid/page-header.tsx +75 -75
  100. package/src/solid/pagination.tsx +80 -80
  101. package/src/solid/password-input.tsx +51 -51
  102. package/src/solid/picker-row.tsx +83 -83
  103. package/src/solid/picker-search.tsx +65 -63
  104. package/src/solid/picker-trigger.tsx +59 -57
  105. package/src/solid/popover.tsx +54 -54
  106. package/src/solid/preview-tile.tsx +67 -67
  107. package/src/solid/progress.tsx +21 -21
  108. package/src/solid/radio-group.tsx +51 -51
  109. package/src/solid/resizable.tsx +128 -128
  110. package/src/solid/responsive-dialog.tsx +134 -134
  111. package/src/solid/schema-form.tsx +743 -743
  112. package/src/solid/scope-indicator.tsx +5 -5
  113. package/src/solid/scroll-area.tsx +16 -16
  114. package/src/solid/section-card.tsx +281 -281
  115. package/src/solid/select.tsx +101 -101
  116. package/src/solid/separator.tsx +25 -25
  117. package/src/solid/settings-row.tsx +122 -122
  118. package/src/solid/sheet.tsx +96 -96
  119. package/src/solid/skeleton.tsx +8 -8
  120. package/src/solid/slider.tsx +132 -132
  121. package/src/solid/sliding-indicator.tsx +280 -265
  122. package/src/solid/sonner.tsx +164 -164
  123. package/src/solid/spinner.tsx +12 -12
  124. package/src/solid/spotlight.tsx +140 -140
  125. package/src/solid/step-indicator.tsx +18 -18
  126. package/src/solid/swatch-picker.tsx +38 -38
  127. package/src/solid/switch.tsx +52 -52
  128. package/src/solid/table.tsx +63 -63
  129. package/src/solid/tabs.tsx +93 -93
  130. package/src/solid/textarea.tsx +8 -8
  131. package/src/solid/toggle-group.tsx +83 -83
  132. package/src/solid/toggle.tsx +33 -33
  133. package/src/solid/tooltip.tsx +16 -16
  134. package/src/solid/widget-card.tsx +90 -90
  135. package/src/solid/widget-identity.tsx +99 -99
  136. package/src/solid/widget-trust-badge.tsx +20 -20
  137. package/src/styles/globals.css +316 -319
  138. package/src/styles/theme.css +448 -448
  139. package/src/tokens/hex.ts +29 -29
  140. package/src/tokens/material.ts +75 -75
  141. package/src/tokens/presets.ts +303 -303
  142. package/src/tokens/readability.ts +32 -32
  143. package/src/tokens/theme-colors.ts +95 -95
  144. package/src/tokens/theme-css.ts +22 -22
  145. package/src/tokens/theme-recipe.ts +106 -106
@@ -7,64 +7,64 @@ import { Icon } from "./icon.js";
7
7
  /* Two box sizes and the glyph that fits each: `sm` is the row-embedded control
8
8
  * (picker rows, dense lists), `default` the touch target of a standalone one. */
9
9
  const CHECKBOX_SIZE = {
10
- sm: { box: "size-5", glyph: "size-3.5", px: 14 },
11
- default: { box: "size-7", glyph: "size-5", px: 20 },
10
+ sm: { box: "size-5", glyph: "size-3.5", px: 14 },
11
+ default: { box: "size-7", glyph: "size-5", px: 20 },
12
12
  } as const;
13
13
 
14
14
  type CheckboxSize = keyof typeof CHECKBOX_SIZE;
15
15
 
16
16
  const Checkbox: Component<ComponentProps<typeof CheckboxPrimitive> & { size?: CheckboxSize }> = (
17
- props,
17
+ props,
18
18
  ) => {
19
- const [local, others] = splitProps(props, ["class", "children", "size"]);
20
- const label = () => local.children as JSX.Element;
21
- const size = () => CHECKBOX_SIZE[local.size ?? "default"];
22
- return (
23
- <CheckboxPrimitive data-slot="checkbox" {...others}>
24
- {/* One <label> row: the box is a plain span, not a Kobalte Control, so a
19
+ const [local, others] = splitProps(props, ["class", "children", "size"]);
20
+ const label = () => local.children as JSX.Element;
21
+ const size = () => CHECKBOX_SIZE[local.size ?? "default"];
22
+ return (
23
+ <CheckboxPrimitive data-slot="checkbox" {...others}>
24
+ {/* One <label> row: the box is a plain span, not a Kobalte Control, so a
25
25
  click anywhere toggles exactly once. */}
26
- {(state) => (
27
- <CheckboxPrimitive.Label
28
- data-slot="checkbox-label"
29
- class="group inline-flex cursor-pointer select-none items-center gap-2.5 data-[disabled]:cursor-not-allowed"
30
- >
31
- <CheckboxPrimitive.Input class="peer" />
32
- <span
33
- aria-hidden="true"
34
- data-slot="checkbox-box"
35
- data-size={local.size ?? "default"}
36
- class={cn(
37
- "box-border inline-flex shrink-0 items-center justify-center overflow-hidden rounded-xs transition-glass duration-200 ease-out group-active:scale-90",
38
- size().box,
39
- "peer-focus-visible:ring-[3px] peer-focus-visible:ring-ring/50 peer-focus-visible:[--glass-edge:var(--ring)]",
40
- state.checked()
41
- ? "glass glass-tint text-foreground [--glass-tone:var(--primary)]"
42
- : FIELD_CHROME,
43
- props.disabled && "cursor-not-allowed opacity-40",
44
- local.class,
45
- )}
46
- >
47
- {/* Always mounted so the box keeps constant height. */}
48
- <Icon
49
- icon="lucide:check"
50
- width={size().px}
51
- height={size().px}
52
- class={cn(
53
- size().glyph,
54
- "transition-glass duration-200 ease-out",
55
- state.checked() ? "scale-100 opacity-100" : "scale-0 opacity-0",
56
- )}
57
- />
58
- </span>
59
- {local.children && (
60
- <span data-slot="checkbox-text" class="text-sm leading-none">
61
- {label()}
62
- </span>
63
- )}
64
- </CheckboxPrimitive.Label>
65
- )}
66
- </CheckboxPrimitive>
67
- );
26
+ {(state) => (
27
+ <CheckboxPrimitive.Label
28
+ data-slot="checkbox-label"
29
+ class="group inline-flex cursor-pointer items-center gap-2.5 select-none data-[disabled]:cursor-not-allowed"
30
+ >
31
+ <CheckboxPrimitive.Input class="peer" />
32
+ <span
33
+ aria-hidden="true"
34
+ data-slot="checkbox-box"
35
+ data-size={local.size ?? "default"}
36
+ class={cn(
37
+ "transition-glass box-border inline-flex shrink-0 items-center justify-center overflow-hidden rounded-xs duration-200 ease-out group-active:scale-90",
38
+ size().box,
39
+ "peer-focus-visible:ring-ring/50 peer-focus-visible:ring-[3px] peer-focus-visible:[--glass-edge:var(--ring)]",
40
+ state.checked()
41
+ ? "glass glass-tint text-foreground [--glass-tone:var(--primary)]"
42
+ : FIELD_CHROME,
43
+ props.disabled && "cursor-not-allowed opacity-40",
44
+ local.class,
45
+ )}
46
+ >
47
+ {/* Always mounted so the box keeps constant height. */}
48
+ <Icon
49
+ icon="lucide:check"
50
+ width={size().px}
51
+ height={size().px}
52
+ class={cn(
53
+ size().glyph,
54
+ "transition-glass duration-200 ease-out",
55
+ state.checked() ? "scale-100 opacity-100" : "scale-0 opacity-0",
56
+ )}
57
+ />
58
+ </span>
59
+ {local.children && (
60
+ <span data-slot="checkbox-text" class="text-sm leading-none">
61
+ {label()}
62
+ </span>
63
+ )}
64
+ </CheckboxPrimitive.Label>
65
+ )}
66
+ </CheckboxPrimitive>
67
+ );
68
68
  };
69
69
 
70
70
  export { Checkbox };
@@ -3,36 +3,36 @@ import { type Component, type ComponentProps, splitProps } from "solid-js";
3
3
  import { cn } from "../lib/utils.js";
4
4
 
5
5
  const Collapsible: Component<ComponentProps<typeof CollapsiblePrimitive>> = (props) => {
6
- return <CollapsiblePrimitive data-slot="collapsible" {...props} />;
6
+ return <CollapsiblePrimitive data-slot="collapsible" {...props} />;
7
7
  };
8
8
 
9
9
  const CollapsibleTrigger: Component<ComponentProps<typeof CollapsiblePrimitive.Trigger>> = (
10
- props,
10
+ props,
11
11
  ) => {
12
- const [local, rest] = splitProps(props, ["class"]);
13
- return (
14
- <CollapsiblePrimitive.Trigger
15
- data-slot="collapsible-trigger"
16
- class={cn("cursor-pointer py-3", local.class)}
17
- {...rest}
18
- />
19
- );
12
+ const [local, rest] = splitProps(props, ["class"]);
13
+ return (
14
+ <CollapsiblePrimitive.Trigger
15
+ data-slot="collapsible-trigger"
16
+ class={cn("cursor-pointer py-3", local.class)}
17
+ {...rest}
18
+ />
19
+ );
20
20
  };
21
21
 
22
22
  const CollapsibleContent: Component<ComponentProps<typeof CollapsiblePrimitive.Content>> = (
23
- props,
23
+ props,
24
24
  ) => {
25
- const [local, rest] = splitProps(props, ["class"]);
26
- return (
27
- <CollapsiblePrimitive.Content
28
- data-slot="collapsible-content"
29
- class={cn(
30
- "overflow-hidden data-closed:animate-collapsible-up data-expanded:animate-collapsible-down",
31
- local.class,
32
- )}
33
- {...rest}
34
- />
35
- );
25
+ const [local, rest] = splitProps(props, ["class"]);
26
+ return (
27
+ <CollapsiblePrimitive.Content
28
+ data-slot="collapsible-content"
29
+ class={cn(
30
+ "data-closed:animate-collapsible-up data-expanded:animate-collapsible-down overflow-hidden",
31
+ local.class,
32
+ )}
33
+ {...rest}
34
+ />
35
+ );
36
36
  };
37
37
 
38
38
  export { Collapsible, CollapsibleContent, CollapsibleTrigger };
@@ -14,240 +14,240 @@ const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v
14
14
 
15
15
  /* Hue 0 at three o'clock, turning clockwise, the direction the conic gradient paints. */
16
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%))";
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
18
 
19
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;
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
29
  }
30
30
 
31
31
  /**
32
32
  * A colour disc: hue around it, saturation from the white centre to the rim, one thumb for both.
33
33
  */
34
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
- };
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
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
- };
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
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
- );
80
+ return (
81
+ <div
82
+ data-slot="color-disc"
83
+ class={cn(
84
+ "relative touch-none rounded-full select-none",
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
142
  };
143
143
 
144
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;
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
154
  }
155
155
 
156
156
  /** Kelvin to a display colour, for the bar's paint only. */
157
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")})`;
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
166
  }
167
167
 
168
168
  /** Warm to cool white on one bar, in Kelvin, over the span the lamps can reach. */
169
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
- );
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 rounded-full select-none",
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
251
  };
252
252
 
253
253
  export { ColorDisc, TemperatureBar };