@slotform/react-ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { Drop, PlaceSpec } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { accepts } from "@slotform/ui-core/drag";
|
|
4
|
+
import { treeMove, treeRows, treeStop } from "@slotform/ui-core/list-state";
|
|
5
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
6
|
+
import { placesFolded } from "@slotform/ui-core/route";
|
|
7
|
+
import {
|
|
8
|
+
DROP_ON,
|
|
9
|
+
PLACE_NEST,
|
|
10
|
+
PRESS_WASH,
|
|
11
|
+
placeRow,
|
|
12
|
+
placeRowGlyph,
|
|
13
|
+
text,
|
|
14
|
+
} from "@slotform/ui-core/variants";
|
|
15
|
+
import { type KeyboardEvent, useMemo, useRef, useState } from "react";
|
|
16
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
17
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
18
|
+
import { useDrop, useHold, useListedDrops } from "../../lib/drag.ts";
|
|
19
|
+
import { useFolds } from "../../lib/folds.ts";
|
|
20
|
+
import { follow, isPage } from "../../lib/navigate.ts";
|
|
21
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
22
|
+
import {
|
|
23
|
+
GLYPH,
|
|
24
|
+
LABEL,
|
|
25
|
+
PLACE_COUNT,
|
|
26
|
+
ROW_BOX,
|
|
27
|
+
ROW_SELECTED_PRESS,
|
|
28
|
+
} from "./row.ts";
|
|
29
|
+
|
|
30
|
+
const TREE = "flex flex-col";
|
|
31
|
+
// The anchor is the row's hit: glyph, label and count, the fold act beside it.
|
|
32
|
+
const HIT = "flex items-center gap-gap grow min-w-0";
|
|
33
|
+
|
|
34
|
+
const childrenOf = (spec: PlaceSpec) => spec.children;
|
|
35
|
+
const keyOf = (spec: PlaceSpec) => spec.route;
|
|
36
|
+
|
|
37
|
+
// Every place under `specs`, folded branches included, by route: its path (the
|
|
38
|
+
// labels from the run's top to it, which names its drop where labels clash).
|
|
39
|
+
const PATH = " › ";
|
|
40
|
+
function walk(
|
|
41
|
+
specs: readonly PlaceSpec[],
|
|
42
|
+
above: string,
|
|
43
|
+
out: Map<string, string>,
|
|
44
|
+
listed: { drop: Drop; path: string; route: string }[],
|
|
45
|
+
) {
|
|
46
|
+
for (const spec of specs) {
|
|
47
|
+
const path = above ? `${above}${PATH}${spec.label}` : spec.label;
|
|
48
|
+
out.set(spec.route, path);
|
|
49
|
+
if (spec.drop) listed.push({ drop: spec.drop, path, route: spec.route });
|
|
50
|
+
walk(spec.children ?? [], path, out, listed);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const takes = (spec: PlaceSpec, kind: string): boolean =>
|
|
54
|
+
(spec.children ?? []).some(
|
|
55
|
+
(child) =>
|
|
56
|
+
(child.drop !== undefined &&
|
|
57
|
+
child.drop.blocked === undefined &&
|
|
58
|
+
accepts(child.drop.accepts, kind)) ||
|
|
59
|
+
takes(child, kind),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
/** A run of places that nest, as the WAI-ARIA tree: one tab stop on the current place's row (else the first), Up and Down between the visible rows, Right to open a branch and to step into it, Left to fold it and to step out to its parent, Home and End, Enter to open the place. A branch is open by the viewer's choice (kept by the browser), else when the current place is under it. */
|
|
63
|
+
export function PlaceTree(props: {
|
|
64
|
+
specs: readonly PlaceSpec[];
|
|
65
|
+
label: string;
|
|
66
|
+
route: string | undefined;
|
|
67
|
+
trail: readonly PlaceSpec[];
|
|
68
|
+
onPlace?: () => void;
|
|
69
|
+
}) {
|
|
70
|
+
const { specs, label, route, trail, onPlace } = props;
|
|
71
|
+
const { chosen, choose } = useFolds();
|
|
72
|
+
const folded = useMemo(
|
|
73
|
+
() => placesFolded(specs, chosen, trail),
|
|
74
|
+
[specs, chosen, trail],
|
|
75
|
+
);
|
|
76
|
+
const rows = useMemo(
|
|
77
|
+
() => treeRows(specs, { key: keyOf, children: childrenOf }, folded),
|
|
78
|
+
[specs, folded],
|
|
79
|
+
);
|
|
80
|
+
// The drops of every place, offered by menu whether its row stands or not.
|
|
81
|
+
const { paths, drops } = useMemo(() => {
|
|
82
|
+
const paths = new Map<string, string>();
|
|
83
|
+
const drops: { drop: Drop; path: string; route: string }[] = [];
|
|
84
|
+
walk(specs, "", paths, drops);
|
|
85
|
+
return { paths, drops };
|
|
86
|
+
}, [specs]);
|
|
87
|
+
useListedDrops(drops);
|
|
88
|
+
// The key of the row holding the one tab stop: the last focused, else the
|
|
89
|
+
// current place's.
|
|
90
|
+
const [active, setActive] = useState<string>();
|
|
91
|
+
const stop = treeStop(rows, active ?? route);
|
|
92
|
+
const box = useRef<HTMLDivElement>(null);
|
|
93
|
+
const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {
|
|
94
|
+
// A key's target is the focused element, an HTML one here.
|
|
95
|
+
const target = event.target as HTMLElement;
|
|
96
|
+
if (target.getAttribute("role") !== "treeitem") return;
|
|
97
|
+
// Space does nothing on a row (WAI-ARIA): it is no page scroll either.
|
|
98
|
+
if (event.key === " ") {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (event.key === "Enter") {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
// The anchor does what a press on the row does.
|
|
105
|
+
target.querySelector("a")?.click();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const at = rows.findIndex((each) => each.key === target.dataset.key);
|
|
109
|
+
const move = treeMove(rows, at, event.key);
|
|
110
|
+
if (!move) return;
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
if ("focus" in move) {
|
|
113
|
+
// Every visible row is mounted, in the rows' order.
|
|
114
|
+
box.current
|
|
115
|
+
?.querySelectorAll<HTMLElement>('[role="treeitem"]')
|
|
116
|
+
[move.focus]?.focus();
|
|
117
|
+
} else choose(move.fold, move.open);
|
|
118
|
+
};
|
|
119
|
+
return (
|
|
120
|
+
<div
|
|
121
|
+
ref={box}
|
|
122
|
+
role="tree"
|
|
123
|
+
aria-label={label}
|
|
124
|
+
onKeyDown={onKeyDown}
|
|
125
|
+
onFocus={(event) => {
|
|
126
|
+
const { target } = event;
|
|
127
|
+
if (!(target instanceof HTMLElement)) return;
|
|
128
|
+
const key =
|
|
129
|
+
target.closest<HTMLElement>('[role="treeitem"]')?.dataset.key;
|
|
130
|
+
if (key !== undefined) setActive(key);
|
|
131
|
+
}}
|
|
132
|
+
className={TREE}
|
|
133
|
+
>
|
|
134
|
+
{rows.map((each, index) => (
|
|
135
|
+
<TreeRow
|
|
136
|
+
key={each.key}
|
|
137
|
+
spec={each.item}
|
|
138
|
+
path={paths.get(each.key) ?? each.item.label}
|
|
139
|
+
depth={each.depth}
|
|
140
|
+
size={each.size}
|
|
141
|
+
place={each.place}
|
|
142
|
+
branch={each.branch}
|
|
143
|
+
open={each.open}
|
|
144
|
+
tabbable={index === stop}
|
|
145
|
+
current={each.key === route}
|
|
146
|
+
onPath={trail.some((one) => one.route === each.key)}
|
|
147
|
+
onToggle={() => choose(each.key, !each.open)}
|
|
148
|
+
onPlace={onPlace}
|
|
149
|
+
/>
|
|
150
|
+
))}
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// One place of the tree: its row (a `treeitem` that takes the drop and the
|
|
156
|
+
// keys), the anchor that goes to the place, and a branch's fold act at the end.
|
|
157
|
+
function TreeRow(props: {
|
|
158
|
+
spec: PlaceSpec;
|
|
159
|
+
path: string;
|
|
160
|
+
depth: number;
|
|
161
|
+
size: number;
|
|
162
|
+
place: number;
|
|
163
|
+
branch: boolean;
|
|
164
|
+
open: boolean;
|
|
165
|
+
tabbable: boolean;
|
|
166
|
+
current: boolean;
|
|
167
|
+
onPath: boolean;
|
|
168
|
+
onToggle: () => void;
|
|
169
|
+
onPlace?: () => void;
|
|
170
|
+
}) {
|
|
171
|
+
const { spec, branch, open, current, onPath, onToggle, onPlace } = props;
|
|
172
|
+
const words = useWords();
|
|
173
|
+
const { mark, over } = useDrop(spec.drop, spec.route, props.path);
|
|
174
|
+
// A folded branch opens under a drag held over it that a place inside takes.
|
|
175
|
+
const hold = useHold(
|
|
176
|
+
branch && !open
|
|
177
|
+
? { wants: (kind) => takes(spec, kind), open: onToggle }
|
|
178
|
+
: undefined,
|
|
179
|
+
);
|
|
180
|
+
const state = current ? "selected" : "rest";
|
|
181
|
+
// The place the current one is under keeps the ink of a selected one.
|
|
182
|
+
const ink = current || onPath ? "selected" : "rest";
|
|
183
|
+
// A branch that is no page (a spot, `#folder`) only opens and folds.
|
|
184
|
+
const folder = branch && !isPage(spec.route);
|
|
185
|
+
const level: VarStyle = { "--level": props.depth };
|
|
186
|
+
return (
|
|
187
|
+
<div
|
|
188
|
+
role="treeitem"
|
|
189
|
+
tabIndex={props.tabbable ? 0 : -1}
|
|
190
|
+
aria-level={props.depth + 1}
|
|
191
|
+
aria-setsize={props.size}
|
|
192
|
+
aria-posinset={props.place}
|
|
193
|
+
aria-expanded={branch ? open : undefined}
|
|
194
|
+
aria-current={current ? "page" : onPath ? "true" : undefined}
|
|
195
|
+
data-key={spec.route}
|
|
196
|
+
{...mark}
|
|
197
|
+
{...hold}
|
|
198
|
+
style={level}
|
|
199
|
+
className={cn(
|
|
200
|
+
placeRow({ state }),
|
|
201
|
+
ROW_BOX,
|
|
202
|
+
current ? ROW_SELECTED_PRESS : PRESS_WASH,
|
|
203
|
+
over && DROP_ON,
|
|
204
|
+
)}
|
|
205
|
+
>
|
|
206
|
+
{props.depth > 0 ? (
|
|
207
|
+
<span aria-hidden="true" className={PLACE_NEST} />
|
|
208
|
+
) : null}
|
|
209
|
+
<a
|
|
210
|
+
href={spec.route}
|
|
211
|
+
tabIndex={-1}
|
|
212
|
+
onClick={(event) => {
|
|
213
|
+
if (folder) {
|
|
214
|
+
event.preventDefault();
|
|
215
|
+
onToggle();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
follow(event);
|
|
219
|
+
onPlace?.();
|
|
220
|
+
}}
|
|
221
|
+
className={HIT}
|
|
222
|
+
>
|
|
223
|
+
<span className={cn(placeRowGlyph({ state: ink }), GLYPH)}>
|
|
224
|
+
<Icon name={spec.icon} />
|
|
225
|
+
</span>
|
|
226
|
+
<span
|
|
227
|
+
className={cn(
|
|
228
|
+
text({ role: "body" }),
|
|
229
|
+
placeRowGlyph({ state: ink }),
|
|
230
|
+
LABEL,
|
|
231
|
+
)}
|
|
232
|
+
>
|
|
233
|
+
{spec.label}
|
|
234
|
+
</span>
|
|
235
|
+
{spec.count === undefined ? null : (
|
|
236
|
+
<span className={cn(text({ role: "caption" }), PLACE_COUNT)}>
|
|
237
|
+
{spec.count}
|
|
238
|
+
</span>
|
|
239
|
+
)}
|
|
240
|
+
</a>
|
|
241
|
+
{branch ? (
|
|
242
|
+
<IconButtonBase
|
|
243
|
+
icon="ChevronDown"
|
|
244
|
+
open={open}
|
|
245
|
+
label={`${open ? words.collapse : words.expand} ${spec.label}`}
|
|
246
|
+
tabIndex={-1}
|
|
247
|
+
onClick={onToggle}
|
|
248
|
+
/>
|
|
249
|
+
) : null}
|
|
250
|
+
</div>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Slider as Base } from "@base-ui/react/slider";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { Draft } from "@slotform/ui-core/react/acts";
|
|
4
|
+
import {
|
|
5
|
+
ANSWER,
|
|
6
|
+
SLIDER,
|
|
7
|
+
SLIDER_FILL,
|
|
8
|
+
SLIDER_HEAD,
|
|
9
|
+
SLIDER_LABEL,
|
|
10
|
+
SLIDER_REST,
|
|
11
|
+
SLIDER_THUMB,
|
|
12
|
+
SLIDER_TRACK,
|
|
13
|
+
SLIDER_VALUE,
|
|
14
|
+
} from "@slotform/ui-core/variants";
|
|
15
|
+
import { PAINT_CONTROL_HIDDEN } from "../../lib/paint.tsx";
|
|
16
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
17
|
+
import type { SliderProps } from "./index.tsx";
|
|
18
|
+
|
|
19
|
+
const BOX = "flex flex-col justify-center";
|
|
20
|
+
const HEAD = "flex items-center justify-between";
|
|
21
|
+
const LABEL = "truncate data-disabled:text-ink-disabled";
|
|
22
|
+
const VALUE = "shrink-0 truncate data-disabled:text-ink-disabled";
|
|
23
|
+
// The track's inline padding is half the knob, so Base UI maps the pointer over
|
|
24
|
+
// the track less the knob, the knob's centre's travel; the fill and the rest
|
|
25
|
+
// run over that padding to the track's ends. The track stands on a body line
|
|
26
|
+
// (`SLIDER_TRACK`) and its hit box is the target, centred on it: a pseudo
|
|
27
|
+
// element of the track's own, which a press lands on as on the track, reaching
|
|
28
|
+
// over the gap above and the inset below and taking no room.
|
|
29
|
+
const TRACK =
|
|
30
|
+
"group relative flex items-center px-[calc(var(--spacing-icon-meta)/2)] before:absolute before:inset-x-0 before:top-1/2 before:h-target before:-translate-y-1/2 before:content-['']";
|
|
31
|
+
// The fill and the rest stand a knob's width apart: the fill's end margin is
|
|
32
|
+
// the knob's room (the thumb itself is out of the flow), not an element.
|
|
33
|
+
const FILL =
|
|
34
|
+
"grow -ms-[calc(var(--spacing-icon-meta)/2)] me-icon-meta group-hover:bg-toggle-on-hover group-active:bg-toggle-on-hover group-data-disabled:bg-ink-disabled";
|
|
35
|
+
// The thumb is the target-sized hit box, its centre on the gap between the fill
|
|
36
|
+
// and the rest: the fill's width plus half the knob (`--share`, the value's
|
|
37
|
+
// share of the range), set by CSS from the first frame. It holds the knob and
|
|
38
|
+
// Base UI's range input, whose box is the thumb's, so the target is the box
|
|
39
|
+
// and the knob stays the drawn size.
|
|
40
|
+
const THUMB =
|
|
41
|
+
"group/thumb [inset-inline-start:calc((100%-var(--spacing-icon-meta))*var(--share)+var(--spacing-icon-meta)/2)]! flex size-target items-center justify-center";
|
|
42
|
+
const KNOB =
|
|
43
|
+
"relative shrink-0 overflow-hidden in-data-[modality=keyboard]:group-has-focus-visible/thumb:outline-2 group-has-focus-visible/thumb:outline-offset-2 group-has-focus-visible/thumb:outline-ring group-data-disabled/thumb:border-edge group-data-disabled/thumb:bg-fill-disabled";
|
|
44
|
+
const WASH = `absolute inset-0 ${ANSWER} not-in-data-disabled:group-hover:bg-wash-hover not-in-data-disabled:group-active:bg-wash-press`;
|
|
45
|
+
const REST =
|
|
46
|
+
"grow -me-[calc(var(--spacing-icon-meta)/2)] group-data-disabled:bg-edge";
|
|
47
|
+
|
|
48
|
+
/** The label, value and track every Slider renders, on the `draft` its host holds: a field hosts the draft of its slider and draws a rejection in its own line. Painted, the label stands and the value and the track are filled, at the same height. Outside the package's exports. */
|
|
49
|
+
export function SliderBase({
|
|
50
|
+
label,
|
|
51
|
+
draft,
|
|
52
|
+
onChange,
|
|
53
|
+
onCommit,
|
|
54
|
+
min,
|
|
55
|
+
max,
|
|
56
|
+
step,
|
|
57
|
+
unit,
|
|
58
|
+
bare,
|
|
59
|
+
said,
|
|
60
|
+
}: Omit<SliderProps, "value"> & {
|
|
61
|
+
draft: Draft<number>;
|
|
62
|
+
/** The track alone, its name only the thumb's: a slider in a bar (the player dock's seek and volume) that draws no head over its track. */
|
|
63
|
+
bare?: boolean;
|
|
64
|
+
/** The thumb's value as words (`3:07`), where the number's own is not what a viewer reads. */
|
|
65
|
+
said?: (value: number) => string;
|
|
66
|
+
}) {
|
|
67
|
+
const ended = draft.ended;
|
|
68
|
+
const painted = draft.painted && !ended;
|
|
69
|
+
// Painted or ended, the thumb rests at the start: the value is the placeholder.
|
|
70
|
+
const at = draft.painted ? min : draft.value;
|
|
71
|
+
// The fill and the rest share the track less the knob in proportion to
|
|
72
|
+
// the value, and the knob sits in the gap between them, so neither runs
|
|
73
|
+
// under it. Base UI's `center` alignment places the thumb by the value
|
|
74
|
+
// alone, measuring nothing, and maps the pointer over the track's content
|
|
75
|
+
// box, the track less the knob.
|
|
76
|
+
const track: VarStyle = {
|
|
77
|
+
"--share":
|
|
78
|
+
max > min ? Math.min(1, Math.max(0, (at - min) / (max - min))) : 0,
|
|
79
|
+
};
|
|
80
|
+
return (
|
|
81
|
+
<Base.Root
|
|
82
|
+
value={at}
|
|
83
|
+
onValueChange={(next) => {
|
|
84
|
+
draft.change(next);
|
|
85
|
+
if (!ended) onChange(next);
|
|
86
|
+
}}
|
|
87
|
+
onValueCommitted={(next) => {
|
|
88
|
+
if (onCommit) draft.change(next, () => onCommit(next));
|
|
89
|
+
}}
|
|
90
|
+
min={min}
|
|
91
|
+
max={max}
|
|
92
|
+
step={step}
|
|
93
|
+
format={unit ? { style: "unit", unit } : undefined}
|
|
94
|
+
thumbAlignment="center"
|
|
95
|
+
className={cn(SLIDER, BOX)}
|
|
96
|
+
// Base UI marks a disabled slider with `data-disabled` alone; the label
|
|
97
|
+
// and value read as disabled to a checker through `aria-disabled` here.
|
|
98
|
+
render={(root, state) => (
|
|
99
|
+
<div
|
|
100
|
+
{...root}
|
|
101
|
+
aria-disabled={state.disabled || ended || undefined}
|
|
102
|
+
inert={painted || undefined}
|
|
103
|
+
/>
|
|
104
|
+
)}
|
|
105
|
+
>
|
|
106
|
+
{bare ? null : (
|
|
107
|
+
<div className={cn(SLIDER_HEAD, HEAD)}>
|
|
108
|
+
<Base.Label className={cn(SLIDER_LABEL, LABEL)}>{label}</Base.Label>
|
|
109
|
+
<Base.Value
|
|
110
|
+
className={cn(SLIDER_VALUE, VALUE, draft.painted && "invisible")}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
)}
|
|
114
|
+
<Base.Control
|
|
115
|
+
className={cn(SLIDER_TRACK, TRACK, painted && PAINT_CONTROL_HIDDEN)}
|
|
116
|
+
style={track}
|
|
117
|
+
>
|
|
118
|
+
<span
|
|
119
|
+
className={cn(SLIDER_FILL, FILL)}
|
|
120
|
+
style={{ flexGrow: at - min }}
|
|
121
|
+
/>
|
|
122
|
+
<span
|
|
123
|
+
className={cn(SLIDER_REST, REST)}
|
|
124
|
+
style={{ flexGrow: max - at }}
|
|
125
|
+
/>
|
|
126
|
+
{/* Named by the label's text itself: Base UI's reference to the label's element reads as no label to a checker once the label is scrolled out of view, leaving the description. */}
|
|
127
|
+
<Base.Thumb
|
|
128
|
+
aria-label={label}
|
|
129
|
+
getAriaValueText={said ? (_, value) => said(value) : undefined}
|
|
130
|
+
className={cn(THUMB, ended && "opacity-0")}
|
|
131
|
+
>
|
|
132
|
+
<span className={cn(SLIDER_THUMB, KNOB)}>
|
|
133
|
+
<span className={WASH} />
|
|
134
|
+
</span>
|
|
135
|
+
</Base.Thumb>
|
|
136
|
+
</Base.Control>
|
|
137
|
+
</Base.Root>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FieldOwned } from "@slotform/ui-core/react/field";
|
|
2
|
+
import type { Datum } from "@slotform/ui-core/read";
|
|
3
|
+
import { use } from "react";
|
|
4
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
5
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
6
|
+
import type { Fielded } from "../../lib/field.ts";
|
|
7
|
+
import { FieldBody } from "../form-field/index.tsx";
|
|
8
|
+
import { SliderBase } from "./base.tsx";
|
|
9
|
+
|
|
10
|
+
/** A number picked along a range, its label over the track. */
|
|
11
|
+
export interface SliderProps extends Closed, Fielded {
|
|
12
|
+
/** The value, between `min` and `max`. A selection paints the track, inert, until its read lands and follows it until the viewer moves it. Once its read ended the control stands with no value and a change says why instead. */
|
|
13
|
+
value: Datum<number>;
|
|
14
|
+
/** Hears each value the viewer moves it to. */
|
|
15
|
+
onChange: (value: number) => void;
|
|
16
|
+
/** Hears the value the viewer lets go of the thumb on (a key's step is one). Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
17
|
+
onCommit?: (value: number) => unknown;
|
|
18
|
+
/** The value at the track's start. */
|
|
19
|
+
min: number;
|
|
20
|
+
/** The value at the track's end. */
|
|
21
|
+
max: number;
|
|
22
|
+
/** The distance between two values it can take; 1 unless set. */
|
|
23
|
+
step?: number;
|
|
24
|
+
/** An Intl unit identifier (`minute`, `percent`), formatted after the value in the viewer's locale. */
|
|
25
|
+
unit?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A slider's label and value over its track: the fill up to the thumb, the rest after it, the label naming the thumb (it truncates). Placed alone it is its field, the description or the error under the track. Painted, the label stands and the value and the track are filled, at the same height. */
|
|
29
|
+
export function Slider({
|
|
30
|
+
label,
|
|
31
|
+
description,
|
|
32
|
+
optional,
|
|
33
|
+
error,
|
|
34
|
+
value,
|
|
35
|
+
...range
|
|
36
|
+
}: SliderProps) {
|
|
37
|
+
if (use(FieldOwned))
|
|
38
|
+
return <OwnedSlider label={label} value={value} {...range} />;
|
|
39
|
+
return (
|
|
40
|
+
<FieldBody
|
|
41
|
+
alone
|
|
42
|
+
label={label}
|
|
43
|
+
description={description}
|
|
44
|
+
optional={optional}
|
|
45
|
+
error={error}
|
|
46
|
+
slider={{ value, ...range }}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A slider whose owner draws its field: it holds its own draft.
|
|
52
|
+
function OwnedSlider({
|
|
53
|
+
value,
|
|
54
|
+
...rest
|
|
55
|
+
}: Omit<SliderProps, "description" | "optional" | "error">) {
|
|
56
|
+
return <SliderBase {...rest} draft={useHeldDraft(value)} />;
|
|
57
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { Stage, StageEnd, StepState } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { stagesShown } from "@slotform/ui-core/list-state";
|
|
4
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
5
|
+
import { type Datum, paints } from "@slotform/ui-core/read";
|
|
6
|
+
import { type RailState, railBelow, WAITING } from "@slotform/ui-core/stages";
|
|
7
|
+
import {
|
|
8
|
+
BLOCK_IN,
|
|
9
|
+
FIGURES,
|
|
10
|
+
FLOW_IN,
|
|
11
|
+
lineBox,
|
|
12
|
+
STAGE_CHECK,
|
|
13
|
+
STAGE_CROSS,
|
|
14
|
+
STAGE_ROW,
|
|
15
|
+
STAGE_WORDS,
|
|
16
|
+
stage,
|
|
17
|
+
stageMark,
|
|
18
|
+
stageRail,
|
|
19
|
+
text,
|
|
20
|
+
} from "@slotform/ui-core/variants";
|
|
21
|
+
import type { ReactNode } from "react";
|
|
22
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
23
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
24
|
+
import { moment } from "../../lib/moment.ts";
|
|
25
|
+
import { PAINT_CONTROL, Painted } from "../../lib/paint.tsx";
|
|
26
|
+
import { Swap } from "../../lib/swap.tsx";
|
|
27
|
+
|
|
28
|
+
const LIST = "flex flex-col min-w-0";
|
|
29
|
+
const ROW = "flex min-w-0";
|
|
30
|
+
// The marks' column is the mark's width, the rail running down its middle,
|
|
31
|
+
// and stands the row's full height over its vertical padding (`-my-gap`), so
|
|
32
|
+
// the rail is one line from the first mark to the last: a rail-coloured
|
|
33
|
+
// spacer of that padding above the mark, the mark's own line box in its two
|
|
34
|
+
// halves around it, the rest below.
|
|
35
|
+
const MARKS = "flex flex-col items-center shrink-0 w-icon-meta -my-gap";
|
|
36
|
+
const MARK = "flex flex-col items-center h-lh shrink-0";
|
|
37
|
+
const SHAPE = "shrink-0";
|
|
38
|
+
// A glyph mark (the check on its disc, the cross) centres its icon.
|
|
39
|
+
const GLYPH = "flex shrink-0";
|
|
40
|
+
const RAIL = "grow w-0";
|
|
41
|
+
const LEAD = "h-gap w-0 shrink-0";
|
|
42
|
+
const WORDS = "flex flex-col min-w-0";
|
|
43
|
+
|
|
44
|
+
/** A rail of fixed states. */
|
|
45
|
+
export interface StagesProps extends Closed {
|
|
46
|
+
/** The stages in order, each done, current or later; a done or current one may carry the moment it was reached. A selection paints a rail of later stages, and the rail is inert, until its read lands. */
|
|
47
|
+
steps: Datum<readonly Stage[]>;
|
|
48
|
+
/** How the rail ended: the terminal row in place of every stage after the last done one, its reason under its label. */
|
|
49
|
+
ended?: StageEnd;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Row(props: {
|
|
53
|
+
state: StepState | "ended";
|
|
54
|
+
mark: ReactNode;
|
|
55
|
+
last: boolean;
|
|
56
|
+
// The rail is waiting: its marks are painted.
|
|
57
|
+
painted?: boolean;
|
|
58
|
+
// The rail the row before runs down to this mark; none above the first.
|
|
59
|
+
above?: RailState;
|
|
60
|
+
current?: boolean;
|
|
61
|
+
// The terminal row replacing the later stages: a block, fading in as it
|
|
62
|
+
// mounts.
|
|
63
|
+
block?: boolean;
|
|
64
|
+
children: ReactNode;
|
|
65
|
+
}) {
|
|
66
|
+
// A later label is meta text, so its mark stands on a meta line.
|
|
67
|
+
const role = props.state === "later" ? "meta" : "body";
|
|
68
|
+
const below = props.last
|
|
69
|
+
? undefined
|
|
70
|
+
: stageRail({ state: railBelow(props.state) });
|
|
71
|
+
return (
|
|
72
|
+
<li
|
|
73
|
+
aria-current={props.current ? "step" : undefined}
|
|
74
|
+
className={cn(STAGE_ROW, ROW, props.block && BLOCK_IN)}
|
|
75
|
+
>
|
|
76
|
+
<span className={MARKS}>
|
|
77
|
+
<span
|
|
78
|
+
className={cn(props.above && stageRail({ state: props.above }), LEAD)}
|
|
79
|
+
/>
|
|
80
|
+
<span className={cn(lineBox({ role }), MARK)}>
|
|
81
|
+
<span
|
|
82
|
+
className={cn(
|
|
83
|
+
props.above && stageRail({ state: props.above }),
|
|
84
|
+
RAIL,
|
|
85
|
+
)}
|
|
86
|
+
/>
|
|
87
|
+
{/* A stage that advances while shown is a mark change; a waiting rail's switch to its loaded one lands at once. */}
|
|
88
|
+
{props.painted ? (
|
|
89
|
+
props.mark
|
|
90
|
+
) : (
|
|
91
|
+
<Swap id={props.state} scale>
|
|
92
|
+
{props.mark}
|
|
93
|
+
</Swap>
|
|
94
|
+
)}
|
|
95
|
+
<span className={cn(below, RAIL)} />
|
|
96
|
+
</span>
|
|
97
|
+
{props.last ? null : <span className={cn(below, RAIL)} />}
|
|
98
|
+
</span>
|
|
99
|
+
<span className={cn(props.last ? undefined : STAGE_WORDS, WORDS)}>
|
|
100
|
+
{props.children}
|
|
101
|
+
</span>
|
|
102
|
+
</li>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Its stages top to bottom on a hairline rail joining their marks, solid through the done stages: a done one a disc with a check and its moment under the label, the current one a ring in the accent with its label at 500, a later one a hollow ring with its label in meta; an ended rail closes on a danger cross, its label and its reason in meta. */
|
|
107
|
+
export function Stages({ steps, ended }: StagesProps) {
|
|
108
|
+
const [drawn] = useSelections([steps]);
|
|
109
|
+
const waits = paints(drawn);
|
|
110
|
+
// An ended read draws no stage; the frame that holds it says why.
|
|
111
|
+
let shown: readonly Stage[] = [];
|
|
112
|
+
if (waits) shown = WAITING;
|
|
113
|
+
else if (!drawn.painted)
|
|
114
|
+
shown = stagesShown(drawn.value, ended !== undefined);
|
|
115
|
+
const lastShown = shown.at(-1);
|
|
116
|
+
return (
|
|
117
|
+
<ol inert={waits || undefined} className={LIST}>
|
|
118
|
+
{shown.map((step, at) => {
|
|
119
|
+
const last = ended === undefined && at === shown.length - 1;
|
|
120
|
+
const before = shown[at - 1];
|
|
121
|
+
let mark = (
|
|
122
|
+
<span
|
|
123
|
+
aria-hidden
|
|
124
|
+
className={cn(stageMark({ state: "later" }), SHAPE)}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
if (waits)
|
|
128
|
+
mark = (
|
|
129
|
+
<span
|
|
130
|
+
aria-hidden
|
|
131
|
+
className={cn(
|
|
132
|
+
stageMark({ state: "later" }),
|
|
133
|
+
SHAPE,
|
|
134
|
+
PAINT_CONTROL,
|
|
135
|
+
)}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
else if (step.state === "done")
|
|
139
|
+
mark = (
|
|
140
|
+
<span
|
|
141
|
+
aria-hidden
|
|
142
|
+
className={cn(stageMark({ state: "done" }), STAGE_CHECK, GLYPH)}
|
|
143
|
+
>
|
|
144
|
+
<Icon name="Check" fit="meta" />
|
|
145
|
+
</span>
|
|
146
|
+
);
|
|
147
|
+
else if (step.state === "current")
|
|
148
|
+
mark = (
|
|
149
|
+
<span
|
|
150
|
+
aria-hidden
|
|
151
|
+
className={cn(stageMark({ state: "current" }), SHAPE)}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
return (
|
|
155
|
+
<Row
|
|
156
|
+
key={at}
|
|
157
|
+
state={step.state}
|
|
158
|
+
mark={mark}
|
|
159
|
+
painted={waits}
|
|
160
|
+
last={last}
|
|
161
|
+
above={before && railBelow(before.state)}
|
|
162
|
+
current={step.state === "current"}
|
|
163
|
+
>
|
|
164
|
+
<span className={stage({ state: step.state })}>
|
|
165
|
+
{waits ? <Painted role="name" at={at} /> : step.label}
|
|
166
|
+
</span>
|
|
167
|
+
{step.at ? (
|
|
168
|
+
<time
|
|
169
|
+
dateTime={step.at}
|
|
170
|
+
className={cn(text({ role: "meta" }), FIGURES, FLOW_IN)}
|
|
171
|
+
>
|
|
172
|
+
{moment(step.at)}
|
|
173
|
+
</time>
|
|
174
|
+
) : null}
|
|
175
|
+
</Row>
|
|
176
|
+
);
|
|
177
|
+
})}
|
|
178
|
+
{ended ? (
|
|
179
|
+
<Row
|
|
180
|
+
state="ended"
|
|
181
|
+
mark={
|
|
182
|
+
<span aria-hidden className={cn(STAGE_CROSS, GLYPH)}>
|
|
183
|
+
<Icon name="X" fit="meta" />
|
|
184
|
+
</span>
|
|
185
|
+
}
|
|
186
|
+
last
|
|
187
|
+
block
|
|
188
|
+
above={lastShown && railBelow(lastShown.state)}
|
|
189
|
+
>
|
|
190
|
+
<span className={stage({ state: "ended" })}>{ended.label}</span>
|
|
191
|
+
{ended.reason ? (
|
|
192
|
+
<span className={text({ role: "meta" })}>{ended.reason}</span>
|
|
193
|
+
) : null}
|
|
194
|
+
</Row>
|
|
195
|
+
) : null}
|
|
196
|
+
</ol>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { CountLink } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
4
|
+
import {
|
|
5
|
+
COUNT_LINKS,
|
|
6
|
+
FIGURES,
|
|
7
|
+
LINK_TARGET,
|
|
8
|
+
text,
|
|
9
|
+
} from "@slotform/ui-core/variants";
|
|
10
|
+
import { ButtonLink } from "../../atoms/button/link.tsx";
|
|
11
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
12
|
+
|
|
13
|
+
const COUNTS = "flex flex-wrap";
|
|
14
|
+
const PAINTED = "flex items-center";
|
|
15
|
+
|
|
16
|
+
const number = formatterFor("number");
|
|
17
|
+
|
|
18
|
+
/** A line of counts that lead to their lists: each a figure and its label as a standalone link on the target height; `painted` while the counts are not here, one link's target box and a phrase's filler. Outside the package's exports. */
|
|
19
|
+
export function CountLinks({
|
|
20
|
+
counts,
|
|
21
|
+
painted,
|
|
22
|
+
}: {
|
|
23
|
+
counts: readonly CountLink[];
|
|
24
|
+
painted?: boolean;
|
|
25
|
+
}) {
|
|
26
|
+
if (painted)
|
|
27
|
+
return (
|
|
28
|
+
<p className={cn(text({ role: "meta" }), COUNT_LINKS, COUNTS)}>
|
|
29
|
+
<span className={cn(LINK_TARGET, PAINTED)}>
|
|
30
|
+
<Painted role="phrase" />
|
|
31
|
+
</span>
|
|
32
|
+
</p>
|
|
33
|
+
);
|
|
34
|
+
return (
|
|
35
|
+
<p className={cn(text({ role: "meta" }), COUNT_LINKS, COUNTS)}>
|
|
36
|
+
{counts.map((count, at) => (
|
|
37
|
+
<ButtonLink key={at} href={count.href}>
|
|
38
|
+
{/* A standalone link is a flex box, whose bare text drops the space. */}
|
|
39
|
+
<span>
|
|
40
|
+
<span className={FIGURES}>{number.format(count.value)}</span>{" "}
|
|
41
|
+
{count.label}
|
|
42
|
+
</span>
|
|
43
|
+
</ButtonLink>
|
|
44
|
+
))}
|
|
45
|
+
</p>
|
|
46
|
+
);
|
|
47
|
+
}
|