@glasshome/ui 1.21.0 → 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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/use-is-mobile.d.ts +3 -1
- package/dist/solid/alert-dialog.d.ts +7 -1
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +7 -1
- package/dist/solid/dialog-parts.d.ts +3 -2
- package/dist/solid/dialog.d.ts +7 -1
- package/dist/solid/docked-panel.d.ts +7 -1
- package/dist/solid/index.d.ts +9 -9
- package/dist/solid/index.js +5456 -5447
- package/dist/solid/media-store.d.ts +4 -1
- package/dist/solid/option-card.d.ts +4 -1
- package/dist/solid/responsive-dialog.d.ts +7 -1
- package/dist/solid/sheet.d.ts +7 -1
- package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
- package/package.json +128 -126
- package/scripts/check-gallery.ts +142 -142
- package/scripts/check-pack.ts +13 -13
- package/scripts/check-structural-classes.ts +20 -20
- package/scripts/check-tokens.ts +27 -27
- package/scripts/check-ui-drift.mjs +103 -103
- package/src/index.ts +75 -80
- package/src/lib/alert-tones.ts +41 -41
- package/src/lib/anchor-placement.ts +21 -21
- package/src/lib/button-variants.ts +28 -28
- package/src/lib/card-classes.ts +9 -9
- package/src/lib/carousel-classes.ts +14 -14
- package/src/lib/glass-tone.ts +11 -11
- package/src/lib/input-classes.ts +6 -6
- package/src/lib/layers.ts +4 -4
- package/src/lib/logo-lockup.ts +8 -8
- package/src/lib/menu-classes.ts +2 -2
- package/src/lib/motion-classes.ts +8 -8
- package/src/lib/motion-window.ts +24 -24
- package/src/lib/overlay-classes.ts +6 -6
- package/src/lib/pill-classes.ts +3 -3
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/spotlight-geometry.ts +67 -67
- package/src/lib/thumb-classes.ts +2 -2
- package/src/lib/tier-badge.ts +16 -16
- package/src/lib/use-is-mobile.ts +17 -14
- package/src/lib/utils.ts +1 -1
- package/src/solid/accordion.tsx +41 -41
- package/src/solid/alert-dialog.tsx +95 -95
- package/src/solid/alert.tsx +88 -88
- package/src/solid/area-picker.tsx +204 -204
- package/src/solid/aspect-ratio.tsx +13 -13
- package/src/solid/avatar.tsx +27 -27
- package/src/solid/badge.tsx +49 -49
- package/src/solid/bottom-sheet/arbitration.ts +22 -22
- package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
- package/src/solid/bottom-sheet/drag-controller.ts +201 -201
- package/src/solid/bottom-sheet/focus-trap.ts +51 -47
- package/src/solid/bottom-sheet/index.ts +12 -12
- package/src/solid/bottom-sheet/keyboard.ts +25 -25
- package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
- package/src/solid/bottom-sheet/state-machine.ts +28 -28
- package/src/solid/bottom-sheet/velocity.ts +29 -29
- package/src/solid/breadcrumb.tsx +76 -76
- package/src/solid/button-group.tsx +46 -46
- package/src/solid/button.tsx +19 -19
- package/src/solid/card.tsx +67 -67
- package/src/solid/carousel.tsx +246 -246
- package/src/solid/charts.tsx +253 -253
- package/src/solid/checkbox.tsx +51 -51
- package/src/solid/collapsible.tsx +22 -22
- package/src/solid/color-disc.tsx +213 -213
- package/src/solid/color-slider.tsx +81 -81
- package/src/solid/color-wheel.tsx +61 -61
- package/src/solid/context-menu.tsx +63 -63
- package/src/solid/copy-button.tsx +31 -31
- package/src/solid/count-pill.tsx +11 -11
- package/src/solid/dashboard-preview.tsx +104 -104
- package/src/solid/data-table.tsx +228 -228
- package/src/solid/dialog-parts.tsx +129 -129
- package/src/solid/dialog.tsx +113 -113
- package/src/solid/dock-paging.ts +9 -9
- package/src/solid/dock.tsx +339 -338
- package/src/solid/docked-panel.tsx +35 -35
- package/src/solid/dropdown-menu.tsx +77 -77
- package/src/solid/empty.tsx +70 -70
- package/src/solid/entity-data.ts +38 -38
- package/src/solid/entity-selector.tsx +634 -634
- package/src/solid/field.tsx +205 -205
- package/src/solid/form.tsx +159 -159
- package/src/solid/hero-action.tsx +85 -85
- package/src/solid/hover-card.tsx +11 -11
- package/src/solid/icon-picker.tsx +401 -401
- package/src/solid/icon.tsx +101 -78
- package/src/solid/image-picker.tsx +416 -414
- package/src/solid/index.ts +265 -304
- package/src/solid/input-group.tsx +123 -123
- package/src/solid/input-otp.tsx +143 -143
- package/src/solid/input.tsx +4 -4
- package/src/solid/item.tsx +130 -130
- package/src/solid/kbd.tsx +20 -20
- package/src/solid/label.tsx +12 -12
- package/src/solid/list-reorder.ts +122 -122
- package/src/solid/logo.tsx +60 -60
- package/src/solid/media-copy.ts +21 -21
- package/src/solid/media-store.ts +60 -57
- package/src/solid/media-tile.tsx +85 -85
- package/src/solid/menu-parts.tsx +164 -164
- package/src/solid/number-field.tsx +56 -56
- package/src/solid/option-card.tsx +168 -165
- package/src/solid/ornament.tsx +43 -43
- package/src/solid/overlay.tsx +4 -4
- package/src/solid/page-header.tsx +75 -75
- package/src/solid/pagination.tsx +80 -80
- package/src/solid/password-input.tsx +51 -51
- package/src/solid/picker-row.tsx +83 -83
- package/src/solid/picker-search.tsx +65 -63
- package/src/solid/picker-trigger.tsx +59 -57
- package/src/solid/popover.tsx +54 -54
- package/src/solid/preview-tile.tsx +67 -67
- package/src/solid/progress.tsx +21 -21
- package/src/solid/radio-group.tsx +51 -51
- package/src/solid/resizable.tsx +128 -128
- package/src/solid/responsive-dialog.tsx +134 -134
- package/src/solid/schema-form.tsx +746 -739
- package/src/solid/scope-indicator.tsx +5 -5
- package/src/solid/scroll-area.tsx +16 -16
- package/src/solid/section-card.tsx +281 -281
- package/src/solid/select.tsx +101 -101
- package/src/solid/separator.tsx +25 -25
- package/src/solid/settings-row.tsx +122 -122
- package/src/solid/sheet.tsx +96 -96
- package/src/solid/skeleton.tsx +8 -8
- package/src/solid/slider.tsx +132 -132
- package/src/solid/sliding-indicator.tsx +280 -265
- package/src/solid/sonner.tsx +164 -164
- package/src/solid/spinner.tsx +12 -12
- package/src/solid/spotlight.tsx +140 -140
- package/src/solid/step-indicator.tsx +18 -18
- package/src/solid/swatch-picker.tsx +38 -38
- package/src/solid/switch.tsx +52 -52
- package/src/solid/table.tsx +63 -63
- package/src/solid/tabs.tsx +93 -93
- package/src/solid/textarea.tsx +8 -8
- package/src/solid/toggle-group.tsx +83 -83
- package/src/solid/toggle.tsx +33 -33
- package/src/solid/tooltip.tsx +16 -16
- package/src/solid/widget-card.tsx +90 -90
- package/src/solid/widget-identity.tsx +99 -99
- package/src/solid/widget-trust-badge.tsx +20 -20
- package/src/styles/globals.css +316 -319
- package/src/styles/theme.css +448 -448
- package/src/tokens/hex.ts +29 -29
- package/src/tokens/material.ts +75 -75
- package/src/tokens/presets.ts +303 -303
- package/src/tokens/readability.ts +32 -32
- package/src/tokens/theme-colors.ts +95 -95
- package/src/tokens/theme-css.ts +22 -22
- package/src/tokens/theme-recipe.ts +106 -106
package/src/solid/spotlight.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
58
|
+
const anchorEl = () => props.anchor ?? props.target;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
createEffect(() => {
|
|
80
|
+
const target = props.target;
|
|
81
|
+
const anchor = anchorEl();
|
|
82
|
+
let raf = 0;
|
|
83
|
+
let start: number | undefined;
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
93
|
+
measure();
|
|
94
|
+
raf = requestAnimationFrame(tick);
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
121
|
-
|
|
120
|
+
const place = () =>
|
|
121
|
+
placeBubble(viewport(), anchorBox(), bubbleSize(), BUBBLE_GAP_WITH_TAIL, VIEWPORT_MARGIN);
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
11
|
+
const steps = () => Array.from({ length: Math.max(props.count, 0) }, (_, step) => step);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
}
|
package/src/solid/switch.tsx
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
defaultChecked?: boolean;
|
|
9
|
+
onChange?: (checked: boolean) => void;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const Switch: Component<SwitchProps> = (props) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 };
|