@glasshome/ui 1.21.1 → 1.22.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 (146) 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/solid/sonner.d.ts +1 -0
  7. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  8. package/package.json +128 -126
  9. package/scripts/check-gallery.ts +142 -142
  10. package/scripts/check-pack.ts +13 -13
  11. package/scripts/check-structural-classes.ts +20 -20
  12. package/scripts/check-tokens.ts +27 -27
  13. package/scripts/check-ui-drift.mjs +103 -103
  14. package/src/index.ts +75 -80
  15. package/src/lib/alert-tones.ts +41 -41
  16. package/src/lib/anchor-placement.ts +21 -21
  17. package/src/lib/button-variants.ts +28 -28
  18. package/src/lib/card-classes.ts +9 -9
  19. package/src/lib/carousel-classes.ts +14 -14
  20. package/src/lib/glass-tone.ts +11 -11
  21. package/src/lib/input-classes.ts +6 -6
  22. package/src/lib/layers.ts +4 -4
  23. package/src/lib/logo-lockup.ts +8 -8
  24. package/src/lib/menu-classes.ts +2 -2
  25. package/src/lib/motion-classes.ts +8 -8
  26. package/src/lib/motion-window.ts +24 -24
  27. package/src/lib/overlay-classes.ts +6 -6
  28. package/src/lib/pill-classes.ts +3 -3
  29. package/src/lib/position-bar-classes.ts +1 -1
  30. package/src/lib/spotlight-geometry.ts +67 -67
  31. package/src/lib/thumb-classes.ts +2 -2
  32. package/src/lib/tier-badge.ts +16 -16
  33. package/src/lib/use-is-mobile.ts +17 -14
  34. package/src/lib/utils.ts +1 -1
  35. package/src/solid/accordion.tsx +41 -41
  36. package/src/solid/alert-dialog.tsx +95 -95
  37. package/src/solid/alert.tsx +88 -88
  38. package/src/solid/area-picker.tsx +204 -204
  39. package/src/solid/aspect-ratio.tsx +13 -13
  40. package/src/solid/avatar.tsx +27 -27
  41. package/src/solid/badge.tsx +49 -49
  42. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  43. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  44. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  45. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  46. package/src/solid/bottom-sheet/index.ts +12 -12
  47. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  48. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  49. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  50. package/src/solid/bottom-sheet/velocity.ts +29 -29
  51. package/src/solid/breadcrumb.tsx +76 -76
  52. package/src/solid/button-group.tsx +46 -46
  53. package/src/solid/button.tsx +19 -19
  54. package/src/solid/card.tsx +67 -67
  55. package/src/solid/carousel.tsx +246 -246
  56. package/src/solid/charts.tsx +253 -253
  57. package/src/solid/checkbox.tsx +51 -51
  58. package/src/solid/collapsible.tsx +22 -22
  59. package/src/solid/color-disc.tsx +213 -213
  60. package/src/solid/color-slider.tsx +81 -81
  61. package/src/solid/color-wheel.tsx +61 -61
  62. package/src/solid/context-menu.tsx +63 -63
  63. package/src/solid/copy-button.tsx +31 -31
  64. package/src/solid/count-pill.tsx +11 -11
  65. package/src/solid/dashboard-preview.tsx +104 -104
  66. package/src/solid/data-table.tsx +228 -228
  67. package/src/solid/dialog-parts.tsx +127 -127
  68. package/src/solid/dialog.tsx +113 -113
  69. package/src/solid/dock-paging.ts +9 -9
  70. package/src/solid/dock.tsx +339 -339
  71. package/src/solid/docked-panel.tsx +35 -35
  72. package/src/solid/dropdown-menu.tsx +77 -77
  73. package/src/solid/empty.tsx +70 -70
  74. package/src/solid/entity-data.ts +38 -38
  75. package/src/solid/entity-selector.tsx +634 -634
  76. package/src/solid/field.tsx +205 -205
  77. package/src/solid/form.tsx +159 -159
  78. package/src/solid/hero-action.tsx +85 -85
  79. package/src/solid/hover-card.tsx +11 -11
  80. package/src/solid/icon-picker.tsx +401 -401
  81. package/src/solid/icon.tsx +101 -78
  82. package/src/solid/image-picker.tsx +416 -414
  83. package/src/solid/index.ts +265 -304
  84. package/src/solid/input-group.tsx +123 -123
  85. package/src/solid/input-otp.tsx +143 -143
  86. package/src/solid/input.tsx +4 -4
  87. package/src/solid/item.tsx +130 -130
  88. package/src/solid/kbd.tsx +20 -20
  89. package/src/solid/label.tsx +12 -12
  90. package/src/solid/list-reorder.ts +122 -122
  91. package/src/solid/logo.tsx +60 -60
  92. package/src/solid/media-copy.ts +21 -21
  93. package/src/solid/media-store.ts +56 -56
  94. package/src/solid/media-tile.tsx +85 -85
  95. package/src/solid/menu-parts.tsx +164 -164
  96. package/src/solid/number-field.tsx +56 -56
  97. package/src/solid/option-card.tsx +164 -164
  98. package/src/solid/ornament.tsx +43 -43
  99. package/src/solid/overlay.tsx +4 -4
  100. package/src/solid/page-header.tsx +75 -75
  101. package/src/solid/pagination.tsx +80 -80
  102. package/src/solid/password-input.tsx +51 -51
  103. package/src/solid/picker-row.tsx +83 -83
  104. package/src/solid/picker-search.tsx +65 -63
  105. package/src/solid/picker-trigger.tsx +59 -57
  106. package/src/solid/popover.tsx +54 -54
  107. package/src/solid/preview-tile.tsx +67 -67
  108. package/src/solid/progress.tsx +21 -21
  109. package/src/solid/radio-group.tsx +51 -51
  110. package/src/solid/resizable.tsx +128 -128
  111. package/src/solid/responsive-dialog.tsx +134 -134
  112. package/src/solid/schema-form.tsx +743 -743
  113. package/src/solid/scope-indicator.tsx +5 -5
  114. package/src/solid/scroll-area.tsx +16 -16
  115. package/src/solid/section-card.tsx +281 -281
  116. package/src/solid/select.tsx +101 -101
  117. package/src/solid/separator.tsx +25 -25
  118. package/src/solid/settings-row.tsx +122 -122
  119. package/src/solid/sheet.tsx +96 -96
  120. package/src/solid/skeleton.tsx +8 -8
  121. package/src/solid/slider.tsx +132 -132
  122. package/src/solid/sliding-indicator.tsx +280 -265
  123. package/src/solid/sonner.tsx +165 -164
  124. package/src/solid/spinner.tsx +12 -12
  125. package/src/solid/spotlight.tsx +140 -140
  126. package/src/solid/step-indicator.tsx +18 -18
  127. package/src/solid/swatch-picker.tsx +38 -38
  128. package/src/solid/switch.tsx +52 -52
  129. package/src/solid/table.tsx +63 -63
  130. package/src/solid/tabs.tsx +93 -93
  131. package/src/solid/textarea.tsx +8 -8
  132. package/src/solid/toggle-group.tsx +83 -83
  133. package/src/solid/toggle.tsx +33 -33
  134. package/src/solid/tooltip.tsx +16 -16
  135. package/src/solid/widget-card.tsx +90 -90
  136. package/src/solid/widget-identity.tsx +99 -99
  137. package/src/solid/widget-trust-badge.tsx +20 -20
  138. package/src/styles/globals.css +316 -319
  139. package/src/styles/theme.css +448 -448
  140. package/src/tokens/hex.ts +29 -29
  141. package/src/tokens/material.ts +75 -75
  142. package/src/tokens/presets.ts +303 -303
  143. package/src/tokens/readability.ts +32 -32
  144. package/src/tokens/theme-colors.ts +95 -95
  145. package/src/tokens/theme-css.ts +22 -22
  146. package/src/tokens/theme-recipe.ts +106 -106
