@glasshome/ui 1.41.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/SPEC.md +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/anchor-placement.d.ts +34 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +26 -0
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +32 -0
- package/dist/lib/behavior/controllable.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +13 -0
- package/dist/lib/behavior/focus-scope.d.ts +24 -0
- package/dist/lib/behavior/hide-outside.d.ts +7 -0
- package/dist/lib/behavior/layer-stack.d.ts +34 -0
- package/dist/lib/behavior/menu.d.ts +59 -0
- package/dist/lib/behavior/modal-root.d.ts +68 -0
- package/dist/lib/behavior/polymorphic.d.ts +6 -0
- package/dist/lib/behavior/presence.d.ts +18 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/behavior/solid.d.ts +13 -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 +5 -2
- package/dist/lib/overlay-classes.d.ts +4 -0
- package/dist/lib/page-cover.d.ts +8 -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 -43
- 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/alert-dialog.d.ts +5 -8
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
- package/dist/solid/bottom-sheet/constants.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 +53 -16
- package/dist/solid/dialog.d.ts +7 -10
- 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 +5 -2
- package/dist/solid/index.js +8671 -14317
- 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 +3 -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 +6 -9
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/stale-veil.d.ts +7 -0
- package/dist/solid/tabs.d.ts +28 -9
- package/dist/solid/toggle-group.d.ts +30 -5
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +71 -9
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
- package/package.json +6 -7
- package/src/index.ts +1 -0
- package/src/lib/anchor-placement.ts +77 -4
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +106 -0
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +218 -0
- package/src/lib/behavior/controllable.ts +22 -0
- package/src/lib/behavior/dismiss.ts +185 -0
- package/src/lib/behavior/focus-scope.ts +227 -0
- package/src/lib/behavior/hide-outside.ts +85 -0
- package/src/lib/behavior/layer-stack.ts +150 -0
- package/src/lib/behavior/menu.ts +470 -0
- package/src/lib/behavior/modal-root.tsx +452 -0
- package/src/lib/behavior/polymorphic.tsx +30 -0
- package/src/lib/behavior/presence.ts +89 -0
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/behavior/solid.ts +30 -0
- package/src/lib/clipboard.ts +4 -4
- 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 +33 -8
- package/src/lib/overlay-classes.ts +8 -3
- package/src/lib/page-cover.ts +47 -0
- 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 -136
- 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/alert-dialog.tsx +36 -85
- package/src/solid/area-picker.tsx +5 -3
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/badge.tsx +5 -5
- package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
- package/src/solid/bottom-sheet/constants.ts +3 -1
- package/src/solid/bottom-sheet/drag-controller.ts +11 -0
- package/src/solid/breadcrumb.tsx +4 -4
- package/src/solid/button-group.tsx +4 -4
- package/src/solid/button.tsx +12 -6
- package/src/solid/card.tsx +5 -4
- 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 +287 -86
- package/src/solid/dialog-parts.tsx +135 -46
- package/src/solid/dialog.tsx +44 -76
- package/src/solid/dock-edit.tsx +5 -4
- package/src/solid/dock.tsx +6 -5
- package/src/solid/dropdown-menu.tsx +252 -107
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +5 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +9 -9
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +288 -21
- package/src/solid/icon-picker.tsx +2 -1
- package/src/solid/image-picker.tsx +6 -5
- package/src/solid/index.ts +5 -4
- package/src/solid/input-group.tsx +7 -5
- package/src/solid/input-otp.tsx +2 -1
- package/src/solid/item.tsx +5 -5
- package/src/solid/logo.tsx +5 -4
- package/src/solid/menu-parts.tsx +619 -145
- package/src/solid/option-card.tsx +6 -10
- package/src/solid/picker-row.tsx +10 -5
- package/src/solid/picker-search.tsx +2 -1
- package/src/solid/popover.tsx +424 -71
- 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 +10 -10
- 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 +48 -80
- 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/spotlight.tsx +23 -11
- package/src/solid/stale-veil.tsx +20 -0
- package/src/solid/switch.tsx +8 -6
- package/src/solid/tabs.tsx +377 -52
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +237 -95
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +285 -26
- package/src/styles/globals.css +64 -10
- package/src/styles/theme.css +12 -4
- package/src/tokens/material.ts +11 -2
- package/dist/lib/when-animations-settle.d.ts +0 -4
- package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
- package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
- package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
- package/src/lib/when-animations-settle.ts +0 -12
- package/src/solid/bottom-sheet/focus-trap.ts +0 -63
- package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
- package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
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
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { Dialog as DialogPrimitive, useDialogContext } from "@kobalte/core/dialog";
|
|
2
1
|
import { usePortalMount } from "./portal-mount.js";
|
|
3
2
|
import type { VariantProps } from "cva";
|
|
4
3
|
import {
|
|
5
4
|
children,
|
|
6
5
|
type Component,
|
|
7
|
-
type ComponentProps,
|
|
8
6
|
type JSX,
|
|
9
7
|
type ParentComponent,
|
|
10
8
|
Show,
|
|
11
|
-
createSignal,
|
|
12
9
|
splitProps,
|
|
13
10
|
} from "solid-js";
|
|
11
|
+
import { ModalFrame, useDialogContext } from "../lib/behavior/modal-root.js";
|
|
14
12
|
import { buttonVariants } from "../lib/button-variants.js";
|
|
15
|
-
import { inShadowRoot, shadowLayer } from "../lib/shadow-layer.js";
|
|
16
13
|
import { Z_CLASS } from "../lib/layers.js";
|
|
17
14
|
import { SCRIM_MOTION } from "../lib/motion-classes.js";
|
|
18
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
OVERLAY_SURFACE,
|
|
17
|
+
SCRIM_CLASS,
|
|
18
|
+
SCRIM_CONTAIN,
|
|
19
|
+
SCROLL_CONTAIN,
|
|
20
|
+
} from "../lib/overlay-classes.js";
|
|
19
21
|
import { cn } from "../lib/utils.js";
|
|
20
22
|
import {
|
|
21
23
|
createModalDismiss,
|
|
22
24
|
createModalParts,
|
|
23
|
-
|
|
25
|
+
createModalRootSkin,
|
|
26
|
+
createModalTextParts,
|
|
24
27
|
MODAL_MAX_H,
|
|
25
|
-
|
|
28
|
+
type ModalContentProps,
|
|
26
29
|
type ModalDismissProps,
|
|
27
|
-
|
|
30
|
+
ModalCover,
|
|
28
31
|
} from "./dialog-parts.js";
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
* refcounted page lock every modal family shares. */
|
|
32
|
-
const Sheet: ParentComponent<ComponentProps<typeof DialogPrimitive>> = (props) => {
|
|
33
|
-
const mount = usePortalMount();
|
|
34
|
-
return <DialogPrimitive modal={!inShadowRoot(mount)} {...props} preventScroll={false} />;
|
|
35
|
-
};
|
|
33
|
+
const Sheet = createModalRootSkin("dialog");
|
|
36
34
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const {
|
|
36
|
+
Trigger: SheetTrigger,
|
|
37
|
+
Title: SheetTitle,
|
|
38
|
+
Description: SheetDescription,
|
|
39
|
+
} = createModalTextParts("sheet");
|
|
40
40
|
|
|
41
41
|
type SheetCloseProps = ModalDismissProps &
|
|
42
42
|
Partial<Pick<VariantProps<typeof buttonVariants>, "variant" | "size">>;
|
|
43
43
|
|
|
44
|
-
const SheetDismiss = createModalDismiss("sheet-close");
|
|
44
|
+
const SheetDismiss = createModalDismiss("sheet-close", useDialogContext);
|
|
45
45
|
|
|
46
46
|
/** Already the outline button; see DialogClose on why `as={Button}` is wrong. */
|
|
47
47
|
const SheetClose: ParentComponent<SheetCloseProps> = (props) => {
|
|
@@ -59,38 +59,29 @@ const SheetClose: ParentComponent<SheetCloseProps> = (props) => {
|
|
|
59
59
|
);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
const
|
|
63
|
-
const [local, rest] = splitProps(props, ["class"]);
|
|
64
|
-
return (
|
|
65
|
-
<DialogPrimitive.Overlay
|
|
66
|
-
data-slot="sheet-overlay"
|
|
67
|
-
class={cn(
|
|
68
|
-
`${SCRIM_MOTION} pointer-events-auto fixed inset-0 select-none ${Z_CLASS.overlay} ${SCRIM_CLASS}`,
|
|
69
|
-
local.class,
|
|
70
|
-
)}
|
|
71
|
-
{...rest}
|
|
72
|
-
/>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
62
|
+
const SHEET_SCRIM = `${SCRIM_MOTION} pointer-events-auto fixed inset-0 select-none ${Z_CLASS.overlay} ${SCRIM_CLASS} ${SCRIM_CONTAIN}`;
|
|
75
63
|
|
|
76
64
|
/* A viewport-tall panel would stretch the percentage-sized sheen into a small
|
|
77
65
|
* blob over a flat field; pinned lengths match the ellipse a dialog gets. */
|
|
78
66
|
const SHEET_SURFACE = `${OVERLAY_SURFACE} [--glass-sheen:600px_300px]`;
|
|
79
67
|
|
|
80
|
-
const SHEET_PANEL = `fixed ${Z_CLASS.overlay} flex flex-col overflow-hidden rounded-lg ${SHEET_SURFACE} transition ease-in-out focus:outline-none focus-visible:outline-none data-[closed]:animate-out data-[expanded]:animate-in data-[closed]:duration-300 data-[expanded]:duration-500`;
|
|
68
|
+
const SHEET_PANEL = `fixed ${Z_CLASS.overlay} flex flex-col overflow-hidden ${SCROLL_CONTAIN} rounded-lg ${SHEET_SURFACE} transition ease-in-out focus:outline-none focus-visible:outline-none data-[closed]:animate-out data-[expanded]:animate-in data-[closed]:duration-300 data-[expanded]:duration-500`;
|
|
69
|
+
|
|
70
|
+
/* The data-[closed] duration in SHEET_PANEL. */
|
|
71
|
+
const SHEET_EXIT_MS = 300;
|
|
81
72
|
|
|
82
73
|
const SHEET_SIDE = {
|
|
83
74
|
right:
|
|
84
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",
|
|
85
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",
|
|
86
77
|
top: `data-[closed]:slide-out-to-top data-[expanded]:slide-in-from-top inset-x-3 top-3 ${MODAL_MAX_H}`,
|
|
87
|
-
/** @deprecated
|
|
78
|
+
/** @deprecated `BottomSheet` or `ResponsiveDialog`; removed in 2.0.0. */
|
|
88
79
|
bottom: `data-[closed]:slide-out-to-bottom data-[expanded]:slide-in-from-bottom inset-x-3 bottom-3 ${MODAL_MAX_H}`,
|
|
89
80
|
} as const;
|
|
90
81
|
|
|
91
82
|
type SheetSide = keyof typeof SHEET_SIDE;
|
|
92
83
|
|
|
93
|
-
type SheetContentProps =
|
|
84
|
+
type SheetContentProps = ModalContentProps & {
|
|
94
85
|
/** A modal belongs in `ResponsiveDialog`; this family slides from an edge. */
|
|
95
86
|
side?: SheetSide;
|
|
96
87
|
above?: JSX.Element;
|
|
@@ -116,66 +107,43 @@ const SheetContent: ParentComponent<SheetContentProps> = (props) => {
|
|
|
116
107
|
"side",
|
|
117
108
|
"above",
|
|
118
109
|
"ariaLabel",
|
|
110
|
+
"style",
|
|
119
111
|
"ref",
|
|
120
|
-
"
|
|
121
|
-
"
|
|
112
|
+
"onOpenAutoFocus",
|
|
113
|
+
"onFocusOutside",
|
|
114
|
+
"forceMount",
|
|
122
115
|
]);
|
|
123
|
-
const
|
|
124
|
-
const [panel, setPanel] = createSignal<HTMLElement>();
|
|
125
|
-
const layer = shadowLayer({
|
|
126
|
-
content: panel,
|
|
127
|
-
open: () => context.isOpen(),
|
|
128
|
-
dismiss: () => context.close(),
|
|
129
|
-
trapsFocus: true,
|
|
130
|
-
initialFocus: "container",
|
|
131
|
-
consumer: local,
|
|
132
|
-
});
|
|
133
|
-
|
|
116
|
+
const ctx = useDialogContext();
|
|
134
117
|
return (
|
|
135
|
-
|
|
136
|
-
<
|
|
137
|
-
<
|
|
138
|
-
|
|
118
|
+
<>
|
|
119
|
+
<ModalCover panel={ctx.panel} open={ctx.isOpen} dormant={ctx.dormant} />
|
|
120
|
+
<ModalFrame
|
|
121
|
+
slot="sheet"
|
|
122
|
+
mount={usePortalMount()}
|
|
123
|
+
exitMs={SHEET_EXIT_MS}
|
|
124
|
+
scrimClass={SHEET_SCRIM}
|
|
125
|
+
panelClass={cn(SHEET_PANEL, SHEET_SIDE[local.side ?? "right"], local.class)}
|
|
126
|
+
panelStyle={typeof local.style === "object" ? local.style : undefined}
|
|
127
|
+
ariaLabel={local.ariaLabel}
|
|
139
128
|
ref={(el: HTMLElement) => {
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
if (typeof local.ref === "function") local.ref(el as HTMLDivElement);
|
|
130
|
+
}}
|
|
131
|
+
onOpenAutoFocus={(event: Event) => {
|
|
132
|
+
// The panel takes focus itself, not its first control.
|
|
133
|
+
if (local.onOpenAutoFocus) local.onOpenAutoFocus(event);
|
|
134
|
+
else event.preventDefault();
|
|
142
135
|
}}
|
|
143
|
-
onInteractOutside={layer.onInteractOutside}
|
|
144
|
-
onCloseAutoFocus={layer.onCloseAutoFocus}
|
|
145
|
-
data-slot="sheet-content"
|
|
146
|
-
role="dialog"
|
|
147
|
-
aria-label={context.titleId() ? undefined : local.ariaLabel}
|
|
148
|
-
class={cn(SHEET_PANEL, SHEET_SIDE[local.side ?? "right"], local.class)}
|
|
149
|
-
onOpenAutoFocus={(e: Event) => e.preventDefault()}
|
|
150
136
|
{...rest}
|
|
151
137
|
>
|
|
152
138
|
<SheetAbove above={local.above} />
|
|
153
139
|
{local.children}
|
|
154
|
-
</
|
|
155
|
-
|
|
140
|
+
</ModalFrame>
|
|
141
|
+
</>
|
|
156
142
|
);
|
|
157
143
|
};
|
|
158
144
|
|
|
159
145
|
const { Header: SheetHeader, Body: SheetBody, Footer: SheetFooter } = createModalParts("sheet");
|
|
160
146
|
|
|
161
|
-
const SheetTitle: Component<ComponentProps<typeof DialogPrimitive.Title>> = (props) => {
|
|
162
|
-
const [local, rest] = splitProps(props, ["class"]);
|
|
163
|
-
return (
|
|
164
|
-
<DialogPrimitive.Title data-slot="sheet-title" class={cn(MODAL_TITLE, local.class)} {...rest} />
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const SheetDescription: Component<ComponentProps<typeof DialogPrimitive.Description>> = (props) => {
|
|
169
|
-
const [local, rest] = splitProps(props, ["class"]);
|
|
170
|
-
return (
|
|
171
|
-
<DialogPrimitive.Description
|
|
172
|
-
data-slot="sheet-description"
|
|
173
|
-
class={cn(MODAL_DESCRIPTION, local.class)}
|
|
174
|
-
{...rest}
|
|
175
|
-
/>
|
|
176
|
-
);
|
|
177
|
-
};
|
|
178
|
-
|
|
179
147
|
export {
|
|
180
148
|
Sheet,
|
|
181
149
|
SheetBody,
|