magic-pill 9.2.0 → 9.4.0-next.1
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/CHANGELOG.md +25 -0
- package/MIGRATING.md +2 -0
- package/README.md +158 -17
- package/dist/MagicPill/MagicPill.d.mts +43 -1
- package/dist/MagicPill/MagicPill.d.ts +43 -1
- package/dist/MagicPill/MagicPill.js +53 -6
- package/dist/MagicPill/MagicPill.mjs +56 -9
- package/dist/MagicPill/flag.js +1 -59
- package/dist/MagicPill/flag.mjs +1 -58
- package/dist/MagicPill/useChoreography.js +2 -1
- package/dist/MagicPill/useChoreography.mjs +3 -2
- package/dist/Pill/PillProgress.d.mts +12 -0
- package/dist/Pill/PillProgress.d.ts +12 -0
- package/dist/Pill/PillProgress.js +42 -0
- package/dist/Pill/PillProgress.mjs +42 -0
- package/dist/Pill/goo.js +353 -0
- package/dist/Pill/goo.mjs +347 -0
- package/dist/Pill/modal.js +2 -1
- package/dist/Pill/modal.mjs +3 -2
- package/dist/Pill/morph.js +7 -4
- package/dist/Pill/morph.mjs +8 -5
- package/dist/Pill/travel.js +2 -1
- package/dist/Pill/travel.mjs +3 -2
- package/dist/Pill/zone.js +3 -2
- package/dist/Pill/zone.mjs +4 -3
- package/dist/PillForm/PillSubmit.js +1 -1
- package/dist/PillForm/PillSubmit.mjs +3 -3
- package/dist/PillForm/popover.js +2 -1
- package/dist/PillForm/popover.mjs +3 -2
- package/dist/PillNavbar/PillNavbar.d.mts +8 -0
- package/dist/PillNavbar/PillNavbar.d.ts +8 -0
- package/dist/PillNavbar/PillNavbar.js +3 -2
- package/dist/PillNavbar/PillNavbar.mjs +3 -2
- package/dist/PillNavbar/room.d.mts +3 -0
- package/dist/PillNavbar/room.d.ts +2 -0
- package/dist/PillNavbar/room.js +89 -17
- package/dist/PillNavbar/room.mjs +89 -18
- package/dist/PillOptics/PillOptics.js +2 -1
- package/dist/PillOptics/PillOptics.mjs +3 -2
- package/dist/forms.css +2 -1
- package/dist/index.d.mts +30 -15
- package/dist/index.d.ts +30 -15
- package/dist/index.js +40 -12
- package/dist/index.mjs +40 -13
- package/dist/satellites/Actions.d.mts +12 -0
- package/dist/satellites/Actions.d.ts +11 -0
- package/dist/satellites/Actions.js +59 -0
- package/dist/satellites/Actions.mjs +56 -0
- package/dist/satellites/Orbitals.js +554 -0
- package/dist/satellites/Orbitals.mjs +554 -0
- package/dist/satellites/Satellites.js +400 -0
- package/dist/satellites/Satellites.mjs +400 -0
- package/dist/satellites/layout.js +156 -0
- package/dist/satellites/layout.mjs +156 -0
- package/dist/satellites/measure.js +25 -0
- package/dist/satellites/measure.mjs +24 -0
- package/dist/satellites/orbits.js +139 -0
- package/dist/satellites/orbits.mjs +136 -0
- package/dist/satellites/types.d.mts +54 -0
- package/dist/satellites/types.d.ts +54 -0
- package/dist/satellites.d.mts +5 -0
- package/dist/satellites.d.ts +5 -0
- package/dist/satellites.js +14 -0
- package/dist/satellites.mjs +12 -0
- package/dist/store/store.d.mts +103 -0
- package/dist/store/store.d.ts +103 -0
- package/dist/store/store.js +52 -1
- package/dist/store/store.mjs +52 -2
- package/dist/styles.css +174 -10
- package/dist/utils/react.js +8 -1
- package/dist/utils/react.mjs +8 -2
- package/package.json +12 -2
- package/dist/icons/ArrowIcon.d.mts +0 -4
- package/dist/icons/ArrowIcon.d.ts +0 -4
- package/dist/icons/BoxIcon.d.mts +0 -4
- package/dist/icons/BoxIcon.d.ts +0 -4
- package/dist/icons/CheckIcon.d.mts +0 -4
- package/dist/icons/CheckIcon.d.ts +0 -4
- package/dist/icons/CloseIcon.d.mts +0 -4
- package/dist/icons/CloseIcon.d.ts +0 -4
- package/dist/icons/CouponIcon.d.mts +0 -4
- package/dist/icons/CouponIcon.d.ts +0 -4
- package/dist/icons/DocumentIcon.d.mts +0 -4
- package/dist/icons/DocumentIcon.d.ts +0 -4
- package/dist/icons/HelpIcon.d.mts +0 -4
- package/dist/icons/HelpIcon.d.ts +0 -4
- package/dist/icons/InfoIcon.d.mts +0 -4
- package/dist/icons/InfoIcon.d.ts +0 -4
- package/dist/icons/MailIcon.d.mts +0 -4
- package/dist/icons/MailIcon.d.ts +0 -4
- package/dist/icons/PhoneIcon.d.mts +0 -4
- package/dist/icons/PhoneIcon.d.ts +0 -4
- package/dist/icons/PlusIcon.d.mts +0 -4
- package/dist/icons/PlusIcon.d.ts +0 -4
- package/dist/icons/UndoIcon.d.mts +0 -4
- package/dist/icons/UndoIcon.d.ts +0 -4
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Fragment, forwardRef, useEffect,
|
|
3
|
+
import { Fragment, forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import Pill from "../Pill/Pill.mjs";
|
|
5
5
|
import { PillIcon } from "../Pill/parts.mjs";
|
|
6
6
|
import { NotificationContent } from "../PillNotification/PillNotification.mjs";
|
|
7
7
|
import { getStore } from "../store/store.mjs";
|
|
8
8
|
import { getInputModality, trackInputModality } from "../utils/inputModality.mjs";
|
|
9
9
|
import { usePillQueue } from "../store/usePillQueue.mjs";
|
|
10
|
-
import { mergeRefs } from "../utils/react.mjs";
|
|
10
|
+
import { devWarn, mergeRefs, useIsomorphicLayoutEffect } from "../utils/react.mjs";
|
|
11
11
|
import { prefersReducedMotion } from "../utils/timing.mjs";
|
|
12
12
|
import { VISUALLY_HIDDEN } from "../utils/visuallyHidden.mjs";
|
|
13
13
|
import { BASE, IDLE, NONE, isOpen, readTimings } from "./choreography.mjs";
|
|
14
|
-
import { flagStyle, measureFlagSpot
|
|
14
|
+
import { flagStyle, measureFlagSpot } from "./flag.mjs";
|
|
15
|
+
import { playSplit } from "../Pill/goo.mjs";
|
|
15
16
|
import { useChoreography } from "./useChoreography.mjs";
|
|
16
17
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
17
18
|
|
|
@@ -82,13 +83,29 @@ const notificationIn = ({ scene, presence }) => scene.kind === "notification" &&
|
|
|
82
83
|
* The batteries-included pill: a <Pill> with a base layer, a queue of
|
|
83
84
|
* notifications fed by pill(name), and a live region that announces them.
|
|
84
85
|
*/
|
|
85
|
-
const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
|
+
const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene, duration = DEFAULT_DURATION, idle = "hidden", idleIcon, swap = "queue", notificationLayout = "pill", linkComponent, classNames, pathname, satellites, electronSide = "after", electronLine = "along", keepElectronsOut = false, electronEnding = "join", arrange = "gather", orbitalsOpenOn = "press-hover", orbitalLabels = true, orbitalsStayOpen = true, actionsStyle = "detached", actionsSide = "start", actionsOrientation = "auto", actionsLabel = "Page actions", placement = "bottom", orientation, moveThroughCircle, variant, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }, forwardedRef) {
|
|
86
87
|
const store = getStore(name);
|
|
87
88
|
const { current } = usePillQueue(name);
|
|
88
89
|
const rootRef = useRef(null);
|
|
89
90
|
const ref = useMemo(() => mergeRefs(rootRef, forwardedRef), [forwardedRef]);
|
|
90
91
|
const flagRef = useRef(null);
|
|
91
92
|
useEffect(() => store.registerHost(), [store]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (satellites) return;
|
|
95
|
+
const check = () => {
|
|
96
|
+
if (store.getElectrons().length > 0) {
|
|
97
|
+
devWarn(`pill("${name}").electron() needs the satellites: <MagicPill satellites={satellites}>, from "magic-pill/satellites".`);
|
|
98
|
+
unsubscribe();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const unsubscribe = store.subscribe(check);
|
|
102
|
+
check();
|
|
103
|
+
return unsubscribe;
|
|
104
|
+
}, [
|
|
105
|
+
store,
|
|
106
|
+
satellites,
|
|
107
|
+
name
|
|
108
|
+
]);
|
|
92
109
|
useEffect(trackInputModality, []);
|
|
93
110
|
const hasBase = hasContent(children);
|
|
94
111
|
const lastBase = useRef(children);
|
|
@@ -159,7 +176,7 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
|
|
|
159
176
|
}
|
|
160
177
|
});
|
|
161
178
|
const flagY = flagDisplayed.presence === "panel" ? void 0 : flagSpot.y;
|
|
162
|
-
|
|
179
|
+
useIsomorphicLayoutEffect(() => {
|
|
163
180
|
const from = flagFrom.current;
|
|
164
181
|
flagFrom.current = null;
|
|
165
182
|
const flag = flagRef.current;
|
|
@@ -175,18 +192,18 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
|
|
|
175
192
|
});
|
|
176
193
|
}, [flagSpot, flagY]);
|
|
177
194
|
const flagPresence = useRef(flagDisplayed.presence);
|
|
178
|
-
|
|
195
|
+
useIsomorphicLayoutEffect(() => {
|
|
179
196
|
const previous = flagPresence.current;
|
|
180
197
|
flagPresence.current = flagDisplayed.presence;
|
|
181
198
|
const sidebar = rootRef.current;
|
|
182
199
|
const flag = flagRef.current;
|
|
183
200
|
if (!sidebar || !flag || previous === flagDisplayed.presence) return;
|
|
184
201
|
const { enter, fade, change, exit } = readTimings(flag);
|
|
185
|
-
if (previous === "hidden" && flagDisplayed.presence === "rest")
|
|
202
|
+
if (previous === "hidden" && flagDisplayed.presence === "rest") playSplit(sidebar, flag, "split", {
|
|
186
203
|
delay: 0,
|
|
187
204
|
duration: enter
|
|
188
205
|
});
|
|
189
|
-
else if (flagDisplayed.presence === "hidden")
|
|
206
|
+
else if (flagDisplayed.presence === "hidden") playSplit(sidebar, flag, "join", {
|
|
190
207
|
delay: fade + change,
|
|
191
208
|
duration: exit
|
|
192
209
|
});
|
|
@@ -235,9 +252,38 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
|
|
|
235
252
|
presence: next
|
|
236
253
|
});
|
|
237
254
|
};
|
|
255
|
+
const satelliteHost = satellites ? {
|
|
256
|
+
name,
|
|
257
|
+
store,
|
|
258
|
+
rootRef,
|
|
259
|
+
placement,
|
|
260
|
+
vertical: isVertical,
|
|
261
|
+
pathname,
|
|
262
|
+
notifying: target.kind === "notification" || displayed.scene.kind === "notification" || hasBase && !isOpen(displayed.presence),
|
|
263
|
+
linkComponent,
|
|
264
|
+
variant,
|
|
265
|
+
theme: rest.theme,
|
|
266
|
+
electronSide,
|
|
267
|
+
electronLine,
|
|
268
|
+
keepElectronsOut,
|
|
269
|
+
electronEnding,
|
|
270
|
+
arrange,
|
|
271
|
+
orbitalsOpenOn,
|
|
272
|
+
orbitalLabels,
|
|
273
|
+
orbitalsStayOpen,
|
|
274
|
+
actionsStyle,
|
|
275
|
+
actionsSide,
|
|
276
|
+
actionsOrientation,
|
|
277
|
+
actionsLabel
|
|
278
|
+
} : void 0;
|
|
279
|
+
const inside = satellites && satelliteHost && actionsStyle === "inside" ? /* @__PURE__ */ jsx(satellites.Inside, { host: satelliteHost }) : null;
|
|
238
280
|
const renderScene = (shownScene) => {
|
|
239
281
|
switch (shownScene.kind) {
|
|
240
|
-
case "base": return /* @__PURE__ */
|
|
282
|
+
case "base": return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
283
|
+
actionsSide !== "end" && inside,
|
|
284
|
+
lastScenes.current.get(shownScene.key)?.children ?? lastBase.current,
|
|
285
|
+
actionsSide === "end" && inside
|
|
286
|
+
] }, shownScene.key);
|
|
241
287
|
case "idle": return /* @__PURE__ */ jsx(PillIcon, { children: idleIcon });
|
|
242
288
|
case "notification": {
|
|
243
289
|
const { id, input } = shownScene.item;
|
|
@@ -319,6 +365,7 @@ const MagicPill = forwardRef(function MagicPill({ name = "main", children, scene
|
|
|
319
365
|
...flagPause.handlers,
|
|
320
366
|
children: renderScene(flagDisplayed.scene)
|
|
321
367
|
}),
|
|
368
|
+
satellites && satelliteHost && /* @__PURE__ */ jsx(satellites.Layer, { host: satelliteHost }),
|
|
322
369
|
/* @__PURE__ */ jsx("div", {
|
|
323
370
|
role: "status",
|
|
324
371
|
"aria-live": "polite",
|
package/dist/MagicPill/flag.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const require_matchPath = require("../PillNavbar/matchPath.js");
|
|
2
|
-
const require_timing = require("../utils/timing.js");
|
|
3
2
|
|
|
4
3
|
// src/MagicPill/flag.ts
|
|
5
4
|
/** Measures the sidebar, and the navbar item whose `href` matches `at`, if any. */
|
|
@@ -31,63 +30,6 @@ function flagStyle({ shift, y }) {
|
|
|
31
30
|
}
|
|
32
31
|
return style;
|
|
33
32
|
}
|
|
34
|
-
/**
|
|
35
|
-
* The bridge between the sidebar and its flag: it stretches out of the
|
|
36
|
-
* sidebar as the flag pops out of it, then thins away as they part
|
|
37
|
-
* (`split`), or the other way round as the flag goes back (`join`).
|
|
38
|
-
*/
|
|
39
|
-
function playBridge(sidebar, flag, y, kind, timing) {
|
|
40
|
-
if (timing.duration <= 0 || require_timing.prefersReducedMotion() || typeof document.body.animate !== "function") return;
|
|
41
|
-
const rect = sidebar.getBoundingClientRect();
|
|
42
|
-
const flagStyles = getComputedStyle(flag);
|
|
43
|
-
const gap = (Number.parseFloat(flagStyles.columnGap) || 16) * .75;
|
|
44
|
-
const onRight = flag.dataset.placement === "right";
|
|
45
|
-
const overlap = 8;
|
|
46
|
-
const thickness = 22;
|
|
47
|
-
const centre = y ?? rect.top + rect.height / 2;
|
|
48
|
-
const bridge = document.createElement("div");
|
|
49
|
-
bridge.setAttribute("data-mp", "flag-bridge");
|
|
50
|
-
bridge.setAttribute("aria-hidden", "true");
|
|
51
|
-
const from = getComputedStyle(sidebar).backgroundColor;
|
|
52
|
-
const to = flagStyles.backgroundColor;
|
|
53
|
-
bridge.style.cssText = [
|
|
54
|
-
"position:fixed",
|
|
55
|
-
"pointer-events:none",
|
|
56
|
-
`z-index:${(Number.parseInt(flagStyles.zIndex, 10) || 50) - 1}`,
|
|
57
|
-
`top:${centre - thickness / 2}px`,
|
|
58
|
-
`left:${onRight ? rect.left - gap - overlap : rect.right - overlap}px`,
|
|
59
|
-
`width:${gap + 16}px`,
|
|
60
|
-
`height:${thickness}px`,
|
|
61
|
-
`border-radius:${thickness / 2}px`,
|
|
62
|
-
`background:linear-gradient(to ${onRight ? "left" : "right"}, ${from}, ${to})`,
|
|
63
|
-
`transform-origin:${onRight ? "right" : "left"} center`,
|
|
64
|
-
"transform:scaleX(0)"
|
|
65
|
-
].join(";");
|
|
66
|
-
document.body.append(bridge);
|
|
67
|
-
const out = [
|
|
68
|
-
{ transform: "scaleX(0)" },
|
|
69
|
-
{
|
|
70
|
-
transform: "scaleX(1)",
|
|
71
|
-
offset: .35
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
transform: "scaleX(1) scaleY(0.35)",
|
|
75
|
-
offset: .7
|
|
76
|
-
},
|
|
77
|
-
{ transform: "scaleX(1) scaleY(0)" }
|
|
78
|
-
];
|
|
79
|
-
const remove = () => bridge.remove();
|
|
80
|
-
bridge.animate(kind === "split" ? out : [...out].reverse().map((frame, index, all) => ({
|
|
81
|
-
...frame,
|
|
82
|
-
offset: index / (all.length - 1)
|
|
83
|
-
})), {
|
|
84
|
-
delay: timing.delay,
|
|
85
|
-
duration: timing.duration,
|
|
86
|
-
easing: "ease-out",
|
|
87
|
-
fill: "both"
|
|
88
|
-
}).finished.then(remove, remove);
|
|
89
|
-
}
|
|
90
33
|
|
|
91
34
|
exports.flagStyle = flagStyle;
|
|
92
|
-
exports.measureFlagSpot = measureFlagSpot;
|
|
93
|
-
exports.playBridge = playBridge;
|
|
35
|
+
exports.measureFlagSpot = measureFlagSpot;
|
package/dist/MagicPill/flag.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { findActiveIndex } from "../PillNavbar/matchPath.mjs";
|
|
2
|
-
import { prefersReducedMotion } from "../utils/timing.mjs";
|
|
3
2
|
|
|
4
3
|
// src/MagicPill/flag.ts
|
|
5
4
|
/** Measures the sidebar, and the navbar item whose `href` matches `at`, if any. */
|
|
@@ -31,61 +30,5 @@ function flagStyle({ shift, y }) {
|
|
|
31
30
|
}
|
|
32
31
|
return style;
|
|
33
32
|
}
|
|
34
|
-
/**
|
|
35
|
-
* The bridge between the sidebar and its flag: it stretches out of the
|
|
36
|
-
* sidebar as the flag pops out of it, then thins away as they part
|
|
37
|
-
* (`split`), or the other way round as the flag goes back (`join`).
|
|
38
|
-
*/
|
|
39
|
-
function playBridge(sidebar, flag, y, kind, timing) {
|
|
40
|
-
if (timing.duration <= 0 || prefersReducedMotion() || typeof document.body.animate !== "function") return;
|
|
41
|
-
const rect = sidebar.getBoundingClientRect();
|
|
42
|
-
const flagStyles = getComputedStyle(flag);
|
|
43
|
-
const gap = (Number.parseFloat(flagStyles.columnGap) || 16) * .75;
|
|
44
|
-
const onRight = flag.dataset.placement === "right";
|
|
45
|
-
const overlap = 8;
|
|
46
|
-
const thickness = 22;
|
|
47
|
-
const centre = y ?? rect.top + rect.height / 2;
|
|
48
|
-
const bridge = document.createElement("div");
|
|
49
|
-
bridge.setAttribute("data-mp", "flag-bridge");
|
|
50
|
-
bridge.setAttribute("aria-hidden", "true");
|
|
51
|
-
const from = getComputedStyle(sidebar).backgroundColor;
|
|
52
|
-
const to = flagStyles.backgroundColor;
|
|
53
|
-
bridge.style.cssText = [
|
|
54
|
-
"position:fixed",
|
|
55
|
-
"pointer-events:none",
|
|
56
|
-
`z-index:${(Number.parseInt(flagStyles.zIndex, 10) || 50) - 1}`,
|
|
57
|
-
`top:${centre - thickness / 2}px`,
|
|
58
|
-
`left:${onRight ? rect.left - gap - overlap : rect.right - overlap}px`,
|
|
59
|
-
`width:${gap + 16}px`,
|
|
60
|
-
`height:${thickness}px`,
|
|
61
|
-
`border-radius:${thickness / 2}px`,
|
|
62
|
-
`background:linear-gradient(to ${onRight ? "left" : "right"}, ${from}, ${to})`,
|
|
63
|
-
`transform-origin:${onRight ? "right" : "left"} center`,
|
|
64
|
-
"transform:scaleX(0)"
|
|
65
|
-
].join(";");
|
|
66
|
-
document.body.append(bridge);
|
|
67
|
-
const out = [
|
|
68
|
-
{ transform: "scaleX(0)" },
|
|
69
|
-
{
|
|
70
|
-
transform: "scaleX(1)",
|
|
71
|
-
offset: .35
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
transform: "scaleX(1) scaleY(0.35)",
|
|
75
|
-
offset: .7
|
|
76
|
-
},
|
|
77
|
-
{ transform: "scaleX(1) scaleY(0)" }
|
|
78
|
-
];
|
|
79
|
-
const remove = () => bridge.remove();
|
|
80
|
-
bridge.animate(kind === "split" ? out : [...out].reverse().map((frame, index, all) => ({
|
|
81
|
-
...frame,
|
|
82
|
-
offset: index / (all.length - 1)
|
|
83
|
-
})), {
|
|
84
|
-
delay: timing.delay,
|
|
85
|
-
duration: timing.duration,
|
|
86
|
-
easing: "ease-out",
|
|
87
|
-
fill: "both"
|
|
88
|
-
}).finished.then(remove, remove);
|
|
89
|
-
}
|
|
90
33
|
|
|
91
|
-
export { flagStyle, measureFlagSpot
|
|
34
|
+
export { flagStyle, measureFlagSpot };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
let react = require("react");
|
|
4
|
+
const require_react = require("../utils/react.js");
|
|
4
5
|
const require_choreography = require("./choreography.js");
|
|
5
6
|
const require_morph = require("../Pill/morph.js");
|
|
6
7
|
|
|
@@ -19,7 +20,7 @@ function useChoreography(rootRef, target, options) {
|
|
|
19
20
|
optionsRef.current = options;
|
|
20
21
|
const followUps = (0, react.useRef)([]);
|
|
21
22
|
const capture = (0, react.useRef)(null);
|
|
22
|
-
|
|
23
|
+
require_react.useIsomorphicLayoutEffect(() => {
|
|
23
24
|
const swapped = capture.current;
|
|
24
25
|
capture.current = null;
|
|
25
26
|
if (swapped && rootRef.current) require_morph.playSwap(rootRef.current, swapped);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect,
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
|
|
4
5
|
import { batchSteps, isSwap, planSteps, readTimings } from "./choreography.mjs";
|
|
5
6
|
import { captureSwap, playSwap } from "../Pill/morph.mjs";
|
|
6
7
|
|
|
@@ -19,7 +20,7 @@ function useChoreography(rootRef, target, options) {
|
|
|
19
20
|
optionsRef.current = options;
|
|
20
21
|
const followUps = useRef([]);
|
|
21
22
|
const capture = useRef(null);
|
|
22
|
-
|
|
23
|
+
useIsomorphicLayoutEffect(() => {
|
|
23
24
|
const swapped = capture.current;
|
|
24
25
|
capture.current = null;
|
|
25
26
|
if (swapped && rootRef.current) playSwap(rootRef.current, swapped);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export interface PillProgressProps extends ComponentPropsWithoutRef<"span"> {
|
|
3
|
+
/** 0 to 1: how much of the ring is drawn. */
|
|
4
|
+
value: number;
|
|
5
|
+
/**
|
|
6
|
+
* What it measures, for screen readers ("Upload"). Without it, the ring is
|
|
7
|
+
* decorative: the pill around it says what it is (an electron's name).
|
|
8
|
+
*/
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
12
|
+
export declare const PillProgress: import("react").ForwardRefExoticComponent<PillProgressProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
export interface PillProgressProps extends ComponentPropsWithoutRef<"span"> {
|
|
3
|
+
/** 0 to 1: how much of the ring is drawn. */
|
|
4
|
+
value: number;
|
|
5
|
+
/**
|
|
6
|
+
* What it measures, for screen readers ("Upload"). Without it, the ring is
|
|
7
|
+
* decorative: the pill around it says what it is (an electron's name).
|
|
8
|
+
*/
|
|
9
|
+
label?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
12
|
+
export declare const PillProgress: import("react").ForwardRefExoticComponent<PillProgressProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let react = require("react");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
|
|
4
|
+
// src/Pill/PillProgress.tsx
|
|
5
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
6
|
+
const PillProgress = (0, react.forwardRef)(function PillProgress({ value, label, children, ...rest }, ref) {
|
|
7
|
+
const amount = Math.min(1, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
8
|
+
const a11y = label ? {
|
|
9
|
+
role: "progressbar",
|
|
10
|
+
"aria-label": label,
|
|
11
|
+
"aria-valuemin": 0,
|
|
12
|
+
"aria-valuemax": 100,
|
|
13
|
+
"aria-valuenow": Math.round(amount * 100)
|
|
14
|
+
} : {};
|
|
15
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
16
|
+
...a11y,
|
|
17
|
+
...rest,
|
|
18
|
+
ref,
|
|
19
|
+
"data-mp": "progress",
|
|
20
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
21
|
+
viewBox: "0 0 54 54",
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
focusable: "false",
|
|
24
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
25
|
+
"data-mp": "progress-track",
|
|
26
|
+
cx: "27",
|
|
27
|
+
cy: "27",
|
|
28
|
+
r: "24",
|
|
29
|
+
pathLength: "100"
|
|
30
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
31
|
+
"data-mp": "progress-bar",
|
|
32
|
+
cx: "27",
|
|
33
|
+
cy: "27",
|
|
34
|
+
r: "24",
|
|
35
|
+
pathLength: "100",
|
|
36
|
+
strokeDasharray: `${amount * 100} 100`
|
|
37
|
+
})]
|
|
38
|
+
}), children]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
exports.PillProgress = PillProgress;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
// src/Pill/PillProgress.tsx
|
|
5
|
+
/** A progress ring around its content (a value, an icon), in the text colour. */
|
|
6
|
+
const PillProgress = forwardRef(function PillProgress({ value, label, children, ...rest }, ref) {
|
|
7
|
+
const amount = Math.min(1, Math.max(0, Number.isFinite(value) ? value : 0));
|
|
8
|
+
const a11y = label ? {
|
|
9
|
+
role: "progressbar",
|
|
10
|
+
"aria-label": label,
|
|
11
|
+
"aria-valuemin": 0,
|
|
12
|
+
"aria-valuemax": 100,
|
|
13
|
+
"aria-valuenow": Math.round(amount * 100)
|
|
14
|
+
} : {};
|
|
15
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
16
|
+
...a11y,
|
|
17
|
+
...rest,
|
|
18
|
+
ref,
|
|
19
|
+
"data-mp": "progress",
|
|
20
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
21
|
+
viewBox: "0 0 54 54",
|
|
22
|
+
"aria-hidden": "true",
|
|
23
|
+
focusable: "false",
|
|
24
|
+
children: [/* @__PURE__ */ jsx("circle", {
|
|
25
|
+
"data-mp": "progress-track",
|
|
26
|
+
cx: "27",
|
|
27
|
+
cy: "27",
|
|
28
|
+
r: "24",
|
|
29
|
+
pathLength: "100"
|
|
30
|
+
}), /* @__PURE__ */ jsx("circle", {
|
|
31
|
+
"data-mp": "progress-bar",
|
|
32
|
+
cx: "27",
|
|
33
|
+
cy: "27",
|
|
34
|
+
r: "24",
|
|
35
|
+
pathLength: "100",
|
|
36
|
+
strokeDasharray: `${amount * 100} 100`
|
|
37
|
+
})]
|
|
38
|
+
}), children]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { PillProgress };
|