@glasshome/ui 1.42.0 → 1.43.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.
- package/dist/index.js +2 -2
- package/dist/lib/anchor-placement.d.ts +4 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +16 -2
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +6 -4
- package/dist/lib/behavior/focus-scope.d.ts +7 -1
- package/dist/lib/behavior/hide-outside.d.ts +1 -1
- package/dist/lib/behavior/layer-stack.d.ts +3 -2
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +2 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +1 -1
- package/dist/lib/overlay-classes.d.ts +1 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -45
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/dialog-parts.d.ts +8 -8
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +7725 -13458
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +1 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +1 -1
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +22 -22
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CxAii-e9.js → utils-3Codx-NZ.js} +527 -489
- package/package.json +3 -6
- package/src/lib/anchor-placement.ts +10 -3
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +26 -8
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +66 -29
- package/src/lib/behavior/dismiss.ts +61 -21
- package/src/lib/behavior/focus-scope.ts +31 -6
- package/src/lib/behavior/hide-outside.ts +2 -2
- package/src/lib/behavior/layer-stack.ts +33 -8
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +24 -18
- package/src/lib/behavior/polymorphic.tsx +1 -1
- package/src/lib/behavior/presence.ts +1 -1
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/clipboard.ts +2 -3
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +7 -7
- package/src/lib/overlay-classes.ts +1 -3
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -118
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/area-picker.tsx +3 -2
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/bottom-sheet/bottom-sheet.tsx +1 -1
- package/src/solid/button.tsx +12 -6
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +285 -94
- package/src/solid/dialog-parts.tsx +9 -9
- package/src/solid/dock.tsx +3 -2
- package/src/solid/dropdown-menu.tsx +252 -115
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +3 -2
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +5 -6
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +287 -25
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/index.ts +1 -3
- package/src/solid/input-group.tsx +2 -2
- package/src/solid/item.tsx +1 -1
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +5 -1
- package/src/solid/popover.tsx +424 -79
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +1 -1
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +950 -95
- package/src/solid/selection.tsx +142 -66
- package/src/solid/sheet.tsx +1 -1
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +1 -1
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/tabs.tsx +12 -6
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +29 -99
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +24 -24
- package/src/styles/globals.css +61 -7
- package/src/styles/theme.css +7 -4
- package/src/tokens/material.ts +11 -2
package/src/solid/selection.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ComponentProps,
|
|
3
3
|
createContext,
|
|
4
|
+
createSignal,
|
|
4
5
|
type JSX,
|
|
5
6
|
onCleanup,
|
|
6
7
|
onMount,
|
|
@@ -8,26 +9,50 @@ import {
|
|
|
8
9
|
splitProps,
|
|
9
10
|
useContext,
|
|
10
11
|
} from "solid-js";
|
|
12
|
+
import { effect } from "../lib/behavior/solid.js";
|
|
11
13
|
import { cn } from "../lib/utils.js";
|
|
12
14
|
|
|
13
15
|
/** The attribute (without `data-`) that marks the active item: Kobalte's, or the caller's own. */
|
|
14
16
|
export type SelectionMarker = "pressed" | "selected" | "highlighted" | "lit";
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
interface SelectionContextValue {
|
|
19
|
+
marker: SelectionMarker;
|
|
20
|
+
report: (item: HTMLElement, active: boolean) => void;
|
|
21
|
+
watchMarker: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SelectionContext = createContext<SelectionContextValue>();
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
* The glass behind an item while it is the active one. Render it as the first child of every
|
|
20
28
|
* item inside a `SelectionScope`; CSS shows the one whose item carries the scope's marker, so
|
|
21
29
|
* layout keeps it in place and nothing measures it at rest. Renders nothing outside a scope.
|
|
30
|
+
* Pass `active` when the item knows it carries the marker; without it the scope watches the
|
|
31
|
+
* marker attribute instead, which costs a MutationObserver.
|
|
22
32
|
*/
|
|
23
|
-
export function SelectionHighlight() {
|
|
24
|
-
const
|
|
33
|
+
export function SelectionHighlight(props: { active?: boolean }) {
|
|
34
|
+
const scope = useContext(SelectionContext);
|
|
35
|
+
let span: HTMLSpanElement | undefined;
|
|
36
|
+
const [item, setItem] = createSignal<HTMLElement>();
|
|
37
|
+
onMount(() => setItem(span?.parentElement ?? undefined));
|
|
38
|
+
if (scope && props.active === undefined) scope.watchMarker();
|
|
39
|
+
effect(
|
|
40
|
+
() => [item(), props.active] as const,
|
|
41
|
+
([item, active]) => {
|
|
42
|
+
if (!scope || !item || active === undefined) return;
|
|
43
|
+
scope.report(item, active);
|
|
44
|
+
return () => {
|
|
45
|
+
if (active) scope.report(item, false);
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
);
|
|
25
49
|
return (
|
|
26
|
-
<Show when={
|
|
50
|
+
<Show when={scope}>
|
|
27
51
|
{(on) => (
|
|
28
52
|
<span
|
|
53
|
+
ref={span}
|
|
29
54
|
data-selection-highlight=""
|
|
30
|
-
data-on={on()}
|
|
55
|
+
data-on={on().marker}
|
|
31
56
|
data-sliding-indicator=""
|
|
32
57
|
aria-hidden="true"
|
|
33
58
|
class="glass glass-tint"
|
|
@@ -37,7 +62,6 @@ export function SelectionHighlight() {
|
|
|
37
62
|
);
|
|
38
63
|
}
|
|
39
64
|
|
|
40
|
-
const DEFAULT_DURATION_MS = 220;
|
|
41
65
|
// Kobalte clears a menu row's highlight on pointerleave and sets the next on pointermove.
|
|
42
66
|
const GAP_MS = 100;
|
|
43
67
|
// Squash-and-stretch as a pixel budget per axis, so a big item does not deform more.
|
|
@@ -48,14 +72,6 @@ const DEFORM_MAX = 0.14;
|
|
|
48
72
|
/** Centre and size in the scope's own content pixels. */
|
|
49
73
|
type Box = { x: number; y: number; width: number; height: number };
|
|
50
74
|
|
|
51
|
-
function durationMs(root: HTMLElement): number {
|
|
52
|
-
const raw = getComputedStyle(root).getPropertyValue("--duration-slide").trim();
|
|
53
|
-
if (!raw) return DEFAULT_DURATION_MS;
|
|
54
|
-
const value = Number.parseFloat(raw);
|
|
55
|
-
if (Number.isNaN(value)) return DEFAULT_DURATION_MS;
|
|
56
|
-
return raw.endsWith("ms") ? value : value * 1000;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
75
|
function boxIn(root: HTMLElement, el: Element, size: { width: number; height: number }): Box {
|
|
60
76
|
const outer = root.getBoundingClientRect();
|
|
61
77
|
const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
|
|
@@ -75,6 +91,16 @@ function itemBox(root: HTMLElement, item: HTMLElement): Box | undefined {
|
|
|
75
91
|
return box.width > 0 && box.height > 0 ? box : undefined;
|
|
76
92
|
}
|
|
77
93
|
|
|
94
|
+
/** Whether the box shows inside the root's scrollport; a highlight never flies in from out of sight. */
|
|
95
|
+
function inSight(root: HTMLElement, box: Box): boolean {
|
|
96
|
+
return (
|
|
97
|
+
box.y + box.height / 2 > root.scrollTop &&
|
|
98
|
+
box.y - box.height / 2 < root.scrollTop + root.clientHeight &&
|
|
99
|
+
box.x + box.width / 2 > root.scrollLeft &&
|
|
100
|
+
box.x - box.width / 2 < root.scrollLeft + root.clientWidth
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
78
104
|
function flyerBox(root: HTMLElement, flyer: HTMLElement): Box {
|
|
79
105
|
const outer = root.getBoundingClientRect();
|
|
80
106
|
const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
|
|
@@ -99,47 +125,46 @@ function writeStyle(el: HTMLElement, name: string, value: string) {
|
|
|
99
125
|
if (el.style.getPropertyValue(name) !== value) el.style.setProperty(name, value);
|
|
100
126
|
}
|
|
101
127
|
|
|
102
|
-
/**
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
128
|
+
/** The corner and tone the flyer takes from its target, without asking the page for a style. */
|
|
129
|
+
function lookOf(item: HTMLElement, radius: string | undefined) {
|
|
130
|
+
if (radius === undefined) {
|
|
131
|
+
const look = getComputedStyle(item);
|
|
132
|
+
return {
|
|
133
|
+
radius: look.borderRadius,
|
|
134
|
+
tone: look.getPropertyValue("--selection-tone").trim(),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return { radius, tone: item.style.getPropertyValue("--selection-tone").trim() };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* One flight at a time, run by CSS keyframes on the token duration; every way a flight ends goes
|
|
142
|
+
* through `settle`. Each flight flips the phase, so a new flight restarts the keyframes.
|
|
143
|
+
*/
|
|
144
|
+
function createFlight(root: HTMLElement, flyer: HTMLElement, radius: () => string | undefined) {
|
|
145
|
+
let phase: "a" | "b" = "b";
|
|
106
146
|
let landing: Element | undefined;
|
|
107
147
|
|
|
108
|
-
const
|
|
109
|
-
for (const animation of running) animation.cancel();
|
|
110
|
-
running = [];
|
|
148
|
+
const settle = () => {
|
|
111
149
|
landing?.removeAttribute("data-landing");
|
|
112
150
|
landing = undefined;
|
|
151
|
+
flyer.removeAttribute("data-flying");
|
|
113
152
|
};
|
|
114
153
|
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
stop();
|
|
118
|
-
flyer.removeAttribute("data-flying");
|
|
154
|
+
const ended = (event: AnimationEvent) => {
|
|
155
|
+
if (event.animationName === `selection-glide-${phase}`) settle();
|
|
119
156
|
};
|
|
157
|
+
flyer.addEventListener("animationend", ended);
|
|
158
|
+
flyer.addEventListener("animationcancel", ended);
|
|
120
159
|
|
|
121
160
|
const start = (from: Box, item: HTMLElement) => {
|
|
122
|
-
generation += 1;
|
|
123
|
-
const current = generation;
|
|
124
|
-
stop();
|
|
125
161
|
const target = highlightOf(item);
|
|
126
162
|
const to = itemBox(root, item);
|
|
127
|
-
|
|
128
|
-
if (!target || !to || duration <= 0) return settle(current);
|
|
163
|
+
if (!target || !to) return settle();
|
|
129
164
|
|
|
130
|
-
|
|
131
|
-
const look = getComputedStyle(item);
|
|
132
|
-
const radius = look.borderRadius;
|
|
133
|
-
const tone = look.getPropertyValue("--selection-tone").trim();
|
|
165
|
+
const look = lookOf(item, radius());
|
|
134
166
|
const left = to.x - to.width / 2;
|
|
135
167
|
const top = to.y - to.height / 2;
|
|
136
|
-
const rest = `${left}px ${top}px`;
|
|
137
|
-
writeStyle(flyer, "width", `${to.width}px`);
|
|
138
|
-
writeStyle(flyer, "height", `${to.height}px`);
|
|
139
|
-
writeStyle(flyer, "translate", rest);
|
|
140
|
-
writeStyle(flyer, "--selection-radius", radius);
|
|
141
|
-
writeStyle(flyer, "--selection-tone", tone);
|
|
142
|
-
|
|
143
168
|
const dx = from.x - to.x;
|
|
144
169
|
const dy = from.y - to.y;
|
|
145
170
|
const kx = from.width / to.width;
|
|
@@ -154,23 +179,20 @@ function createFlight(root: HTMLElement, flyer: HTMLElement) {
|
|
|
154
179
|
peakY *= alongX ? pinch : stretch;
|
|
155
180
|
}
|
|
156
181
|
|
|
182
|
+
writeStyle(flyer, "width", `${to.width}px`);
|
|
183
|
+
writeStyle(flyer, "height", `${to.height}px`);
|
|
184
|
+
writeStyle(flyer, "translate", `${left}px ${top}px`);
|
|
185
|
+
writeStyle(flyer, "--selection-radius", look.radius);
|
|
186
|
+
writeStyle(flyer, "--selection-tone", look.tone);
|
|
187
|
+
writeStyle(flyer, "--selection-from", `${left + dx}px ${top + dy}px`);
|
|
188
|
+
writeStyle(flyer, "--selection-scale-from", `${kx} ${ky}`);
|
|
189
|
+
writeStyle(flyer, "--selection-scale-peak", `${peakX} ${peakY}`);
|
|
190
|
+
|
|
191
|
+
landing?.removeAttribute("data-landing");
|
|
157
192
|
landing = target;
|
|
158
193
|
target.setAttribute("data-landing", "");
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const end = () => settle(current);
|
|
162
|
-
try {
|
|
163
|
-
running = [
|
|
164
|
-
flyer.animate([{ translate: `${left + dx}px ${top + dy}px` }, { translate: rest }], timing),
|
|
165
|
-
flyer.animate(
|
|
166
|
-
[{ scale: `${kx} ${ky}` }, { scale: `${peakX} ${peakY}` }, { scale: "1 1" }],
|
|
167
|
-
timing,
|
|
168
|
-
),
|
|
169
|
-
];
|
|
170
|
-
} catch {
|
|
171
|
-
return end();
|
|
172
|
-
}
|
|
173
|
-
Promise.all(running.map((animation) => animation.finished)).then(end, end);
|
|
194
|
+
phase = phase === "a" ? "b" : "a";
|
|
195
|
+
flyer.setAttribute("data-flying", phase);
|
|
174
196
|
};
|
|
175
197
|
|
|
176
198
|
return { settle, start, flying: () => flyer.hasAttribute("data-flying") };
|
|
@@ -180,6 +202,11 @@ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
|
|
|
180
202
|
marker: SelectionMarker;
|
|
181
203
|
/** CSS colour for the highlight's glass. Default `var(--material-accent)`. */
|
|
182
204
|
tone?: string;
|
|
205
|
+
/**
|
|
206
|
+
* The items' corner radius as CSS, which the flyer takes in flight. Without it the scope reads
|
|
207
|
+
* each target's computed corner and tone per flight; that read goes in 2.0.0, where it is required.
|
|
208
|
+
*/
|
|
209
|
+
radius?: string;
|
|
183
210
|
style?: JSX.CSSProperties;
|
|
184
211
|
}
|
|
185
212
|
|
|
@@ -188,7 +215,15 @@ interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
|
|
|
188
215
|
* one flyer animates from the old item to the new one and hands off to its resting highlight.
|
|
189
216
|
*/
|
|
190
217
|
export function SelectionScope(props: SelectionScopeProps) {
|
|
191
|
-
const [local, rest] = splitProps(props, [
|
|
218
|
+
const [local, rest] = splitProps(props, [
|
|
219
|
+
"marker",
|
|
220
|
+
"tone",
|
|
221
|
+
"radius",
|
|
222
|
+
"class",
|
|
223
|
+
"style",
|
|
224
|
+
"children",
|
|
225
|
+
"ref",
|
|
226
|
+
]);
|
|
192
227
|
let root: HTMLDivElement | undefined;
|
|
193
228
|
let flyer: HTMLSpanElement | undefined;
|
|
194
229
|
const setRoot = (el: HTMLDivElement) => {
|
|
@@ -197,17 +232,40 @@ export function SelectionScope(props: SelectionScopeProps) {
|
|
|
197
232
|
if (typeof forwarded === "function") forwarded(el);
|
|
198
233
|
};
|
|
199
234
|
|
|
235
|
+
let move: ((next: HTMLElement | undefined) => void) | undefined;
|
|
236
|
+
let watching = false;
|
|
237
|
+
let watch: (() => void) | undefined;
|
|
238
|
+
const reported = new Set<HTMLElement>();
|
|
239
|
+
let queued = false;
|
|
240
|
+
// Decides after the task that changed the marker, which may still scroll the new item into view.
|
|
241
|
+
const report = (item: HTMLElement, active: boolean) => {
|
|
242
|
+
if (active) {
|
|
243
|
+
reported.delete(item);
|
|
244
|
+
reported.add(item);
|
|
245
|
+
} else if (!reported.delete(item)) return;
|
|
246
|
+
if (queued) return;
|
|
247
|
+
queued = true;
|
|
248
|
+
queueMicrotask(() => {
|
|
249
|
+
queued = false;
|
|
250
|
+
move?.([...reported].at(-1));
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
const watchMarker = () => {
|
|
254
|
+
if (watching) return;
|
|
255
|
+
watching = true;
|
|
256
|
+
watch?.();
|
|
257
|
+
};
|
|
258
|
+
|
|
200
259
|
onMount(() => {
|
|
201
260
|
const scope = root;
|
|
202
261
|
const travel = flyer;
|
|
203
262
|
if (!scope || !travel) return;
|
|
204
263
|
const attribute = `data-${local.marker}`;
|
|
205
|
-
const flight = createFlight(scope, travel);
|
|
206
|
-
let active = activeIn(scope, attribute);
|
|
264
|
+
const flight = createFlight(scope, travel, () => local.radius);
|
|
265
|
+
let active = [...reported].at(-1) ?? activeIn(scope, attribute);
|
|
207
266
|
let left: { item: HTMLElement; box: Box | undefined; at: number } | undefined;
|
|
208
267
|
|
|
209
|
-
|
|
210
|
-
const next = activeIn(scope, attribute);
|
|
268
|
+
move = (next) => {
|
|
211
269
|
if (next === active) return;
|
|
212
270
|
const previous = active;
|
|
213
271
|
active = next;
|
|
@@ -228,12 +286,20 @@ export function SelectionScope(props: SelectionScopeProps) {
|
|
|
228
286
|
: recent
|
|
229
287
|
? (recent.box ?? itemBox(scope, recent.item))
|
|
230
288
|
: undefined;
|
|
231
|
-
if (from) flight.start(from, next);
|
|
289
|
+
if (from && inSight(scope, from)) flight.start(from, next);
|
|
232
290
|
else flight.settle();
|
|
233
|
-
}
|
|
234
|
-
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
let observer: MutationObserver | undefined;
|
|
294
|
+
watch = () => {
|
|
295
|
+
observer = new MutationObserver(() => move?.(activeIn(scope, attribute)));
|
|
296
|
+
observer.observe(scope, { subtree: true, attributes: true, attributeFilter: [attribute] });
|
|
297
|
+
};
|
|
298
|
+
if (watching) watch();
|
|
235
299
|
onCleanup(() => {
|
|
236
|
-
observer
|
|
300
|
+
observer?.disconnect();
|
|
301
|
+
move = undefined;
|
|
302
|
+
watch = undefined;
|
|
237
303
|
flight.settle();
|
|
238
304
|
});
|
|
239
305
|
});
|
|
@@ -246,7 +312,17 @@ export function SelectionScope(props: SelectionScopeProps) {
|
|
|
246
312
|
style={local.tone ? { ...local.style, "--selection-tone": local.tone } : local.style}
|
|
247
313
|
{...rest}
|
|
248
314
|
>
|
|
249
|
-
<SelectionContext.Provider
|
|
315
|
+
<SelectionContext.Provider
|
|
316
|
+
value={{
|
|
317
|
+
get marker() {
|
|
318
|
+
return local.marker;
|
|
319
|
+
},
|
|
320
|
+
report,
|
|
321
|
+
watchMarker,
|
|
322
|
+
}}
|
|
323
|
+
>
|
|
324
|
+
{local.children}
|
|
325
|
+
</SelectionContext.Provider>
|
|
250
326
|
<span
|
|
251
327
|
ref={flyer}
|
|
252
328
|
data-selection-flyer=""
|
package/src/solid/sheet.tsx
CHANGED
|
@@ -75,7 +75,7 @@ const SHEET_SIDE = {
|
|
|
75
75
|
"data-[closed]:slide-out-to-right data-[expanded]:slide-in-from-right inset-y-3 right-3 w-3/4 sm:max-w-sm",
|
|
76
76
|
left: "data-[closed]:slide-out-to-left data-[expanded]:slide-in-from-left inset-y-3 left-3 w-3/4 sm:max-w-sm",
|
|
77
77
|
top: `data-[closed]:slide-out-to-top data-[expanded]:slide-in-from-top inset-x-3 top-3 ${MODAL_MAX_H}`,
|
|
78
|
-
/** @deprecated
|
|
78
|
+
/** @deprecated `BottomSheet` or `ResponsiveDialog`; removed in 2.0.0. */
|
|
79
79
|
bottom: `data-[closed]:slide-out-to-bottom data-[expanded]:slide-in-from-bottom inset-x-3 bottom-3 ${MODAL_MAX_H}`,
|
|
80
80
|
} as const;
|
|
81
81
|
|
package/src/solid/slider.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Slider as KSlider } from "@kobalte/core/slider";
|
|
2
1
|
import type { Component } from "solid-js";
|
|
3
|
-
import {
|
|
2
|
+
import { createMemo, createSignal, For } from "solid-js";
|
|
3
|
+
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
4
|
+
import { alongTrack, createDrag, createRange } from "../lib/behavior/range.js";
|
|
4
5
|
import { FIELD_CHROME, FOCUS_RING } from "../lib/input-classes.js";
|
|
6
|
+
import { locale, readingDirection } from "../lib/locale.js";
|
|
5
7
|
import { THUMB_CLASS, THUMB_RAIL_BLEED, THUMB_RAIL_PAD } from "../lib/thumb-classes.js";
|
|
6
8
|
import { cn } from "../lib/utils.js";
|
|
7
9
|
|
|
@@ -32,118 +34,166 @@ interface SliderProps {
|
|
|
32
34
|
"aria-labelledby"?: string;
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
const decimal = new Intl.NumberFormat(locale, { style: "decimal" });
|
|
38
|
+
const rtl = readingDirection === "rtl";
|
|
39
|
+
const START = rtl ? "right" : "left";
|
|
40
|
+
const END = rtl ? "left" : "right";
|
|
41
|
+
const THUMB_SHIFT = rtl ? "translateX(50%)" : "translateX(-50%)";
|
|
42
|
+
|
|
35
43
|
const Slider: Component<SliderProps> = (props) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
]);
|
|
44
|
+
const min = () => props.min ?? 0;
|
|
45
|
+
const max = () => props.max ?? 100;
|
|
46
|
+
const disabled = () => props.disabled ?? false;
|
|
47
|
+
const range = createRange({
|
|
48
|
+
values: () => props.value,
|
|
49
|
+
defaultValues: () => props.defaultValue ?? [min()],
|
|
50
|
+
min,
|
|
51
|
+
max,
|
|
52
|
+
step: () => props.step ?? 1,
|
|
53
|
+
minStepsBetween: () => props.minStepsBetweenThumbs ?? 0,
|
|
54
|
+
disabled,
|
|
55
|
+
onChange: (values) => props.onChange?.(values),
|
|
56
|
+
onChangeEnd: (values) => props.onChangeEnd?.(values),
|
|
57
|
+
});
|
|
58
|
+
const indices = createMemo(() => range.values().map((_, i) => i), [], {
|
|
59
|
+
equals: (a, b) => a.length === b.length,
|
|
60
|
+
});
|
|
61
|
+
const percents = () => range.values().map((v) => range.fraction(v) * 100);
|
|
62
|
+
const [thumbs, setThumbs] = createSignal<HTMLElement[]>([]);
|
|
63
|
+
let active = 0;
|
|
64
|
+
let grab = 0;
|
|
65
|
+
|
|
66
|
+
const drag = createDrag({
|
|
67
|
+
disabled,
|
|
68
|
+
start: (e, rect) => {
|
|
69
|
+
const thumb = (e.target as Element).closest('[data-slot="slider-thumb"]');
|
|
70
|
+
const pressed = thumbs().findIndex((el) => el === thumb);
|
|
71
|
+
const at = alongTrack(e, rect);
|
|
72
|
+
if (pressed >= 0) {
|
|
73
|
+
active = pressed;
|
|
74
|
+
grab = at - range.fraction(range.values()[pressed] ?? 0);
|
|
75
|
+
} else {
|
|
76
|
+
const raw = min() + at * (max() - min());
|
|
77
|
+
grab = 0;
|
|
78
|
+
active = range.closestThumb(raw);
|
|
79
|
+
range.setThumb(active, raw);
|
|
80
|
+
}
|
|
81
|
+
focusWithoutTracking(thumbs()[active]);
|
|
82
|
+
},
|
|
83
|
+
move: (e, rect) => range.setThumb(active, range.valueAt(alongTrack(e, rect) - grab)),
|
|
84
|
+
end: range.dragEnd,
|
|
85
|
+
});
|
|
55
86
|
|
|
56
87
|
const markerPct = (v: number) => {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
return max === min ? 0 : ((v - min) / (max - min)) * 100;
|
|
88
|
+
const span = max() - min();
|
|
89
|
+
return span === 0 ? 0 : ((v - min()) / span) * 100;
|
|
60
90
|
};
|
|
61
91
|
|
|
92
|
+
const disabledMark = () => (disabled() ? "" : undefined);
|
|
93
|
+
|
|
62
94
|
return (
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
defaultValue={local.defaultValue}
|
|
66
|
-
minValue={local.min ?? 0}
|
|
67
|
-
maxValue={local.max ?? 100}
|
|
68
|
-
step={local.step ?? 1}
|
|
69
|
-
minStepsBetweenThumbs={local.minStepsBetweenThumbs}
|
|
70
|
-
disabled={local.disabled}
|
|
71
|
-
onChange={local.onChange}
|
|
72
|
-
onChangeEnd={local.onChangeEnd}
|
|
95
|
+
<div
|
|
96
|
+
role="group"
|
|
73
97
|
data-slot="slider"
|
|
98
|
+
data-orientation="horizontal"
|
|
99
|
+
data-disabled={disabledMark()}
|
|
74
100
|
class={cn(
|
|
75
101
|
// The rail wears the shared toggle/rail chrome, so it reads as an empty
|
|
76
102
|
// well in both themes (a field's light-theme fill rises to the card).
|
|
77
103
|
"relative flex w-full touch-none items-center rounded-xl select-none",
|
|
78
104
|
THUMB_RAIL_PAD,
|
|
79
105
|
FIELD_CHROME,
|
|
80
|
-
|
|
81
|
-
|
|
106
|
+
disabled() && "cursor-not-allowed opacity-50",
|
|
107
|
+
props.class,
|
|
82
108
|
)}
|
|
83
109
|
>
|
|
84
|
-
<
|
|
110
|
+
<div
|
|
85
111
|
data-slot="slider-track"
|
|
112
|
+
data-orientation="horizontal"
|
|
113
|
+
data-disabled={disabledMark()}
|
|
86
114
|
class={cn(
|
|
87
115
|
"relative h-7 w-full",
|
|
88
|
-
|
|
89
|
-
|
|
116
|
+
disabled() ? "cursor-not-allowed" : "cursor-pointer",
|
|
117
|
+
props.trackClass,
|
|
90
118
|
)}
|
|
119
|
+
on:pointerdown={drag.onPointerDown}
|
|
120
|
+
on:pointermove={drag.onPointerMove}
|
|
121
|
+
on:pointerup={drag.onPointerUp}
|
|
122
|
+
on:pointercancel={drag.onPointerCancel}
|
|
91
123
|
>
|
|
92
|
-
<
|
|
124
|
+
<div
|
|
93
125
|
data-slot="slider-fill"
|
|
126
|
+
data-orientation="horizontal"
|
|
127
|
+
data-disabled={disabledMark()}
|
|
94
128
|
class={cn(
|
|
95
129
|
// The fill sits sunk inside the recessed rail: the tinted-surface
|
|
96
130
|
// outer drop shadow would read as a halo leaking out of the groove.
|
|
97
131
|
"glass glass-tint absolute inset-y-0 rounded-xl [--glass-drop:0%] [--glass-wash:90%]",
|
|
98
132
|
THUMB_RAIL_BLEED,
|
|
99
|
-
Array.isArray(
|
|
133
|
+
Array.isArray(props.fillTone) && "glass-edge-gradient",
|
|
100
134
|
)}
|
|
101
|
-
style={
|
|
102
|
-
|
|
135
|
+
style={{
|
|
136
|
+
[START]: `${percents().length > 1 ? Math.min(...percents()) : 0}%`,
|
|
137
|
+
[END]: `${100 - Math.max(...percents())}%`,
|
|
138
|
+
...(Array.isArray(props.fillTone)
|
|
103
139
|
? {
|
|
104
|
-
"--glass-tone":
|
|
105
|
-
"--glass-tone-2":
|
|
140
|
+
"--glass-tone": props.fillTone[0],
|
|
141
|
+
"--glass-tone-2": props.fillTone[1],
|
|
106
142
|
"--glass-wash-2": "var(--glass-wash)",
|
|
107
143
|
"--glass-wash-angle": "90deg",
|
|
108
144
|
}
|
|
109
|
-
: { "--glass-tone":
|
|
110
|
-
}
|
|
145
|
+
: { "--glass-tone": props.fillTone ?? "var(--material-accent)" }),
|
|
146
|
+
}}
|
|
111
147
|
/>
|
|
112
|
-
<
|
|
148
|
+
<For each={props.markers ?? []}>
|
|
113
149
|
{(marker) => (
|
|
114
150
|
<span
|
|
115
151
|
data-slot="slider-marker"
|
|
116
152
|
class="pointer-events-none absolute top-1/2 h-3 w-0.5 -translate-x-1/2 -translate-y-1/2 rounded-full"
|
|
117
153
|
style={{
|
|
118
|
-
left: `${markerPct(marker
|
|
154
|
+
left: `${markerPct(marker)}%`,
|
|
119
155
|
background: "color-mix(in oklab, var(--foreground) 60%, transparent)",
|
|
120
156
|
}}
|
|
121
157
|
/>
|
|
122
158
|
)}
|
|
123
|
-
</
|
|
124
|
-
<
|
|
125
|
-
{(
|
|
126
|
-
<
|
|
159
|
+
</For>
|
|
160
|
+
<For each={indices()}>
|
|
161
|
+
{(index) => (
|
|
162
|
+
<span
|
|
163
|
+
ref={(el) => setThumbs((all) => Object.assign(all.slice(), { [index]: el }))}
|
|
164
|
+
role="slider"
|
|
127
165
|
data-slot="slider-thumb"
|
|
166
|
+
data-orientation="horizontal"
|
|
167
|
+
data-disabled={disabledMark()}
|
|
168
|
+
tabIndex={disabled() ? undefined : 0}
|
|
169
|
+
aria-label={props["aria-label"]}
|
|
170
|
+
aria-labelledby={props["aria-labelledby"]}
|
|
171
|
+
aria-valuemin={min()}
|
|
172
|
+
aria-valuemax={max()}
|
|
173
|
+
aria-valuenow={range.values()[index]}
|
|
174
|
+
aria-valuetext={decimal.format(range.values()[index] ?? 0)}
|
|
175
|
+
aria-orientation="horizontal"
|
|
176
|
+
aria-disabled={disabled() || undefined}
|
|
128
177
|
class={cn(
|
|
129
178
|
THUMB_CLASS,
|
|
130
179
|
FOCUS_RING,
|
|
131
|
-
"absolute top-0 transition-transform duration-
|
|
132
|
-
|
|
133
|
-
|
|
180
|
+
"absolute top-0 transition-transform duration-(--duration-expand) ease-out hover:scale-125 active:scale-110",
|
|
181
|
+
disabled() && "cursor-not-allowed",
|
|
182
|
+
props.thumbClass,
|
|
134
183
|
)}
|
|
135
|
-
aria-label={local["aria-label"]}
|
|
136
|
-
aria-labelledby={local["aria-labelledby"]}
|
|
137
184
|
style={{
|
|
138
|
-
|
|
185
|
+
[START]: `calc(${percents()[index] ?? 0}%)`,
|
|
186
|
+
transform: THUMB_SHIFT,
|
|
187
|
+
"touch-action": "none",
|
|
188
|
+
background: props.thumbColors?.[index] ?? "var(--material-control-knob)",
|
|
139
189
|
}}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
190
|
+
on:keydown={(e) => range.keyDown(e, index)}
|
|
191
|
+
onBlur={range.blur}
|
|
192
|
+
/>
|
|
143
193
|
)}
|
|
144
|
-
</
|
|
145
|
-
</
|
|
146
|
-
</
|
|
194
|
+
</For>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
147
197
|
);
|
|
148
198
|
};
|
|
149
199
|
|
|
@@ -75,7 +75,7 @@ const STRETCH_PX = 6; // grow along travel
|
|
|
75
75
|
const SQUASH_PX = 6; // pinch perpendicular
|
|
76
76
|
const DEFORM_MAX = 0.14;
|
|
77
77
|
|
|
78
|
-
/** @deprecated
|
|
78
|
+
/** @deprecated `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0.0. */
|
|
79
79
|
export function SlidingIndicator(props: SlidingIndicatorProps) {
|
|
80
80
|
const [local, rest] = splitProps(props, [
|
|
81
81
|
"active",
|
package/src/solid/sonner.tsx
CHANGED
|
@@ -186,7 +186,7 @@ const toast = Object.assign(
|
|
|
186
186
|
warning: show("warning"),
|
|
187
187
|
info: show("info"),
|
|
188
188
|
message: show("message"),
|
|
189
|
-
/** @deprecated
|
|
189
|
+
/** @deprecated `toast.promise`; removed in 2.0.0. */
|
|
190
190
|
loading: (message: ToastMessage, data: ExternalToast = {}) => {
|
|
191
191
|
const { description, icon, action, ...rest } = data;
|
|
192
192
|
return sonnerToast.custom(
|
package/src/solid/tabs.tsx
CHANGED
|
@@ -14,13 +14,13 @@ import {
|
|
|
14
14
|
} from "solid-js";
|
|
15
15
|
import { type Collection, createCollection } from "../lib/behavior/collection.js";
|
|
16
16
|
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
17
|
-
import { CANDIDATES, focusWithoutTracking,
|
|
17
|
+
import { CANDIDATES, focusWithoutTracking, trackFocus } from "../lib/behavior/focus-scope.js";
|
|
18
18
|
import { Polymorphic } from "../lib/behavior/polymorphic.js";
|
|
19
19
|
import { effect, merge } from "../lib/behavior/solid.js";
|
|
20
20
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
21
21
|
import { PRESS_DIP, SETTLE_MOTION } from "../lib/motion-classes.js";
|
|
22
22
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
23
|
-
import { SEGMENT_ITEM } from "../lib/segment-classes.js";
|
|
23
|
+
import { SEGMENT_ITEM, SEGMENT_RADIUS } from "../lib/segment-classes.js";
|
|
24
24
|
import { cn } from "../lib/utils.js";
|
|
25
25
|
import { Icon } from "./icon.js";
|
|
26
26
|
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
@@ -181,7 +181,7 @@ const TabsList: Component<TabsListProps> = (props) => {
|
|
|
181
181
|
const [el, setEl] = createSignal<HTMLElement>();
|
|
182
182
|
onMount(() => {
|
|
183
183
|
const listEl = el();
|
|
184
|
-
if (listEl) onCleanup(trackScroll(listEl, "[data-selected]",
|
|
184
|
+
if (listEl) onCleanup(trackScroll(listEl, "[data-selected]", ctx.value));
|
|
185
185
|
});
|
|
186
186
|
onCleanup(() => ctx.setList(undefined));
|
|
187
187
|
|
|
@@ -224,7 +224,11 @@ const TabsList: Component<TabsListProps> = (props) => {
|
|
|
224
224
|
>
|
|
225
225
|
{/* w-max so triggers keep their natural width and the track scrolls;
|
|
226
226
|
w-full alone squeezed them past the rounded edge, unreachable. */}
|
|
227
|
-
<SelectionScope
|
|
227
|
+
<SelectionScope
|
|
228
|
+
marker="selected"
|
|
229
|
+
radius={SEGMENT_RADIUS}
|
|
230
|
+
class="flex h-full w-max min-w-full items-center gap-1"
|
|
231
|
+
>
|
|
228
232
|
{local.children}
|
|
229
233
|
</SelectionScope>
|
|
230
234
|
</Polymorphic>
|
|
@@ -268,6 +272,7 @@ const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
|
268
272
|
effect(el, (node) => {
|
|
269
273
|
if (!node) return;
|
|
270
274
|
let mousePressed = false;
|
|
275
|
+
const focused = trackFocus(node);
|
|
271
276
|
const choose = () => {
|
|
272
277
|
if (disabled()) return;
|
|
273
278
|
ctx.select(local.value);
|
|
@@ -280,7 +285,7 @@ const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
|
280
285
|
};
|
|
281
286
|
const click = (event: MouseEvent) => {
|
|
282
287
|
// WebKit leaves a clicked button unfocused.
|
|
283
|
-
if (!disabled() && !
|
|
288
|
+
if (!disabled() && !focused.has()) focusWithoutTracking(node);
|
|
284
289
|
if (event.detail === 0 || !mousePressed) choose();
|
|
285
290
|
mousePressed = false;
|
|
286
291
|
};
|
|
@@ -289,6 +294,7 @@ const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
|
289
294
|
node.addEventListener("click", click);
|
|
290
295
|
node.addEventListener("focus", focus);
|
|
291
296
|
return () => {
|
|
297
|
+
focused.stop();
|
|
292
298
|
node.removeEventListener("pointerdown", pointerdown);
|
|
293
299
|
node.removeEventListener("click", click);
|
|
294
300
|
node.removeEventListener("focus", focus);
|
|
@@ -349,7 +355,7 @@ const TabsTrigger: Component<TabsTriggerProps> = (props) => {
|
|
|
349
355
|
},
|
|
350
356
|
})}
|
|
351
357
|
>
|
|
352
|
-
<SelectionHighlight />
|
|
358
|
+
<SelectionHighlight active={selected()} />
|
|
353
359
|
{local.icon && (
|
|
354
360
|
<Icon
|
|
355
361
|
data-slot={local.inline ? "tabs-trigger-inline-icon" : "tabs-trigger-icon"}
|