@glasshome/ui 1.31.1 → 1.33.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/README.md +1 -1
- package/SPEC.md +1 -1
- package/dist/lib/opening-release.d.ts +6 -0
- package/dist/lib/when-animations-settle.d.ts +4 -0
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +1 -0
- package/dist/solid/dock.d.ts +1 -1
- package/dist/solid/icon-picker.d.ts +1 -0
- package/dist/solid/index.d.ts +1 -0
- package/dist/solid/index.js +2989 -2806
- package/dist/solid/menu-parts.d.ts +2 -5
- package/dist/solid/selection.d.ts +21 -0
- package/dist/solid/sliding-indicator.d.ts +1 -0
- package/dist/testing/animations.d.ts +1 -0
- package/dist/testing/deny-fetch.d.ts +1 -0
- package/dist/testing/fake-time.d.ts +5 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.js +39 -0
- package/package.json +14 -2
- package/src/lib/menu-classes.ts +1 -1
- package/src/lib/opening-release.ts +25 -0
- package/src/lib/when-animations-settle.ts +12 -0
- package/src/solid/area-picker.tsx +5 -9
- package/src/solid/bottom-sheet/bottom-sheet.tsx +17 -20
- package/src/solid/bottom-sheet/sheet-motion.ts +4 -0
- package/src/solid/dock.tsx +10 -7
- package/src/solid/entity-selector.tsx +4 -6
- package/src/solid/icon-picker.tsx +3 -1
- package/src/solid/index.ts +1 -0
- package/src/solid/menu-parts.tsx +21 -58
- package/src/solid/picker-row.tsx +2 -0
- package/src/solid/select.tsx +7 -6
- package/src/solid/selection.tsx +259 -0
- package/src/solid/sliding-indicator.tsx +2 -0
- package/src/solid/tabs.tsx +5 -8
- package/src/solid/toggle-group.tsx +21 -19
- package/src/solid/toggle.tsx +1 -1
- package/src/styles/globals.css +48 -1
- package/src/styles/theme.css +11 -14
- package/src/testing/animations.ts +16 -0
- package/src/testing/deny-fetch.ts +19 -0
- package/src/testing/fake-time.ts +18 -0
- package/src/testing/index.ts +3 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentProps,
|
|
3
|
+
createContext,
|
|
4
|
+
type JSX,
|
|
5
|
+
onCleanup,
|
|
6
|
+
onMount,
|
|
7
|
+
Show,
|
|
8
|
+
splitProps,
|
|
9
|
+
useContext,
|
|
10
|
+
} from "solid-js";
|
|
11
|
+
import { cn } from "../lib/utils.js";
|
|
12
|
+
|
|
13
|
+
/** The attribute (without `data-`) that marks the active item: Kobalte's, or the caller's own. */
|
|
14
|
+
export type SelectionMarker = "pressed" | "selected" | "highlighted" | "lit";
|
|
15
|
+
|
|
16
|
+
const SelectionContext = createContext<SelectionMarker>();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The glass behind an item while it is the active one. Render it as the first child of every
|
|
20
|
+
* item inside a `SelectionScope`; CSS shows the one whose item carries the scope's marker, so
|
|
21
|
+
* layout keeps it in place and nothing measures it at rest. Renders nothing outside a scope.
|
|
22
|
+
*/
|
|
23
|
+
export function SelectionHighlight() {
|
|
24
|
+
const marker = useContext(SelectionContext);
|
|
25
|
+
return (
|
|
26
|
+
<Show when={marker}>
|
|
27
|
+
{(on) => (
|
|
28
|
+
<span
|
|
29
|
+
data-selection-highlight=""
|
|
30
|
+
data-on={on()}
|
|
31
|
+
data-sliding-indicator=""
|
|
32
|
+
aria-hidden="true"
|
|
33
|
+
class="glass glass-tint"
|
|
34
|
+
/>
|
|
35
|
+
)}
|
|
36
|
+
</Show>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const DEFAULT_DURATION_MS = 220;
|
|
41
|
+
// Kobalte clears a menu row's highlight on pointerleave and sets the next on pointermove.
|
|
42
|
+
const GAP_MS = 100;
|
|
43
|
+
// Squash-and-stretch as a pixel budget per axis, so a big item does not deform more.
|
|
44
|
+
const STRETCH_PX = 6;
|
|
45
|
+
const SQUASH_PX = 6;
|
|
46
|
+
const DEFORM_MAX = 0.14;
|
|
47
|
+
|
|
48
|
+
/** Centre and size in the scope's own content pixels. */
|
|
49
|
+
type Box = { x: number; y: number; width: number; height: number };
|
|
50
|
+
|
|
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
|
+
function boxIn(root: HTMLElement, el: Element, size: { width: number; height: number }): Box {
|
|
60
|
+
const outer = root.getBoundingClientRect();
|
|
61
|
+
const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
|
|
62
|
+
const sy = root.offsetHeight > 0 ? outer.height / root.offsetHeight : 1;
|
|
63
|
+
const rect = el.getBoundingClientRect();
|
|
64
|
+
return {
|
|
65
|
+
x: (rect.left + rect.width / 2 - outer.left) / sx - root.clientLeft + root.scrollLeft,
|
|
66
|
+
y: (rect.top + rect.height / 2 - outer.top) / sy - root.clientTop + root.scrollTop,
|
|
67
|
+
width: size.width,
|
|
68
|
+
height: size.height,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function itemBox(root: HTMLElement, item: HTMLElement): Box | undefined {
|
|
73
|
+
if (!item.isConnected) return undefined;
|
|
74
|
+
const box = boxIn(root, item, { width: item.offsetWidth, height: item.offsetHeight });
|
|
75
|
+
return box.width > 0 && box.height > 0 ? box : undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function flyerBox(root: HTMLElement, flyer: HTMLElement): Box {
|
|
79
|
+
const outer = root.getBoundingClientRect();
|
|
80
|
+
const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
|
|
81
|
+
const sy = root.offsetHeight > 0 ? outer.height / root.offsetHeight : 1;
|
|
82
|
+
const rect = flyer.getBoundingClientRect();
|
|
83
|
+
return boxIn(root, flyer, { width: rect.width / sx, height: rect.height / sy });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function highlightOf(item: Element): Element | null {
|
|
87
|
+
return item.querySelector(":scope > [data-selection-highlight]");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function activeIn(root: HTMLElement, attribute: string): HTMLElement | undefined {
|
|
91
|
+
let active: HTMLElement | undefined;
|
|
92
|
+
for (const el of root.querySelectorAll<HTMLElement>(`[${attribute}]`)) {
|
|
93
|
+
if (el.closest("[data-selection-scope]") === root && highlightOf(el)) active = el;
|
|
94
|
+
}
|
|
95
|
+
return active;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function writeStyle(el: HTMLElement, name: string, value: string) {
|
|
99
|
+
if (el.style.getPropertyValue(name) !== value) el.style.setProperty(name, value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** One flight at a time; every way a flight ends goes through `settle`. */
|
|
103
|
+
function createFlight(root: HTMLElement, flyer: HTMLElement) {
|
|
104
|
+
let generation = 0;
|
|
105
|
+
let running: Animation[] = [];
|
|
106
|
+
let landing: Element | undefined;
|
|
107
|
+
|
|
108
|
+
const stop = () => {
|
|
109
|
+
for (const animation of running) animation.cancel();
|
|
110
|
+
running = [];
|
|
111
|
+
landing?.removeAttribute("data-landing");
|
|
112
|
+
landing = undefined;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const settle = (of = generation) => {
|
|
116
|
+
if (of !== generation) return;
|
|
117
|
+
stop();
|
|
118
|
+
flyer.removeAttribute("data-flying");
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const start = (from: Box, item: HTMLElement) => {
|
|
122
|
+
generation += 1;
|
|
123
|
+
const current = generation;
|
|
124
|
+
stop();
|
|
125
|
+
const target = highlightOf(item);
|
|
126
|
+
const to = itemBox(root, item);
|
|
127
|
+
const duration = durationMs(root);
|
|
128
|
+
if (!target || !to || duration <= 0) return settle(current);
|
|
129
|
+
|
|
130
|
+
// Read before any write: a computed border-radius after a size write forces a second layout.
|
|
131
|
+
const look = getComputedStyle(item);
|
|
132
|
+
const radius = look.borderRadius;
|
|
133
|
+
const tone = look.getPropertyValue("--selection-tone").trim();
|
|
134
|
+
const left = to.x - to.width / 2;
|
|
135
|
+
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
|
+
const dx = from.x - to.x;
|
|
144
|
+
const dy = from.y - to.y;
|
|
145
|
+
const kx = from.width / to.width;
|
|
146
|
+
const ky = from.height / to.height;
|
|
147
|
+
const alongX = Math.abs(dx) >= Math.abs(dy);
|
|
148
|
+
let peakX = (kx + 1) / 2;
|
|
149
|
+
let peakY = (ky + 1) / 2;
|
|
150
|
+
if (Math.hypot(dx, dy) >= 1) {
|
|
151
|
+
const stretch = 1 + Math.min(DEFORM_MAX, STRETCH_PX / (alongX ? to.width : to.height));
|
|
152
|
+
const pinch = 1 - Math.min(DEFORM_MAX, SQUASH_PX / (alongX ? to.height : to.width));
|
|
153
|
+
peakX *= alongX ? stretch : pinch;
|
|
154
|
+
peakY *= alongX ? pinch : stretch;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
landing = target;
|
|
158
|
+
target.setAttribute("data-landing", "");
|
|
159
|
+
flyer.setAttribute("data-flying", "");
|
|
160
|
+
const timing: KeyframeAnimationOptions = { duration, easing: "ease-in-out" };
|
|
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);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return { settle, start, flying: () => flyer.hasAttribute("data-flying") };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface SelectionScopeProps extends Omit<ComponentProps<"div">, "style"> {
|
|
180
|
+
marker: SelectionMarker;
|
|
181
|
+
/** CSS colour for the highlight's glass. Default `var(--material-accent)`. */
|
|
182
|
+
tone?: string;
|
|
183
|
+
style?: JSX.CSSProperties;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Wraps items that each render a `SelectionHighlight`. When the marker moves to another item,
|
|
188
|
+
* one flyer animates from the old item to the new one and hands off to its resting highlight.
|
|
189
|
+
*/
|
|
190
|
+
export function SelectionScope(props: SelectionScopeProps) {
|
|
191
|
+
const [local, rest] = splitProps(props, ["marker", "tone", "class", "style", "children", "ref"]);
|
|
192
|
+
let root: HTMLDivElement | undefined;
|
|
193
|
+
let flyer: HTMLSpanElement | undefined;
|
|
194
|
+
const setRoot = (el: HTMLDivElement) => {
|
|
195
|
+
root = el;
|
|
196
|
+
const forwarded = local.ref;
|
|
197
|
+
if (typeof forwarded === "function") forwarded(el);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
onMount(() => {
|
|
201
|
+
const scope = root;
|
|
202
|
+
const travel = flyer;
|
|
203
|
+
if (!scope || !travel) return;
|
|
204
|
+
const attribute = `data-${local.marker}`;
|
|
205
|
+
const flight = createFlight(scope, travel);
|
|
206
|
+
let active = activeIn(scope, attribute);
|
|
207
|
+
let left: { item: HTMLElement; box: Box | undefined; at: number } | undefined;
|
|
208
|
+
|
|
209
|
+
const observer = new MutationObserver(() => {
|
|
210
|
+
const next = activeIn(scope, attribute);
|
|
211
|
+
if (next === active) return;
|
|
212
|
+
const previous = active;
|
|
213
|
+
active = next;
|
|
214
|
+
if (!next) {
|
|
215
|
+
if (previous) {
|
|
216
|
+
const box = flight.flying() ? flyerBox(scope, travel) : undefined;
|
|
217
|
+
left = { item: previous, box, at: performance.now() };
|
|
218
|
+
}
|
|
219
|
+
flight.settle();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const recent = left && performance.now() - left.at <= GAP_MS ? left : undefined;
|
|
223
|
+
left = undefined;
|
|
224
|
+
const from = flight.flying()
|
|
225
|
+
? flyerBox(scope, travel)
|
|
226
|
+
: previous
|
|
227
|
+
? itemBox(scope, previous)
|
|
228
|
+
: recent
|
|
229
|
+
? (recent.box ?? itemBox(scope, recent.item))
|
|
230
|
+
: undefined;
|
|
231
|
+
if (from) flight.start(from, next);
|
|
232
|
+
else flight.settle();
|
|
233
|
+
});
|
|
234
|
+
observer.observe(scope, { subtree: true, attributes: true, attributeFilter: [attribute] });
|
|
235
|
+
onCleanup(() => {
|
|
236
|
+
observer.disconnect();
|
|
237
|
+
flight.settle();
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<div
|
|
243
|
+
ref={setRoot}
|
|
244
|
+
data-selection-scope=""
|
|
245
|
+
class={cn("relative isolate", local.class)}
|
|
246
|
+
style={local.tone ? { ...local.style, "--selection-tone": local.tone } : local.style}
|
|
247
|
+
{...rest}
|
|
248
|
+
>
|
|
249
|
+
<SelectionContext.Provider value={local.marker}>{local.children}</SelectionContext.Provider>
|
|
250
|
+
<span
|
|
251
|
+
ref={flyer}
|
|
252
|
+
data-selection-flyer=""
|
|
253
|
+
data-sliding-indicator=""
|
|
254
|
+
aria-hidden="true"
|
|
255
|
+
class="glass glass-tint"
|
|
256
|
+
/>
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
@@ -75,6 +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 Use `SelectionScope` with a `SelectionHighlight` in each item; removed in 2.0. */
|
|
78
79
|
export function SlidingIndicator(props: SlidingIndicatorProps) {
|
|
79
80
|
const [local, rest] = splitProps(props, [
|
|
80
81
|
"active",
|
|
@@ -266,6 +267,7 @@ export function SlidingIndicator(props: SlidingIndicatorProps) {
|
|
|
266
267
|
syncObservedItems();
|
|
267
268
|
queueMicrotask(measure);
|
|
268
269
|
});
|
|
270
|
+
// observer-attributes-ok: deprecated; any caller selector must keep working, and style-only batches are skipped
|
|
269
271
|
mo.observe(containerRef, {
|
|
270
272
|
childList: true,
|
|
271
273
|
subtree: !!local.activeSelector,
|
package/src/solid/tabs.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
|
6
6
|
import { SEGMENT_ITEM } from "../lib/segment-classes.js";
|
|
7
7
|
import { cn } from "../lib/utils.js";
|
|
8
8
|
import { Icon } from "./icon.js";
|
|
9
|
-
import {
|
|
9
|
+
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
10
10
|
|
|
11
11
|
/** `split`: the root is `display: contents`, so a host (a modal panel) lays the
|
|
12
12
|
* list and the content out in its own regions while the tab state still spans
|
|
@@ -50,13 +50,9 @@ const TabsList: Component<ComponentProps<typeof TabsPrimitive.List>> = (props) =
|
|
|
50
50
|
>
|
|
51
51
|
{/* w-max so triggers keep their natural width and the track scrolls;
|
|
52
52
|
w-full alone squeezed them past the rounded edge, unreachable. */}
|
|
53
|
-
<
|
|
54
|
-
activeSelector="[data-selected]"
|
|
55
|
-
indicatorClass="rounded-md"
|
|
56
|
-
class="flex h-full w-max min-w-full items-center gap-1"
|
|
57
|
-
>
|
|
53
|
+
<SelectionScope marker="selected" class="flex h-full w-max min-w-full items-center gap-1">
|
|
58
54
|
{local.children}
|
|
59
|
-
</
|
|
55
|
+
</SelectionScope>
|
|
60
56
|
</TabsPrimitive.List>
|
|
61
57
|
);
|
|
62
58
|
};
|
|
@@ -72,12 +68,13 @@ const TabsTrigger: Component<ComponentProps<typeof TabsPrimitive.Trigger> & { ic
|
|
|
72
68
|
class={cn(
|
|
73
69
|
SEGMENT_ITEM,
|
|
74
70
|
PRESS_DIP,
|
|
75
|
-
"hover:text-(--material-accent)/80 data-[selected]:text-(--material-accent)",
|
|
71
|
+
"relative isolate hover:text-(--material-accent)/80 data-[selected]:text-(--material-accent)",
|
|
76
72
|
local.icon && "h-auto flex-1 flex-col gap-1 py-2 text-xs",
|
|
77
73
|
local.class,
|
|
78
74
|
)}
|
|
79
75
|
{...others}
|
|
80
76
|
>
|
|
77
|
+
<SelectionHighlight />
|
|
81
78
|
{local.icon && (
|
|
82
79
|
<Icon
|
|
83
80
|
data-slot="tabs-trigger-icon"
|
|
@@ -14,13 +14,10 @@ import {
|
|
|
14
14
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
15
15
|
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
16
16
|
import { cn } from "../lib/utils.js";
|
|
17
|
-
import {
|
|
17
|
+
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
18
18
|
import { toggleVariants } from "./toggle.js";
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
// single-select mode the indicator paints the selected segment, so items go
|
|
22
|
-
// transparent when pressed (else they double-paint). Multi-select has no single
|
|
23
|
-
// active item, so items keep their own pressed background and no indicator renders.
|
|
20
|
+
// Single-select paints the pressed segment with the selection highlight; multi-select has none.
|
|
24
21
|
type ToggleGroupContextValue = VariantProps<typeof toggleVariants> & { sliding: boolean };
|
|
25
22
|
|
|
26
23
|
const ToggleGroupContext = createContext<ToggleGroupContextValue>({
|
|
@@ -74,11 +71,9 @@ const ToggleGroup: ParentComponent<
|
|
|
74
71
|
<Show when={sliding()} fallback={local.children}>
|
|
75
72
|
{/* w-full, not w-fit: a shrink-to-fit root still sizes to content, and a
|
|
76
73
|
`class="w-full"` root can finally let its flex-1 items share the width. */}
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
indicatorTone={local.tone}
|
|
81
|
-
wrapped={!local.scroll}
|
|
74
|
+
<SelectionScope
|
|
75
|
+
marker="pressed"
|
|
76
|
+
tone={local.tone}
|
|
82
77
|
class={
|
|
83
78
|
local.scroll
|
|
84
79
|
? "flex w-max flex-nowrap items-center"
|
|
@@ -86,7 +81,7 @@ const ToggleGroup: ParentComponent<
|
|
|
86
81
|
}
|
|
87
82
|
>
|
|
88
83
|
{local.children}
|
|
89
|
-
</
|
|
84
|
+
</SelectionScope>
|
|
90
85
|
</Show>
|
|
91
86
|
</ToggleGroupContext.Provider>
|
|
92
87
|
</ToggleGroupPrimitive>
|
|
@@ -96,7 +91,7 @@ const ToggleGroup: ParentComponent<
|
|
|
96
91
|
const ToggleGroupItem: Component<
|
|
97
92
|
ComponentProps<typeof ToggleGroupPrimitive.Item> & VariantProps<typeof toggleVariants>
|
|
98
93
|
> = (props) => {
|
|
99
|
-
const [local, rest] = splitProps(props, ["class", "variant", "size"] as const);
|
|
94
|
+
const [local, rest] = splitProps(props, ["class", "variant", "size", "children"] as const);
|
|
100
95
|
const context = useContext(ToggleGroupContext);
|
|
101
96
|
|
|
102
97
|
return (
|
|
@@ -110,19 +105,26 @@ const ToggleGroupItem: Component<
|
|
|
110
105
|
size: context.size || local.size,
|
|
111
106
|
}),
|
|
112
107
|
// Wrapping is plain CSS: an item never shrinks below its label, so a row that runs out of width breaks.
|
|
113
|
-
"min-w-max flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l",
|
|
114
|
-
//
|
|
115
|
-
// item needs no pressed fill of its own and hover only tints the text.
|
|
116
|
-
// Multi-select has no single indicator, so each pressed segment carries
|
|
117
|
-
// its own neutral fill; hover still tints text only, since a fill there
|
|
118
|
-
// would read as a second, squarer selection.
|
|
108
|
+
"relative isolate min-w-max flex-1 shrink-0 rounded-md px-4 shadow-none focus:z-10 focus-visible:z-10 data-[variant=outline]:border-l-0 data-[variant=outline]:first-of-type:border-l",
|
|
109
|
+
// A hover fill would read as a second, squarer selection, so hover only tints the text.
|
|
119
110
|
context.sliding
|
|
120
111
|
? "hover:text-(--material-accent)"
|
|
121
112
|
: "data-[pressed]:bg-muted data-[pressed]:text-foreground not-data-[pressed]:hover:text-(--material-accent)",
|
|
122
113
|
local.class,
|
|
123
114
|
)}
|
|
124
115
|
{...rest}
|
|
125
|
-
|
|
116
|
+
>
|
|
117
|
+
{(state) => {
|
|
118
|
+
// Each read of a JSX child getter builds it again.
|
|
119
|
+
const content = local.children;
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
<SelectionHighlight />
|
|
123
|
+
{typeof content === "function" ? content(state) : content}
|
|
124
|
+
</>
|
|
125
|
+
);
|
|
126
|
+
}}
|
|
127
|
+
</ToggleGroupPrimitive.Item>
|
|
126
128
|
);
|
|
127
129
|
};
|
|
128
130
|
|
package/src/solid/toggle.tsx
CHANGED
|
@@ -26,7 +26,7 @@ const toggleVariants = cva({
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
/* The hover fill lives here, not in the shared variants: a ToggleGroupItem
|
|
29
|
-
* takes its pressed paint from the group's
|
|
29
|
+
* takes its pressed paint from the group's selection highlight, and
|
|
30
30
|
* `:not([data-pressed]):hover` (0,3,0) outranks any plain `:hover` the group
|
|
31
31
|
* adds to cancel it. Unpressed only, because a background utility is a no-op
|
|
32
32
|
* once `data-[pressed]:glass` engages, so the pressed hover bumps a knob. */
|
package/src/styles/globals.css
CHANGED
|
@@ -768,7 +768,7 @@
|
|
|
768
768
|
translate: 0 0;
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
|
-
.gh-stagger > :not([role="group"]),
|
|
771
|
+
.gh-stagger > :not([role="group"], [data-selection-flyer]),
|
|
772
772
|
.gh-stagger > [role="group"] > * {
|
|
773
773
|
animation: stagger-in calc(var(--duration-morph) * 0.5) var(--ease-emphasis) both;
|
|
774
774
|
animation-delay: calc(var(--stagger-base, 80ms) + var(--i, 0) * var(--stagger-step, 60ms));
|
|
@@ -792,6 +792,53 @@
|
|
|
792
792
|
--i: 6;
|
|
793
793
|
}
|
|
794
794
|
|
|
795
|
+
/* Selection (solid/selection.tsx). Plain CSS on data attributes: a published widget compiles its
|
|
796
|
+
* utilities from the ui source it was built against, so a new utility here would be missing there. */
|
|
797
|
+
[data-selection-highlight],
|
|
798
|
+
[data-selection-flyer] {
|
|
799
|
+
position: absolute;
|
|
800
|
+
z-index: -1;
|
|
801
|
+
pointer-events: none;
|
|
802
|
+
--glass-tone: var(--selection-tone, var(--material-accent));
|
|
803
|
+
}
|
|
804
|
+
/* Hidden, not removed: a display swap would lay out on every selection change. */
|
|
805
|
+
[data-selection-highlight] {
|
|
806
|
+
inset: var(--selection-inset, 0);
|
|
807
|
+
visibility: hidden;
|
|
808
|
+
}
|
|
809
|
+
/* Layered, so a material's own corners (Ink's hand-drawn ones are unlayered) still win. */
|
|
810
|
+
@layer base {
|
|
811
|
+
[data-selection-highlight] {
|
|
812
|
+
border-radius: inherit;
|
|
813
|
+
}
|
|
814
|
+
[data-selection-flyer] {
|
|
815
|
+
border-radius: var(--selection-radius);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
[data-pressed] > [data-selection-highlight][data-on="pressed"],
|
|
819
|
+
[data-selected] > [data-selection-highlight][data-on="selected"],
|
|
820
|
+
[data-highlighted] > [data-selection-highlight][data-on="highlighted"],
|
|
821
|
+
[data-lit] > [data-selection-highlight][data-on="lit"] {
|
|
822
|
+
visibility: inherit;
|
|
823
|
+
}
|
|
824
|
+
[data-on][data-selection-highlight][data-landing] {
|
|
825
|
+
visibility: hidden;
|
|
826
|
+
}
|
|
827
|
+
/* Its transparent border is part of the segment the old indicator covered. */
|
|
828
|
+
[data-slot="toggle-group-item"] {
|
|
829
|
+
--selection-inset: -1px;
|
|
830
|
+
}
|
|
831
|
+
/* Out of layout at rest: a hidden box at its last place would still stretch a scroller. */
|
|
832
|
+
[data-selection-flyer] {
|
|
833
|
+
top: 0;
|
|
834
|
+
left: 0;
|
|
835
|
+
display: none;
|
|
836
|
+
transition: none;
|
|
837
|
+
}
|
|
838
|
+
[data-selection-flyer][data-flying] {
|
|
839
|
+
display: block;
|
|
840
|
+
}
|
|
841
|
+
|
|
795
842
|
/* Icon: the box a glyph sits in, sized by its width/height attributes. */
|
|
796
843
|
svg[data-slot="icon"] {
|
|
797
844
|
display: inline-block;
|
package/src/styles/theme.css
CHANGED
|
@@ -101,22 +101,13 @@
|
|
|
101
101
|
* expand to the bottom rather than a separate box dropping in. No scale, so the
|
|
102
102
|
* option text never squishes; opacity fades in slightly so it isn't a hard wipe. */
|
|
103
103
|
@keyframes select-in {
|
|
104
|
-
/* The trigger opens on pointerdown and the panel appears under the cursor, so
|
|
105
|
-
* the same click's pointerup would land on an option (press-drag-select) and
|
|
106
|
-
* instantly pick/close. Ignore pointer events for the open animation so that
|
|
107
|
-
* release passes through and the panel stays open; a fresh click then selects. */
|
|
108
104
|
from {
|
|
109
105
|
opacity: 0;
|
|
110
106
|
clip-path: inset(0 0 100% 0 round var(--radius-md));
|
|
111
|
-
pointer-events: none;
|
|
112
|
-
}
|
|
113
|
-
90% {
|
|
114
|
-
pointer-events: none;
|
|
115
107
|
}
|
|
116
108
|
to {
|
|
117
109
|
opacity: 1;
|
|
118
110
|
clip-path: inset(0 0 0 0 round var(--radius-md));
|
|
119
|
-
pointer-events: auto;
|
|
120
111
|
}
|
|
121
112
|
}
|
|
122
113
|
@keyframes morph-in {
|
|
@@ -127,18 +118,13 @@
|
|
|
127
118
|
calc(100% - var(--morph-y, 0px) - var(--morph-h, 2.5rem)) var(--morph-x, 0px) round
|
|
128
119
|
var(--morph-radius, 9999px)
|
|
129
120
|
);
|
|
130
|
-
pointer-events: none;
|
|
131
121
|
}
|
|
132
122
|
35% {
|
|
133
123
|
opacity: 1;
|
|
134
124
|
}
|
|
135
|
-
90% {
|
|
136
|
-
pointer-events: none;
|
|
137
|
-
}
|
|
138
125
|
to {
|
|
139
126
|
opacity: 1;
|
|
140
127
|
clip-path: inset(0 0 0 0 round var(--radius-md));
|
|
141
|
-
pointer-events: auto;
|
|
142
128
|
}
|
|
143
129
|
}
|
|
144
130
|
@keyframes morph-out {
|
|
@@ -298,6 +284,7 @@
|
|
|
298
284
|
--duration-micro: 120ms;
|
|
299
285
|
--duration-state: 160ms;
|
|
300
286
|
--duration-expand: 200ms;
|
|
287
|
+
--duration-slide: 220ms;
|
|
301
288
|
/* The hold fill: HOLD_MS - HOLD_GRACE_MS (lib/hold.ts), so it completes as the hold fires. */
|
|
302
289
|
--duration-hold: 250ms;
|
|
303
290
|
/* Ambient motion is an event (SPEC motion rule 5): 1 while the host holds
|
|
@@ -589,6 +576,7 @@ html[data-motion="live"] {
|
|
|
589
576
|
--duration-expand: 0ms;
|
|
590
577
|
--duration-morph: 0ms;
|
|
591
578
|
--duration-hold: 0ms;
|
|
579
|
+
--duration-slide: 0ms;
|
|
592
580
|
}
|
|
593
581
|
/* tw-animate enter/exit classes carry their own fallback duration. */
|
|
594
582
|
.animate-in,
|
|
@@ -610,6 +598,15 @@ html[data-motion="live"] {
|
|
|
610
598
|
}
|
|
611
599
|
|
|
612
600
|
/* Accessibility: minimize animations/transitions when reduce-motion is active */
|
|
601
|
+
/* The tokens too, so motion timed in JS (Web Animations) stops as well. */
|
|
602
|
+
.reduce-motion {
|
|
603
|
+
--duration-micro: 0ms;
|
|
604
|
+
--duration-state: 0ms;
|
|
605
|
+
--duration-expand: 0ms;
|
|
606
|
+
--duration-morph: 0ms;
|
|
607
|
+
--duration-hold: 0ms;
|
|
608
|
+
--duration-slide: 0ms;
|
|
609
|
+
}
|
|
613
610
|
.reduce-motion,
|
|
614
611
|
.reduce-motion * {
|
|
615
612
|
animation-duration: 0.01ms !important;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// happy-dom reports animationName as "", which solid-presence reads as an animation that never ends.
|
|
2
|
+
export function installSettledAnimations(): void {
|
|
3
|
+
const realGetComputedStyle = window.getComputedStyle.bind(window);
|
|
4
|
+
|
|
5
|
+
window.getComputedStyle = ((el: Element, pseudo?: string | null) => {
|
|
6
|
+
const style = realGetComputedStyle(el, pseudo);
|
|
7
|
+
if (style.animationName) return style;
|
|
8
|
+
return new Proxy(style, {
|
|
9
|
+
get: (target, key) => {
|
|
10
|
+
if (key === "animationName") return "none";
|
|
11
|
+
const value = Reflect.get(target, key);
|
|
12
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}) as typeof window.getComputedStyle;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
export function installDenyFetch(): void {
|
|
4
|
+
let denied: string[] = [];
|
|
5
|
+
|
|
6
|
+
const deny = (input: URL | RequestInfo): Promise<Response> => {
|
|
7
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
8
|
+
denied.push(url);
|
|
9
|
+
return Promise.reject(new Error(`fetch denied in tests: stub the route for ${url}`));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
globalThis.fetch = Object.assign(deny, { preconnect: () => {} });
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
const urls = denied;
|
|
16
|
+
denied = [];
|
|
17
|
+
if (urls.length > 0) throw new Error(`unstubbed fetch: ${[...new Set(urls)].join(", ")}`);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { onTestFinished, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
export function useFakeTime(config?: {
|
|
4
|
+
toFake?: NonNullable<Parameters<typeof vi.useFakeTimers>[0]>["toFake"];
|
|
5
|
+
}): void {
|
|
6
|
+
vi.useFakeTimers(config);
|
|
7
|
+
onTestFinished(() => {
|
|
8
|
+
vi.useRealTimers();
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useSystemTime(at: number | Date): void {
|
|
13
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
14
|
+
vi.setSystemTime(at);
|
|
15
|
+
onTestFinished(() => {
|
|
16
|
+
vi.useRealTimers();
|
|
17
|
+
});
|
|
18
|
+
}
|