@@ -1,11 +1,11 @@
1
1
  import {
2
- type Component,
3
- createEffect,
4
- createSignal,
5
- type JSX,
6
- onCleanup,
7
- onMount,
8
- Show,
2
+ type Component,
3
+ createEffect,
4
+ createSignal,
5
+ type JSX,
6
+ onCleanup,
7
+ onMount,
8
+ Show,
9
9
  } from "solid-js";
10
10
  import { Portal } from "solid-js/web";
11
11
  import { Z_CLASS } from "../lib/layers.js";
@@ -24,156 +24,156 @@ const BUBBLE_DEFAULT_WIDTH = 384;
24
24
  const BUBBLE_GAP_WITH_TAIL = BUBBLE_GAP + (TAIL_SIZE * Math.SQRT2) / 2;
25
25
 
26
26
  interface SpotlightProps {
27
- target: Element | undefined;
28
- /** What the bubble is placed against and the tail points at. Defaults to `target`. */
29
- anchor?: Element;
30
- scrim: boolean;
31
- blocking?: boolean;
32
- pad?: number;
33
- onSkip?: () => void;
34
- class?: string;
35
- children: JSX.Element;
27
+ target: Element | undefined;
28
+ /** What the bubble is placed against and the tail points at. Defaults to `target`. */
29
+ anchor?: Element;
30
+ scrim: boolean;
31
+ blocking?: boolean;
32
+ pad?: number;
33
+ onSkip?: () => void;
34
+ class?: string;
35
+ children: JSX.Element;
36
36
  }
