@vvedantb/ui 0.56.0 → 0.58.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 +24 -1
- package/dist/shell/src/AppShell.js +156 -125
- package/dist/shell/src/ButtonTrack.js +57 -0
- package/dist/shell/src/SidePanelTabs.js +595 -0
- package/dist/shell/src/SidebarPanel.js +20 -15
- package/dist/shell/src/SidebarRail.js +43 -19
- package/dist/shell/src/index.js +4 -1
- package/dist/shell/src/shell-panel-motion.js +62 -0
- package/dist/shell/src/shell-variant.js +8 -0
- package/dist/src/client.js +6 -1
- package/dist/src/index.js +6 -1
- package/dist/src/motion/dock-motion.js +209 -0
- package/dist/tokens/src/css/motion.css +7 -1
- package/dist/tokens/src/css/tabs.css +4 -0
- package/dist/tokens/src/tokens.css +21 -0
- package/package.json +1 -1
- package/shell/src/AppShell.tsx +20 -15
- package/shell/src/ButtonTrack.tsx +26 -0
- package/shell/src/SidePanelTabs.tsx +380 -0
- package/shell/src/SidebarPanel.tsx +3 -0
- package/shell/src/SidebarRail.tsx +16 -3
- package/shell/src/index.ts +18 -2
- package/shell/src/shell-panel-motion.ts +64 -0
- package/shell/src/shell-variant.ts +20 -1
- package/src/client.ts +30 -1
- package/src/index.ts +30 -1
- package/src/motion/dock-motion.ts +188 -0
- package/tokens/src/css/motion.css +7 -1
- package/tokens/src/css/tabs.css +4 -0
- package/tokens/src/tokens.css +21 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dock motion for a panel that docks into a rail tile: it grows out of the
|
|
3
|
+
* tile when shown, shrinks back into it when hidden, and settles when the
|
|
4
|
+
* tile it belongs to changes. The Web Animations API drives it: the motions
|
|
5
|
+
* are one-shot and imperative, and a hide has to finish before the caller
|
|
6
|
+
* removes the panel.
|
|
7
|
+
*
|
|
8
|
+
* Off switch: `MotionProvider reducedMotion` (`prefersReducedMotion()`) and
|
|
9
|
+
* `PageMotionProvider disabled` (`html[data-page-motion="off"]`). With either
|
|
10
|
+
* on, nothing here animates: a show is instant and a hide runs at once.
|
|
11
|
+
*/
|
|
12
|
+
import { prefersReducedMotion } from "./reduced-motion";
|
|
13
|
+
|
|
14
|
+
/** Which edge of the panel touches the rail. */
|
|
15
|
+
export type DockEdge = "left" | "right";
|
|
16
|
+
|
|
17
|
+
/** How small the panel gets: close to the tile's size, not a dot. */
|
|
18
|
+
const DOCKED_SCALE = 0.12;
|
|
19
|
+
const POP_IN_MS = 380;
|
|
20
|
+
const POP_OUT_MS = 260;
|
|
21
|
+
const SWITCH_MS = 220;
|
|
22
|
+
/* Out-quint: fast start, long settle. The panel lands rather than stops. */
|
|
23
|
+
const SETTLE_EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
|
|
24
|
+
/* In-cubic: accelerates into the tile, as a minimise does. */
|
|
25
|
+
const DOCK_EASE = "cubic-bezier(0.5, 0, 0.75, 0)";
|
|
26
|
+
const POP_OUT_ID = "dock-pop-out";
|
|
27
|
+
/* How long the docked frame holds after a hide: past the sidebar's 280 ms
|
|
28
|
+
width slide, so the panel never shows at full size while it leaves. */
|
|
29
|
+
const HOLD_MS = 400;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Fired on the panel as a dock motion starts, and it bubbles. Overlays painted
|
|
33
|
+
* over the panel from elsewhere (an iframe host, say) cannot follow its
|
|
34
|
+
* transform, so they step aside for `ms`.
|
|
35
|
+
*/
|
|
36
|
+
export const DOCK_MOTION_EVENT = "dockmotion";
|
|
37
|
+
export class DockMotionEvent extends Event {
|
|
38
|
+
readonly ms: number;
|
|
39
|
+
constructor(ms: number) {
|
|
40
|
+
super(DOCK_MOTION_EVENT, { bubbles: true });
|
|
41
|
+
this.ms = ms;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** True while dock motion must not run. */
|
|
46
|
+
export function dockMotionOff(): boolean {
|
|
47
|
+
if (typeof document === "undefined") return true;
|
|
48
|
+
return document.documentElement.dataset.pageMotion === "off" || prefersReducedMotion();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Points the panel's transform origin at the tile's centre, on the rail
|
|
53
|
+
* edge. False when either is not on screen, so the caller skips the motion.
|
|
54
|
+
* Measure before animating: a scaled panel reports a scaled rect.
|
|
55
|
+
*/
|
|
56
|
+
function aimAt(panel: HTMLElement, tile: HTMLElement | null, edge: DockEdge) {
|
|
57
|
+
if (!tile || dockMotionOff() || typeof panel.animate !== "function") return false;
|
|
58
|
+
const p = panel.getBoundingClientRect();
|
|
59
|
+
// Height, not width: a sidebar aside slides its width open from 0.
|
|
60
|
+
if (p.height === 0) return false;
|
|
61
|
+
const t = tile.getBoundingClientRect();
|
|
62
|
+
const x = edge === "left" ? "0%" : "100%";
|
|
63
|
+
panel.style.transformOrigin = `${x} ${Math.round(t.top + t.height / 2 - p.top)}px`;
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Drops a finished pop-out's held frame (see `dockPopOut`). */
|
|
68
|
+
function releaseDocked(el: HTMLElement | null | undefined) {
|
|
69
|
+
if (!el || typeof el.getAnimations !== "function") return;
|
|
70
|
+
for (const a of el.getAnimations()) if (a.id === POP_OUT_ID) a.cancel();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Shown: the panel grows out of the tile. `after` (an arrow, a badge) fades in
|
|
75
|
+
* once the panel has nearly landed.
|
|
76
|
+
*/
|
|
77
|
+
export function dockPopIn(panel: HTMLElement, tile: HTMLElement | null, edge: DockEdge, after?: HTMLElement | null) {
|
|
78
|
+
// Always, even when the motion is skipped, or the panel stays invisible.
|
|
79
|
+
releaseDocked(panel);
|
|
80
|
+
releaseDocked(after);
|
|
81
|
+
if (!aimAt(panel, tile, edge)) return;
|
|
82
|
+
panel.dispatchEvent(new DockMotionEvent(POP_IN_MS));
|
|
83
|
+
panel.animate(
|
|
84
|
+
[
|
|
85
|
+
{ transform: `scale(${DOCKED_SCALE})`, opacity: 0 },
|
|
86
|
+
{ transform: "scale(1.015)", opacity: 1, offset: 0.75 },
|
|
87
|
+
{ transform: "scale(1)", opacity: 1 },
|
|
88
|
+
],
|
|
89
|
+
{ duration: POP_IN_MS, easing: SETTLE_EASE },
|
|
90
|
+
);
|
|
91
|
+
after?.animate([{ opacity: 0 }, { opacity: 0, offset: 0.6 }, { opacity: 1 }], { duration: POP_IN_MS });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The tile changed with the panel shown: a short settle from the new tile. */
|
|
95
|
+
export function dockNudge(panel: HTMLElement, tile: HTMLElement | null, edge: DockEdge) {
|
|
96
|
+
if (!aimAt(panel, tile, edge)) return;
|
|
97
|
+
panel.dispatchEvent(new DockMotionEvent(SWITCH_MS));
|
|
98
|
+
panel.animate(
|
|
99
|
+
[
|
|
100
|
+
{ transform: "scale(0.965)", opacity: 0.4 },
|
|
101
|
+
{ transform: "scale(1)", opacity: 1 },
|
|
102
|
+
],
|
|
103
|
+
{ duration: SWITCH_MS, easing: SETTLE_EASE },
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Hiding: shrink the panel back into the tile, then run `hide`. With no panel
|
|
109
|
+
* or tile on screen, or motion off, it hides at once. A second call while the
|
|
110
|
+
* panel is closing is ignored. `first` (an arrow) fades out early. The docked
|
|
111
|
+
* frame holds for 400 ms (or until the next `dockPopIn`): the caller may still
|
|
112
|
+
* slide the panel away, and it must stay invisible.
|
|
113
|
+
*/
|
|
114
|
+
export function dockPopOut(
|
|
115
|
+
panel: HTMLElement | null,
|
|
116
|
+
tile: HTMLElement | null,
|
|
117
|
+
edge: DockEdge,
|
|
118
|
+
hide: () => void,
|
|
119
|
+
first?: HTMLElement | null,
|
|
120
|
+
) {
|
|
121
|
+
if (!panel || !aimAt(panel, tile, edge)) {
|
|
122
|
+
hide();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const closing = panel.getAnimations().some((a) => a.id === POP_OUT_ID && a.playState === "running");
|
|
126
|
+
if (closing) return;
|
|
127
|
+
panel.dispatchEvent(new DockMotionEvent(POP_OUT_MS + HOLD_MS));
|
|
128
|
+
first?.animate([{ opacity: 1 }, { opacity: 0 }], { id: POP_OUT_ID, duration: POP_OUT_MS / 3, fill: "forwards" });
|
|
129
|
+
const shrink = panel.animate(
|
|
130
|
+
[
|
|
131
|
+
{ transform: "scale(1)", opacity: 1 },
|
|
132
|
+
{ transform: `scale(${DOCKED_SCALE})`, opacity: 0 },
|
|
133
|
+
],
|
|
134
|
+
{ id: POP_OUT_ID, duration: POP_OUT_MS, easing: DOCK_EASE, fill: "forwards" },
|
|
135
|
+
);
|
|
136
|
+
shrink.onfinish = () => {
|
|
137
|
+
hide();
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
releaseDocked(panel);
|
|
140
|
+
releaseDocked(first);
|
|
141
|
+
}, HOLD_MS);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Lets the panes of a resizable group slide to their next size instead of
|
|
147
|
+
* jumping, so the neighbour pane moves in step with a pop. It sets
|
|
148
|
+
* `data-dock-slide` and the `--dock-slide-dur` / `--dock-slide-ease` variables
|
|
149
|
+
* on `group` for one resize; the package CSS transitions `flex-grow` of its
|
|
150
|
+
* `[data-panel]` children (`react-resizable-panels`). Call it just before the
|
|
151
|
+
* resize. Only for this one toggle: a drag must stay 1:1 with the pointer.
|
|
152
|
+
*/
|
|
153
|
+
export function slideNextResize(group: HTMLElement | null, direction: "open" | "close") {
|
|
154
|
+
if (!group || dockMotionOff()) return;
|
|
155
|
+
const ms = direction === "open" ? POP_IN_MS : POP_OUT_MS;
|
|
156
|
+
group.style.setProperty("--dock-slide-dur", `${ms}ms`);
|
|
157
|
+
group.style.setProperty("--dock-slide-ease", SETTLE_EASE);
|
|
158
|
+
group.dataset.dockSlide = "";
|
|
159
|
+
window.clearTimeout(Number(group.dataset.dockSlideTimer));
|
|
160
|
+
group.dataset.dockSlideTimer = String(
|
|
161
|
+
window.setTimeout(() => {
|
|
162
|
+
delete group.dataset.dockSlide;
|
|
163
|
+
}, ms + 50),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* For one layout change, `follower` slides its `property` with the timing of
|
|
169
|
+
* `leader`'s own transition, so a neighbour the leader pushes moves in step
|
|
170
|
+
* instead of jumping (the main content beside a sidebar's sliding width). Call
|
|
171
|
+
* it just before the change. Fires `DOCK_MOTION_EVENT` on the follower, so
|
|
172
|
+
* overlays over it step aside while it moves.
|
|
173
|
+
*/
|
|
174
|
+
export function slideWith(follower: HTMLElement | null, leader: HTMLElement | null, property: string) {
|
|
175
|
+
if (!follower || !leader || dockMotionOff()) return;
|
|
176
|
+
const lead = getComputedStyle(leader);
|
|
177
|
+
const ms = parseFloat(lead.transitionDuration) * 1000;
|
|
178
|
+
if (!(ms > 0)) return;
|
|
179
|
+
follower.style.transition = `${property} ${lead.transitionDuration} ${lead.transitionTimingFunction}`;
|
|
180
|
+
follower.dispatchEvent(new DockMotionEvent(ms));
|
|
181
|
+
window.clearTimeout(Number(follower.dataset.slideWithTimer));
|
|
182
|
+
follower.dataset.slideWithTimer = String(
|
|
183
|
+
window.setTimeout(() => {
|
|
184
|
+
follower.style.transition = "";
|
|
185
|
+
delete follower.dataset.slideWithTimer;
|
|
186
|
+
}, ms + 50),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
@@ -158,10 +158,16 @@
|
|
|
158
158
|
html[data-page-motion="off"] .t-modal,
|
|
159
159
|
html[data-page-motion="off"] .t-modal.is-closing,
|
|
160
160
|
html[data-page-motion="off"] .t-modal[data-state="closed"],
|
|
161
|
-
html[data-page-motion="off"] .t-tabs-pill
|
|
161
|
+
html[data-page-motion="off"] .t-tabs-pill,
|
|
162
|
+
html[data-page-motion="off"] .t-side-panel-arrow {
|
|
162
163
|
transition-duration: 0s !important;
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
/* `slideNextResize`: the panes of a resizable group slide for one resize. */
|
|
167
|
+
[data-dock-slide] > [data-panel] {
|
|
168
|
+
transition: flex-grow var(--dock-slide-dur) var(--dock-slide-ease);
|
|
169
|
+
}
|
|
170
|
+
|
|
165
171
|
html[data-page-motion="off"]::view-transition-group(*),
|
|
166
172
|
html[data-page-motion="off"]::view-transition-old(*),
|
|
167
173
|
html[data-page-motion="off"]::view-transition-new(*) {
|
package/tokens/src/css/tabs.css
CHANGED
package/tokens/src/tokens.css
CHANGED
|
@@ -246,6 +246,27 @@
|
|
|
246
246
|
--radius: 1rem;
|
|
247
247
|
--field-radius: min(var(--radius), 0.625rem);
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
/* Neutral: soft-dark grey surfaces. Opt in with `<html class="dark neutral">`;
|
|
251
|
+
status and accent colours come from `.dark`. */
|
|
252
|
+
.dark.neutral {
|
|
253
|
+
--background: rgb(34 35 37);
|
|
254
|
+
--border: rgb(78 79 82);
|
|
255
|
+
--default: rgb(68 69 72);
|
|
256
|
+
--field-background: rgb(48 49 52);
|
|
257
|
+
--field-placeholder: rgb(159 160 162);
|
|
258
|
+
--foreground: rgb(250 250 250);
|
|
259
|
+
--muted: rgb(159 160 162);
|
|
260
|
+
--overlay: rgb(48 49 52);
|
|
261
|
+
--scrollbar: rgb(159 160 162);
|
|
262
|
+
--segment: rgb(68 69 72);
|
|
263
|
+
--separator: rgb(58 59 62);
|
|
264
|
+
--surface: rgb(48 49 52);
|
|
265
|
+
--surface-secondary: rgb(58 59 62);
|
|
266
|
+
--surface-tertiary: rgb(68 69 72);
|
|
267
|
+
--surface-card: rgb(48 49 52);
|
|
268
|
+
--sidebar-accent: rgb(58 59 62);
|
|
269
|
+
}
|
|
249
270
|
}
|
|
250
271
|
|
|
251
272
|
@layer base {
|