37
37
 
38
38
  /* Field-by-field so an unchanged measure (same numbers, new object) writes nothing. */
39
39
  function sameFields<T extends object>(a: T | null, b: T | null): boolean {
40
- if (a === b) return true;
41
- if (!a || !b) return false;
42
- return (Object.keys(a) as (keyof T)[]).every((key) => a[key] === b[key]);
40
+ if (a === b) return true;
41
+ if (!a || !b) return false;
42
+ return (Object.keys(a) as (keyof T)[]).every((key) => a[key] === b[key]);
43
43
  }
44
44
 
45
45
  const Spotlight: Component<SpotlightProps> = (props) => {
46
- const [box, setBox] = createSignal<Box | null>(null, { equals: sameFields });
47
- const [anchorBox, setAnchorBox] = createSignal<Box | null>(null, { equals: sameFields });
48
- const [viewport, setViewport] = createSignal(
49
- { width: window.innerWidth, height: window.innerHeight },
50
- { equals: sameFields },
51
- );
52
- const [bubbleSize, setBubbleSize] = createSignal(
53
- { width: BUBBLE_DEFAULT_WIDTH, height: 96 },
54
- { equals: sameFields },
55
- );
56
- let bubble: HTMLDivElement | undefined;
46
+ const [box, setBox] = createSignal<Box | null>(null, { equals: sameFields });
47
+ const [anchorBox, setAnchorBox] = createSignal<Box | null>(null, { equals: sameFields });
48
+ const [viewport, setViewport] = createSignal(
49
+ { width: window.innerWidth, height: window.innerHeight },
50
+ { equals: sameFields },
51
+ );
52
+ const [bubbleSize, setBubbleSize] = createSignal(
53
+ { width: BUBBLE_DEFAULT_WIDTH, height: 96 },
54
+ { equals: sameFields },
55
+ );
56
+ let bubble: HTMLDivElement | undefined;
57
57
 
58
- const anchorEl = () => props.anchor ?? props.target;
58
+ const anchorEl = () => props.anchor ?? props.target;
59
59
 
60
- const rectToBox = (el: Element | undefined) => {
61
- const r = el?.getBoundingClientRect();
62
- return r ? { x: r.left, y: r.top, width: r.width, height: r.height } : null;
63
- };
60
+ const rectToBox = (el: Element | undefined) => {
61
+ const r = el?.getBoundingClientRect();
62
+ return r ? { x: r.left, y: r.top, width: r.width, height: r.height } : null;
63
+ };
64
64
 
65
- const measure = () => {
66
- setViewport({ width: window.innerWidth, height: window.innerHeight });
67
- const targetBox = rectToBox(props.target);
68
- setBox(targetBox);
69
- const anchor = anchorEl();
70
- /* Same element as target: reuse its box instead of measuring it twice a tick. */
71
- setAnchorBox(anchor === props.target ? targetBox : rectToBox(anchor));
72
- if (bubble)
73
- setBubbleSize({
74
- width: bubble.offsetWidth || BUBBLE_DEFAULT_WIDTH,
75
- height: bubble.offsetHeight || 96,
76
- });
77
- };
65
+ const measure = () => {
66
+ setViewport({ width: window.innerWidth, height: window.innerHeight });
67
+ const targetBox = rectToBox(props.target);
68
+ setBox(targetBox);
69
+ const anchor = anchorEl();
70
+ /* Same element as target: reuse its box instead of measuring it twice a tick. */
71
+ setAnchorBox(anchor === props.target ? targetBox : rectToBox(anchor));
72
+ if (bubble)
73
+ setBubbleSize({
74
+ width: bubble.offsetWidth || BUBBLE_DEFAULT_WIDTH,
75
+ height: bubble.offsetHeight || 96,
76
+ });
77
+ };
78
78
 
79
- createEffect(() => {
80
- const target = props.target;
81
- const anchor = anchorEl();
82
- let raf = 0;
83
- let start: number | undefined;
79
+ createEffect(() => {
80
+ const target = props.target;
81
+ const anchor = anchorEl();
82
+ let raf = 0;
83
+ let start: number | undefined;
84
84
 
85
- /* A transform-animating target never fires ResizeObserver, and its motion may
86
- * start a few frames late, so sample the whole window instead of stopping early. */
87
- const tick = (time: number) => {
88
- start ??= time;
89
- measure();
90
- if (time - start < 600) raf = requestAnimationFrame(tick);
91
- };
85
+ /* A transform-animating target never fires ResizeObserver, and its motion may
86
+ * start a few frames late, so sample the whole window instead of stopping early. */
87
+ const tick = (time: number) => {
88
+ start ??= time;
89
+ measure();
90
+ if (time - start < 600) raf = requestAnimationFrame(tick);
91
+ };
92
92
 
93
- measure();
94
- raf = requestAnimationFrame(tick);
93
+ measure();
94
+ raf = requestAnimationFrame(tick);
95
95
 
96
- const observer = new ResizeObserver(measure);
97
- if (target) observer.observe(target);
98
- if (anchor && anchor !== target) observer.observe(anchor);
99
- if (bubble) observer.observe(bubble);
100
- onCleanup(() => {
101
- cancelAnimationFrame(raf);
102
- observer.disconnect();
103
- });
104
- });
96
+ const observer = new ResizeObserver(measure);
97
+ if (target) observer.observe(target);
98
+ if (anchor && anchor !== target) observer.observe(anchor);
99
+ if (bubble) observer.observe(bubble);
100
+ onCleanup(() => {
101
+ cancelAnimationFrame(raf);
102
+ observer.disconnect();
103
+ });
104
+ });
105
105
 
106
- onMount(() => {
107
- const onKey = (e: KeyboardEvent) => {
108
- if (e.key === "Escape") props.onSkip?.();
109
- };
110
- window.addEventListener("resize", measure);
111
- window.addEventListener("scroll", measure, { capture: true, passive: true });
112
- document.addEventListener("keydown", onKey);
113
- onCleanup(() => {
114
- window.removeEventListener("resize", measure);
115
- window.removeEventListener("scroll", measure, { capture: true });
116
- document.removeEventListener("keydown", onKey);
117
- });
118
- });
106
+ onMount(() => {
107
+ const onKey = (e: KeyboardEvent) => {
108
+ if (e.key === "Escape") props.onSkip?.();
109
+ };
110
+ window.addEventListener("resize", measure);
111
+ window.addEventListener("scroll", measure, { capture: true, passive: true });
112
+ document.addEventListener("keydown", onKey);
113
+ onCleanup(() => {
114
+ window.removeEventListener("resize", measure);
115
+ window.removeEventListener("scroll", measure, { capture: true });
116
+ document.removeEventListener("keydown", onKey);
117
+ });
118
+ });
119
119
 
120
- const place = () =>
121
- placeBubble(viewport(), anchorBox(), bubbleSize(), BUBBLE_GAP_WITH_TAIL, VIEWPORT_MARGIN);
120
+ const place = () =>
121
+ placeBubble(viewport(), anchorBox(), bubbleSize(), BUBBLE_GAP_WITH_TAIL, VIEWPORT_MARGIN);
122
122
 
123
- return (
124
- <Portal>
125
- <Show when={props.scrim}>
126
- <div
127
- data-slot="spotlight-scrim"
128
- data-expanded=""
129
- aria-hidden="true"
130
- class={cn(
131
- "fixed inset-0",
132
- SCRIM_CLASS,
133
- Z_CLASS.overlay,
134
- SCRIM_MOTION,
135
- TRAVEL_MOTION,
136
- !box() && !props.blocking && "pointer-events-none",
137
- )}
138
- style={{
139
- "clip-path": `path(evenodd, "${holePath(viewport(), box(), props.pad ?? HOLE_PAD, HOLE_RADIUS)}")`,
140
- }}
141
- />
142
- </Show>
143
- <div
144
- ref={bubble}
145
- data-slot="spotlight-bubble"
146
- data-side={place().side}
147
- class={cn(TRAVEL_MOTION, Z_CLASS.overlay, "fixed top-0 left-0 w-96", props.class)}
148
- style={{ translate: `${place().x}px ${place().y}px` }}
149
- >
150
- <Show when={place().tail}>
151
- {(tail) => (
152
- <div
153
- data-slot="spotlight-tail"
154
- data-side={place().side}
155
- aria-hidden="true"
156
- class={cn(OVERLAY_SURFACE_OPAQUE, "absolute rotate-45 rounded-[2px]")}
157
- style={{
158
- width: `${TAIL_SIZE}px`,
159
- height: `${TAIL_SIZE}px`,
160
- left: `${tail().x - TAIL_SIZE / 2}px`,
161
- ...(place().side === "above"
162
- ? { bottom: `${-TAIL_SIZE / 2}px` }
163
- : { top: `${-TAIL_SIZE / 2}px` }),
164
- }}
165
- />
166
- )}
167
- </Show>
168
- <div
169
- data-slot="spotlight-panel"
170
- class={cn(OVERLAY_SURFACE_OPAQUE, PANEL_TAIL, "relative z-auto p-4")}
171
- >
172
- {props.children}
173
- </div>
174
- </div>
175
- </Portal>
176
- );
123
+ return (
124
+ <Portal>
125
+ <Show when={props.scrim}>
126
+ <div
127
+ data-slot="spotlight-scrim"
128
+ data-expanded=""
129
+ aria-hidden="true"
130
+ class={cn(
131
+ "fixed inset-0",
132
+ SCRIM_CLASS,
133
+ Z_CLASS.overlay,
134
+ SCRIM_MOTION,
135
+ TRAVEL_MOTION,
136
+ !box() && !props.blocking && "pointer-events-none",
137
+ )}
138
+ style={{
139
+ "clip-path": `path(evenodd, "${holePath(viewport(), box(), props.pad ?? HOLE_PAD, HOLE_RADIUS)}")`,
140
+ }}
141
+ />
142
+ </Show>
143
+ <div
144
+ ref={bubble}
145
+ data-slot="spotlight-bubble"
146
+ data-side={place().side}
147
+ class={cn(TRAVEL_MOTION, Z_CLASS.overlay, "fixed top-0 left-0 w-96", props.class)}
148
+ style={{ translate: `${place().x}px ${place().y}px` }}
149
+ >
150
+ <Show when={place().tail}>
151
+ {(tail) => (
152
+ <div
153
+ data-slot="spotlight-tail"
154
+ data-side={place().side}
155
+ aria-hidden="true"
156
+ class={cn(OVERLAY_SURFACE_OPAQUE, "absolute rotate-45 rounded-[2px]")}
157
+ style={{
158
+ width: `${TAIL_SIZE}px`,
159
+ height: `${TAIL_SIZE}px`,
160
+ left: `${tail().x - TAIL_SIZE / 2}px`,
161
+ ...(place().side === "above"
162
+ ? { bottom: `${-TAIL_SIZE / 2}px` }
163
+ : { top: `${-TAIL_SIZE / 2}px` }),
164
+ }}
165
+ />
166
+ )}
167
+ </Show>
168
+ <div
169
+ data-slot="spotlight-panel"
170
+ class={cn(OVERLAY_SURFACE_OPAQUE, PANEL_TAIL, "relative z-auto p-4")}
171
+ >
172
+ {props.children}
173
+ </div>
174
+ </div>
175
+ </Portal>
176
+ );
177
177
  };
178
178
 
179
179
  export { Spotlight };
@@ -8,23 +8,23 @@ import { cn } from "../lib/utils.js";
8
8
  * the only place the position is readable.
9
9
  */
10
10
  export function StepIndicator(props: { count: number; index: number; class?: string }) {
11
- const steps = () => Array.from({ length: Math.max(props.count, 0) }, (_, step) => step);
11
+ const steps = () => Array.from({ length: Math.max(props.count, 0) }, (_, step) => step);
12
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
- );
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
30
  }
@@ -5,43 +5,43 @@ import { RadioGroup, RadioGroupItem } from "./radio-group.js";
5
5
 
6
6
  /** One colour out of a few, as swatches sharing one row; `children` is the custom slot at the end (a picker). */
7
7
  export function SwatchPicker(props: {
8
- value: string | null;
9
- colors: readonly string[];
10
- onChange: (color: string) => void;
11
- "aria-label": string;
12
- /** Names each swatch for assistive tech. */
13
- labelOf?: (color: string, index: number) => string;
14
- class?: string;
15
- children?: JSX.Element;
8
+ value: string | null;
9
+ colors: readonly string[];
10
+ onChange: (color: string) => void;
11
+ "aria-label": string;
12
+ /** Names each swatch for assistive tech. */
13
+ labelOf?: (color: string, index: number) => string;
14
+ class?: string;
15
+ children?: JSX.Element;
16
16
  }) {
17
- return (
18
- <RadioGroup
19
- data-slot="swatch-picker"
20
- class={cn("grid auto-cols-fr grid-flow-col items-center gap-2", props.class)}
21
- value={props.value ?? ""}
22
- onChange={props.onChange}
23
- aria-label={props["aria-label"]}
24
- >
25
- <For each={props.colors}>
26
- {(color, index) => (
27
- <RadioGroupItem
28
- data-slot="swatch-picker-item"
29
- value={color}
30
- showControl={false}
31
- class="group/swatch"
32
- >
33
- <span
34
- data-slot="swatch-picker-swatch"
35
- class="block aspect-square w-full max-w-9 rounded-full border border-foreground/15 transition-glass duration-200 group-active/swatch:scale-90 group-has-[:focus-visible]/swatch:ring-[3px] group-has-[:focus-visible]/swatch:ring-ring/50 group-data-[checked]/swatch:ring-2 group-data-[checked]/swatch:ring-foreground group-data-[checked]/swatch:ring-offset-2 group-data-[checked]/swatch:ring-offset-transparent"
36
- style={{ background: color }}
37
- />
38
- <span class="sr-only">
39
- {props.labelOf?.(color, index()) ?? `Colour ${index() + 1}`}
40
- </span>
41
- </RadioGroupItem>
42
- )}
43
- </For>
44
- {props.children}
45
- </RadioGroup>
46
- );
17
+ return (
18
+ <RadioGroup
19
+ data-slot="swatch-picker"
20
+ class={cn("grid auto-cols-fr grid-flow-col items-center gap-2", props.class)}
21
+ value={props.value ?? ""}
22
+ onChange={props.onChange}
23
+ aria-label={props["aria-label"]}
24
+ >
25
+ <For each={props.colors}>
26
+ {(color, index) => (
27
+ <RadioGroupItem
28
+ data-slot="swatch-picker-item"
29
+ value={color}
30
+ showControl={false}
31
+ class="group/swatch"
32
+ >
33
+ <span
34
+ data-slot="swatch-picker-swatch"
35
+ class="border-foreground/15 transition-glass group-has-[:focus-visible]/swatch:ring-ring/50 group-data-[checked]/swatch:ring-foreground block aspect-square w-full max-w-9 rounded-full border duration-200 group-active/swatch:scale-90 group-has-[:focus-visible]/swatch:ring-[3px] group-data-[checked]/swatch:ring-2 group-data-[checked]/swatch:ring-offset-2 group-data-[checked]/swatch:ring-offset-transparent"
36
+ style={{ background: color }}
37
+ />
38
+ <span class="sr-only">
39
+ {props.labelOf?.(color, index()) ?? `Colour ${index() + 1}`}
40
+ </span>
41
+ </RadioGroupItem>
42
+ )}
43
+ </For>
44
+ {props.children}
45
+ </RadioGroup>
46
+ );
47
47
  }
@@ -4,62 +4,62 @@ import { THUMB_CLASS, THUMB_FACE_ON } from "../lib/thumb-classes.js";
4
4
  import { cn } from "../lib/utils.js";
5
5
 
6
6
  type SwitchProps = Omit<ComponentProps<"button">, "onChange" | "children"> & {
7
- checked?: boolean;
8
- defaultChecked?: boolean;
9
- onChange?: (checked: boolean) => void;
7
+ checked?: boolean;
8
+ defaultChecked?: boolean;
9
+ onChange?: (checked: boolean) => void;
10
10
  };
11
11
 
12
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();
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
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={{
56
- "--thumb-face-on": THUMB_FACE_ON,
57
- background: checked() ? "var(--thumb-face-on)" : "var(--thumb-face-off)",
58
- }}
59
- />
60
- {local.name && <input type="hidden" name={local.name} value={checked() ? "on" : "off"} />}
61
- </button>
62
- );
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 transition-glass relative inline-flex h-7 w-14 shrink-0 cursor-pointer items-center rounded-xl 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={{
56
+ "--thumb-face-on": THUMB_FACE_ON,
57
+ background: checked() ? "var(--thumb-face-on)" : "var(--thumb-face-off)",
58
+ }}
59
+ />
60
+ {local.name && <input type="hidden" name={local.name} value={checked() ? "on" : "off"} />}
61
+ </button>
62
+ );
63
63
  };
64
64
 
65
65
  export { Switch };