@vitavision/workbench 0.2.0 → 0.3.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 +6 -5
- package/dist/index.d.ts +201 -7
- package/dist/index.js +260 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/AppShell.tsx +3 -2
- package/src/components/NavRail.tsx +213 -0
- package/src/components/SequenceNavigator.tsx +33 -8
- package/src/components/StatusBar.tsx +68 -0
- package/src/components/Stepper.tsx +151 -0
- package/src/components/stepperModel.ts +49 -0
- package/src/index.ts +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitavision/workbench",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Studio-app building blocks on @vitavision/ui: app shell, split panes, tree view, playback bar and playhead store, file drop (toasts re-exported from @vitavision/ui).",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"react-dom": "^19.2.0"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@vitavision/ui": "^0.
|
|
49
|
+
"@vitavision/ui": "^0.12.0",
|
|
50
50
|
"lucide-react": "^1.48.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
@@ -34,7 +34,8 @@ export interface AppShellProps {
|
|
|
34
34
|
header?: ReactNode;
|
|
35
35
|
/**
|
|
36
36
|
* A fixed-width column at the far left, outside the resizable panels: an icon rail of
|
|
37
|
-
* workspaces
|
|
37
|
+
* workspaces, such as a `NavRail`. It takes its content's width and is a `<nav>` named by
|
|
38
|
+
* `railLabel`.
|
|
38
39
|
*/
|
|
39
40
|
rail?: ReactNode;
|
|
40
41
|
/** Names the rail's landmark (`<nav>`). Defaults to "Workspaces". */
|
|
@@ -45,7 +46,7 @@ export interface AppShellProps {
|
|
|
45
46
|
main: ReactNode;
|
|
46
47
|
/** The panel right of the main surface — an inspector. */
|
|
47
48
|
right?: ReactNode;
|
|
48
|
-
/** The strip along the bottom, across the whole width — a `PlaybackBar`, a
|
|
49
|
+
/** The strip along the bottom, across the whole width — a `PlaybackBar`, a `StatusBar`. */
|
|
49
50
|
bottom?: ReactNode;
|
|
50
51
|
/** Names the left panel's landmark (`<aside>`). Defaults to "Navigator". */
|
|
51
52
|
leftLabel?: string | undefined;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The workspaces of a studio app as a column of icons down its left edge: Library, Teach,
|
|
3
|
+
* Inspect. One is current; choosing another swaps the screen.
|
|
4
|
+
*
|
|
5
|
+
* Each item is a button, or — through `asChild` — the app's own link element, so a router's
|
|
6
|
+
* `<Link>` keeps client-side navigation and this package never imports a router.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
cloneElement,
|
|
11
|
+
createContext,
|
|
12
|
+
isValidElement,
|
|
13
|
+
use,
|
|
14
|
+
useId,
|
|
15
|
+
useState,
|
|
16
|
+
type HTMLAttributes,
|
|
17
|
+
type MouseEvent,
|
|
18
|
+
type ReactElement,
|
|
19
|
+
type ReactNode,
|
|
20
|
+
} from "react";
|
|
21
|
+
|
|
22
|
+
import { Tooltip, cn, focusRing } from "@vitavision/ui";
|
|
23
|
+
|
|
24
|
+
/** How a `NavRail` shows its items' labels. */
|
|
25
|
+
export type NavRailLabels = "visible" | "tooltip";
|
|
26
|
+
|
|
27
|
+
/** Props of `NavRail`. */
|
|
28
|
+
export interface NavRailProps {
|
|
29
|
+
/** The current item's `value`, or `null` for none. Leave undefined to let the rail keep it. */
|
|
30
|
+
value?: string | null | undefined;
|
|
31
|
+
/** The current item at first, when the rail keeps it (`value` undefined). */
|
|
32
|
+
defaultValue?: string | undefined;
|
|
33
|
+
/** Called with an item's `value` when a person chooses an item other than the current one. */
|
|
34
|
+
onValueChange?: ((value: string) => void) | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* `"visible"` (the default) sets each label under its icon; `"tooltip"` draws icon-only
|
|
37
|
+
* buttons and shows the label in a tooltip on hover or focus.
|
|
38
|
+
*/
|
|
39
|
+
labels?: NavRailLabels | undefined;
|
|
40
|
+
/** The `NavRailItem`s, in order. */
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
/** Merged with the list's own classes through `cn`. */
|
|
43
|
+
className?: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Props of `NavRailItem`. */
|
|
47
|
+
export interface NavRailItemProps {
|
|
48
|
+
/** Identifies the item to the rail's `value`. Unique within the rail. */
|
|
49
|
+
value: string;
|
|
50
|
+
/** The item's name: its text under the icon, or its tooltip and accessible name. */
|
|
51
|
+
label: string;
|
|
52
|
+
/** The item's icon, decorative (`aria-hidden`): the label carries the meaning. */
|
|
53
|
+
icon: ReactNode;
|
|
54
|
+
/**
|
|
55
|
+
* A mark on the icon's corner: a number is drawn as a count (over 99 as "99+"), anything
|
|
56
|
+
* else as given. It describes the item (`aria-describedby`); it is not part of its name.
|
|
57
|
+
*/
|
|
58
|
+
badge?: ReactNode | number;
|
|
59
|
+
/** Shown but not choosable. A link item gets `aria-disabled` and its clicks are cancelled. */
|
|
60
|
+
disabled?: boolean | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Render onto the one child element — a router's `<Link to="…" />` or an `<a href>` —
|
|
63
|
+
* instead of a `<button>`. Give the child without content: the icon and label become its
|
|
64
|
+
* children. Its own `className` is kept beside the item's, and its own `onClick` runs first;
|
|
65
|
+
* calling `event.preventDefault()` there keeps the item from being chosen.
|
|
66
|
+
*/
|
|
67
|
+
asChild?: boolean | undefined;
|
|
68
|
+
/** With `asChild`, the one element to render as. */
|
|
69
|
+
children?: ReactElement | undefined;
|
|
70
|
+
/** Merged with the item's own classes through `cn`. */
|
|
71
|
+
className?: string | undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface NavRailState {
|
|
75
|
+
value: string | null;
|
|
76
|
+
labels: NavRailLabels;
|
|
77
|
+
choose: (value: string) => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const NavRailContext = createContext<NavRailState | null>(null);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A vertical rail of workspaces: `NavRailItem`s as a list of buttons (or the app's links, via
|
|
84
|
+
* `asChild`), one of them current. Controlled with `value` and `onValueChange`, or kept by the
|
|
85
|
+
* rail from `defaultValue`.
|
|
86
|
+
*
|
|
87
|
+
* The current item carries `aria-current="page"` and `data-state="active"` (the others
|
|
88
|
+
* `"inactive"`). Every item is its own Tab stop. The rail is a plain list with no landmark of
|
|
89
|
+
* its own: `AppShell`'s `rail` slot is already a named `<nav>`, so elsewhere wrap it in a
|
|
90
|
+
* `<nav aria-label="…">`.
|
|
91
|
+
*/
|
|
92
|
+
export function NavRail({ value, defaultValue, onValueChange, labels = "visible", children, className }: NavRailProps) {
|
|
93
|
+
const [kept, setKept] = useState<string | null>(defaultValue ?? null);
|
|
94
|
+
const current = value === undefined ? kept : value;
|
|
95
|
+
const choose = (next: string) => {
|
|
96
|
+
if (next === current) return;
|
|
97
|
+
if (value === undefined) setKept(next);
|
|
98
|
+
onValueChange?.(next);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<NavRailContext value={{ value: current, labels, choose }}>
|
|
103
|
+
<ul data-labels={labels} className={cn("flex flex-col items-center gap-1 p-1.5", className)}>
|
|
104
|
+
{children}
|
|
105
|
+
</ul>
|
|
106
|
+
</NavRailContext>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* One workspace of a `NavRail`: an icon over its label, or an icon-only button with the label
|
|
112
|
+
* in a tooltip (the rail's `labels`). A `<button>` by default; with `asChild`, the one child
|
|
113
|
+
* element (the app's link) takes the item's look, `aria-current` and click.
|
|
114
|
+
*/
|
|
115
|
+
export function NavRailItem({
|
|
116
|
+
value,
|
|
117
|
+
label,
|
|
118
|
+
icon,
|
|
119
|
+
badge,
|
|
120
|
+
disabled = false,
|
|
121
|
+
asChild = false,
|
|
122
|
+
children,
|
|
123
|
+
className,
|
|
124
|
+
}: NavRailItemProps) {
|
|
125
|
+
const rail = use(NavRailContext);
|
|
126
|
+
if (rail === null) throw new Error("NavRailItem must be rendered inside a NavRail.");
|
|
127
|
+
const badgeId = useId();
|
|
128
|
+
|
|
129
|
+
const active = rail.value === value;
|
|
130
|
+
const iconOnly = rail.labels === "tooltip";
|
|
131
|
+
const hasBadge = badge !== undefined && badge !== null && badge !== false;
|
|
132
|
+
|
|
133
|
+
const content = (
|
|
134
|
+
<>
|
|
135
|
+
<span aria-hidden className="relative grid place-items-center [&>svg]:size-4.5">
|
|
136
|
+
{icon}
|
|
137
|
+
{hasBadge && (
|
|
138
|
+
<span
|
|
139
|
+
id={badgeId}
|
|
140
|
+
data-badge=""
|
|
141
|
+
className={cn(
|
|
142
|
+
"absolute -top-1.5 left-[calc(100%-0.375rem)]",
|
|
143
|
+
typeof badge === "number" &&
|
|
144
|
+
"min-w-4 rounded-full bg-signal px-1 text-center font-mono text-[10px] leading-4 text-signal-fg tabular-nums",
|
|
145
|
+
)}
|
|
146
|
+
>
|
|
147
|
+
{typeof badge === "number" ? formatCount(badge) : badge}
|
|
148
|
+
</span>
|
|
149
|
+
)}
|
|
150
|
+
</span>
|
|
151
|
+
{!iconOnly && <span className="max-w-full truncate text-[10px] leading-tight">{label}</span>}
|
|
152
|
+
</>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const shared = {
|
|
156
|
+
"aria-current": active ? ("page" as const) : undefined,
|
|
157
|
+
"aria-label": iconOnly ? label : undefined,
|
|
158
|
+
"aria-describedby": hasBadge ? badgeId : undefined,
|
|
159
|
+
"data-state": active ? "active" : "inactive",
|
|
160
|
+
"data-disabled": disabled ? "" : undefined,
|
|
161
|
+
};
|
|
162
|
+
const classes = cn(
|
|
163
|
+
"relative flex flex-col items-center justify-center gap-0.5 rounded-control text-fg-muted transition-colors",
|
|
164
|
+
iconOnly ? "size-9" : "w-14 px-1 py-1.5",
|
|
165
|
+
active ? "bg-signal/12 text-fg [&_svg]:text-signal" : "hover:bg-raised hover:text-fg",
|
|
166
|
+
disabled && "cursor-not-allowed opacity-50 hover:bg-transparent hover:text-fg-muted",
|
|
167
|
+
focusRing,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
let item: ReactElement;
|
|
171
|
+
if (asChild && isValidElement<ChildProps>(children)) {
|
|
172
|
+
const own = children.props;
|
|
173
|
+
// `@vitavision/ui` keeps its Slot to itself, and this package takes no Radix dependency of
|
|
174
|
+
// its own: the one child element is cloned with the item's props merged in.
|
|
175
|
+
// eslint-disable-next-line @eslint-react/no-clone-element -- the asChild merge, see above
|
|
176
|
+
item = cloneElement(children, {
|
|
177
|
+
...shared,
|
|
178
|
+
"aria-disabled": disabled ? true : undefined,
|
|
179
|
+
className: cn(classes, className, own.className),
|
|
180
|
+
onClick: (event: MouseEvent<HTMLElement>) => {
|
|
181
|
+
own.onClick?.(event);
|
|
182
|
+
if (disabled) {
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!event.defaultPrevented) rail.choose(value);
|
|
187
|
+
},
|
|
188
|
+
children: content,
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
item = (
|
|
192
|
+
<button
|
|
193
|
+
type="button"
|
|
194
|
+
{...shared}
|
|
195
|
+
disabled={disabled}
|
|
196
|
+
onClick={() => rail.choose(value)}
|
|
197
|
+
className={cn(classes, className)}
|
|
198
|
+
>
|
|
199
|
+
{content}
|
|
200
|
+
</button>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return <li>{iconOnly ? <Tooltip content={label}>{item}</Tooltip> : item}</li>;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The props `asChild` reads from, and merges into, the child element. */
|
|
208
|
+
type ChildProps = HTMLAttributes<HTMLElement> & Partial<Record<`data-${string}`, string>>;
|
|
209
|
+
|
|
210
|
+
/** A badge count: up to 99 as is, more as "99+". */
|
|
211
|
+
function formatCount(count: number): string {
|
|
212
|
+
return count > 99 ? "99+" : String(count);
|
|
213
|
+
}
|
|
@@ -10,10 +10,21 @@
|
|
|
10
10
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
11
11
|
import { useEffect, useRef, type ReactNode } from "react";
|
|
12
12
|
|
|
13
|
-
import { Button, Kbd, cn, focusRing } from "@vitavision/ui";
|
|
13
|
+
import { Button, Kbd, StatusDot, cn, focusRing, type Tone } from "@vitavision/ui";
|
|
14
14
|
|
|
15
15
|
import { stepIndex } from "./sequence";
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A per-item status — "not found" in a batch run, "rejected" by a reviewer — drawn as a dot in
|
|
19
|
+
* the thumbnail's corner and said in words in the item's name.
|
|
20
|
+
*/
|
|
21
|
+
export interface SequenceItemStatus {
|
|
22
|
+
/** The dot's colour, by meaning; also the item's `data-status`. */
|
|
23
|
+
tone: Tone;
|
|
24
|
+
/** The status in words, appended to the item's name and tooltip: `"frame_0003.bmp, not found"`. */
|
|
25
|
+
label: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
/** One item of a `SequenceNavigator`. */
|
|
18
29
|
export interface SequenceItem {
|
|
19
30
|
/** Its identity, unique in the sequence. */
|
|
@@ -22,6 +33,8 @@ export interface SequenceItem {
|
|
|
22
33
|
label: string;
|
|
23
34
|
/** A thumbnail URL, loaded lazily. Without it, the default rendering is the label. */
|
|
24
35
|
thumbnail?: string | undefined;
|
|
36
|
+
/** A status, drawn as a dot in the thumbnail's corner over any thumbnail rendering. */
|
|
37
|
+
status?: SequenceItemStatus | undefined;
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
/** Props of `SequenceNavigator`. */
|
|
@@ -49,8 +62,11 @@ export interface SequenceNavigatorProps {
|
|
|
49
62
|
* ("3 / 50").
|
|
50
63
|
*
|
|
51
64
|
* The current thumbnail carries `aria-current="true"` and `data-current`, has an outline,
|
|
52
|
-
* and is scrolled into view when it changes.
|
|
53
|
-
*
|
|
65
|
+
* and is scrolled into view when it changes. An item with a `status` shows a dot in its
|
|
66
|
+
* corner, carries `data-status` (the tone) and is named `"label, status"`. `[` and `]` step
|
|
67
|
+
* from anywhere outside a text field. Thumbnails load lazily, so a capture of thousands of
|
|
68
|
+
* frames opens at once. The strip is as wide as its thumbnails, so previous and next stay
|
|
69
|
+
* beside a short sequence; a long one scrolls.
|
|
54
70
|
*/
|
|
55
71
|
export function SequenceNavigator({
|
|
56
72
|
items,
|
|
@@ -104,22 +120,27 @@ export function SequenceNavigator({
|
|
|
104
120
|
disabled={items.length < 2 || atStart}
|
|
105
121
|
onClick={() => step(-1)}
|
|
106
122
|
/>
|
|
107
|
-
|
|
123
|
+
{/* The padding (and the matching scroll padding, for the current item scrolled into view)
|
|
124
|
+
is the room for the current ring and the focus outline: the scroller clips at its edge. */}
|
|
125
|
+
<ol ref={listRef} aria-label={ariaLabel} className="flex min-w-0 scroll-px-1 gap-1 overflow-x-auto p-1">
|
|
108
126
|
{items.map((item) => {
|
|
109
127
|
const current = item.id === value;
|
|
128
|
+
const { status } = item;
|
|
129
|
+
const name = status ? `${item.label}, ${status.label}` : item.label;
|
|
110
130
|
return (
|
|
111
131
|
<li key={item.id} className="shrink-0">
|
|
112
132
|
<button
|
|
113
133
|
type="button"
|
|
114
|
-
title={
|
|
115
|
-
aria-label={
|
|
134
|
+
title={name}
|
|
135
|
+
aria-label={name}
|
|
116
136
|
aria-current={current ? "true" : undefined}
|
|
117
137
|
data-current={current ? "" : undefined}
|
|
138
|
+
data-status={status?.tone}
|
|
118
139
|
onClick={() => {
|
|
119
140
|
if (!current) onValueChange(item.id);
|
|
120
141
|
}}
|
|
121
142
|
className={cn(
|
|
122
|
-
"block h-10 w-14 overflow-hidden rounded-control border border-line bg-raised text-fg",
|
|
143
|
+
"relative block h-10 w-14 overflow-hidden rounded-control border border-line bg-raised text-fg",
|
|
123
144
|
"data-current:ring-2 data-current:ring-signal",
|
|
124
145
|
focusRing,
|
|
125
146
|
)}
|
|
@@ -129,7 +150,11 @@ export function SequenceNavigator({
|
|
|
129
150
|
) : item.thumbnail ? (
|
|
130
151
|
<img src={item.thumbnail} alt="" loading="lazy" decoding="async" className="h-full w-full object-cover" />
|
|
131
152
|
) : (
|
|
132
|
-
<span className="block truncate px-1 font-mono text-[10px]">{item.label}</span>
|
|
153
|
+
<span className={cn("block truncate px-1 font-mono text-[10px]", status && "pr-3")}>{item.label}</span>
|
|
154
|
+
)}
|
|
155
|
+
{status && (
|
|
156
|
+
// The surface-coloured backing keeps the dot legible over any thumbnail.
|
|
157
|
+
<StatusDot tone={status.tone} className="absolute top-0.5 right-0.5 rounded-full bg-surface p-0.5" />
|
|
133
158
|
)}
|
|
134
159
|
</button>
|
|
135
160
|
</li>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The status line along the foot of a studio app: what the app is doing and what it is
|
|
3
|
+
* showing — the duration of the last operation, the current frame, the model in use.
|
|
4
|
+
*
|
|
5
|
+
* Studio apps each grew one, and each placed, sized and spaced its facts differently. This is
|
|
6
|
+
* the one line, built from `ReadoutStrip`, so the facts read like the readouts everywhere else:
|
|
7
|
+
* mono, quiet labels, separated by a dot.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
|
|
12
|
+
import { ReadoutStrip, cn, type ReadoutItem } from "@vitavision/ui";
|
|
13
|
+
|
|
14
|
+
/** Props of `StatusBar`. */
|
|
15
|
+
export interface StatusBarProps {
|
|
16
|
+
/** The facts at the left end, in order. Items whose `value` is `null` or `undefined` are skipped. */
|
|
17
|
+
start?: ReadoutItem[] | undefined;
|
|
18
|
+
/** The facts at the right end, in order. Items whose `value` is `null` or `undefined` are skipped. */
|
|
19
|
+
end?: ReadoutItem[] | undefined;
|
|
20
|
+
/** Drawn between the two ends, e.g. a `ProgressBar` while an operation runs. */
|
|
21
|
+
children?: ReactNode;
|
|
22
|
+
/** Names the bar. Defaults to "Status". */
|
|
23
|
+
"aria-label"?: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Announce changes to the bar's content politely (`role="status"`) instead of leaving it a
|
|
26
|
+
* plain named group. Defaults to false.
|
|
27
|
+
*/
|
|
28
|
+
live?: boolean | undefined;
|
|
29
|
+
/** Merged with the bar's own classes through `cn`. */
|
|
30
|
+
className?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* One 24 px line of facts for `AppShell`'s `bottom` slot: a `ReadoutStrip` of `start` items at
|
|
35
|
+
* the left end, one of `end` items at the right end, and `children` between them.
|
|
36
|
+
*
|
|
37
|
+
* It is a `role="group"` named by `aria-label` ("Status"). With `live` it is a
|
|
38
|
+
* `role="status"` instead (a polite live region, and `data-live`), so a screen reader
|
|
39
|
+
* announces what changes in it: use that for facts worth hearing when they change (an
|
|
40
|
+
* operation finished), not for ones that change many times a second. The line does not wrap;
|
|
41
|
+
* keep it to a few short facts.
|
|
42
|
+
*/
|
|
43
|
+
export function StatusBar({
|
|
44
|
+
start,
|
|
45
|
+
end,
|
|
46
|
+
children,
|
|
47
|
+
"aria-label": ariaLabel = "Status",
|
|
48
|
+
live = false,
|
|
49
|
+
className,
|
|
50
|
+
}: StatusBarProps) {
|
|
51
|
+
const hasChildren = children !== undefined && children !== null && children !== false;
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
role={live ? "status" : "group"}
|
|
55
|
+
aria-label={ariaLabel}
|
|
56
|
+
aria-live={live ? "polite" : undefined}
|
|
57
|
+
data-live={live ? "" : undefined}
|
|
58
|
+
className={cn("flex h-6 min-w-0 items-center gap-3 overflow-hidden px-3", className)}
|
|
59
|
+
>
|
|
60
|
+
{start && <ReadoutStrip items={start} className={STRIP} />}
|
|
61
|
+
{hasChildren && <div className="flex min-w-0 flex-1 items-center gap-2">{children}</div>}
|
|
62
|
+
{end && <ReadoutStrip items={end} className={cn(STRIP, "ml-auto")} />}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** One line: the strip's own wrapping would push the second line out of a 24 px bar. */
|
|
68
|
+
const STRIP = "shrink-0 flex-nowrap whitespace-nowrap";
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A gated sequence of steps — Teach, then Find, then Verify — where a step can be entered
|
|
3
|
+
* only once what it depends on is in place, and says what that is.
|
|
4
|
+
*
|
|
5
|
+
* A disabled button would say nothing: it cannot be focused, so neither the tooltip nor a
|
|
6
|
+
* screen reader can give the reason. A blocked step stays focusable, marked
|
|
7
|
+
* `aria-disabled`, and carries its reason as its description.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Check, Lock } from "lucide-react";
|
|
11
|
+
import { useId, useState, type ReactNode } from "react";
|
|
12
|
+
|
|
13
|
+
import { Tooltip, cn, focusRing } from "@vitavision/ui";
|
|
14
|
+
|
|
15
|
+
import { stepStates, type StepState } from "./stepperModel";
|
|
16
|
+
|
|
17
|
+
/** One step of a `Stepper`. */
|
|
18
|
+
export interface StepperStep {
|
|
19
|
+
/** Its identity, unique among the steps; the stepper's `value`. */
|
|
20
|
+
id: string;
|
|
21
|
+
/** Its name. */
|
|
22
|
+
label: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Why it cannot be entered yet — "Teach a model first". A step with a reason is blocked:
|
|
25
|
+
* shown, focusable and described by the reason, but not choosable.
|
|
26
|
+
*/
|
|
27
|
+
blockedBy?: string | undefined;
|
|
28
|
+
/** Marks it done (a check instead of its number). */
|
|
29
|
+
complete?: boolean | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Props of `Stepper`. */
|
|
33
|
+
export interface StepperProps {
|
|
34
|
+
/** The steps, in order. */
|
|
35
|
+
steps: readonly StepperStep[];
|
|
36
|
+
/** The current step's id, or `null` for none. Leave undefined to let the stepper keep it. */
|
|
37
|
+
value?: string | null | undefined;
|
|
38
|
+
/** The current step at first, when the stepper keeps it. Defaults to the first step. */
|
|
39
|
+
defaultValue?: string | undefined;
|
|
40
|
+
/** Called with a step's id when a person chooses a step that is neither current nor blocked. */
|
|
41
|
+
onValueChange?: ((id: string) => void) | undefined;
|
|
42
|
+
/** A row (the default) or a column. */
|
|
43
|
+
orientation?: "horizontal" | "vertical" | undefined;
|
|
44
|
+
/** Names the list of steps. */
|
|
45
|
+
"aria-label": string;
|
|
46
|
+
/** Merged with the list's own classes through `cn`. */
|
|
47
|
+
className?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The steps of a gated sequence as an ordered list of buttons, numbered, with the current one
|
|
52
|
+
* marked (`aria-current="step"`) and done ones checked. Controlled with `value` and
|
|
53
|
+
* `onValueChange`, or kept by the stepper from `defaultValue`.
|
|
54
|
+
*
|
|
55
|
+
* A step with `blockedBy` is blocked: it keeps its Tab stop but carries `aria-disabled`, its
|
|
56
|
+
* reason is its description (`aria-describedby`) and its tooltip, and choosing it does nothing.
|
|
57
|
+
* Each step carries `data-state` (`current`, `complete`, `blocked` or `upcoming`), and the
|
|
58
|
+
* list `data-orientation`.
|
|
59
|
+
*/
|
|
60
|
+
export function Stepper({
|
|
61
|
+
steps,
|
|
62
|
+
value,
|
|
63
|
+
defaultValue,
|
|
64
|
+
onValueChange,
|
|
65
|
+
orientation = "horizontal",
|
|
66
|
+
"aria-label": ariaLabel,
|
|
67
|
+
className,
|
|
68
|
+
}: StepperProps) {
|
|
69
|
+
const [kept, setKept] = useState<string | null>(() => defaultValue ?? steps[0]?.id ?? null);
|
|
70
|
+
const current = value === undefined ? kept : value;
|
|
71
|
+
const views = stepStates(steps, current);
|
|
72
|
+
const baseId = useId();
|
|
73
|
+
const vertical = orientation === "vertical";
|
|
74
|
+
|
|
75
|
+
const choose = (id: string) => {
|
|
76
|
+
if (value === undefined) setKept(id);
|
|
77
|
+
onValueChange?.(id);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<ol
|
|
82
|
+
aria-label={ariaLabel}
|
|
83
|
+
data-orientation={orientation}
|
|
84
|
+
className={cn("flex", vertical ? "flex-col items-start" : "flex-wrap items-center gap-y-1", className)}
|
|
85
|
+
>
|
|
86
|
+
{steps.map((step, index) => {
|
|
87
|
+
const view = views[index];
|
|
88
|
+
if (view === undefined) return null;
|
|
89
|
+
const { state, canActivate } = view;
|
|
90
|
+
const blocked = state === "blocked";
|
|
91
|
+
const reasonId = `${baseId}-${index}-reason`;
|
|
92
|
+
const button = (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
aria-current={state === "current" ? "step" : undefined}
|
|
96
|
+
aria-disabled={blocked ? true : undefined}
|
|
97
|
+
aria-describedby={blocked ? reasonId : undefined}
|
|
98
|
+
data-state={state}
|
|
99
|
+
onClick={() => {
|
|
100
|
+
if (canActivate) choose(step.id);
|
|
101
|
+
}}
|
|
102
|
+
className={cn(
|
|
103
|
+
"flex items-center gap-2 rounded-control px-1.5 py-1 text-sm transition-colors",
|
|
104
|
+
state === "current" ? "font-medium text-fg" : "text-fg-muted",
|
|
105
|
+
canActivate && "hover:text-fg",
|
|
106
|
+
blocked && "cursor-not-allowed",
|
|
107
|
+
focusRing,
|
|
108
|
+
)}
|
|
109
|
+
>
|
|
110
|
+
<StepMarker state={state} number={index + 1} />
|
|
111
|
+
<span>{step.label}</span>
|
|
112
|
+
</button>
|
|
113
|
+
);
|
|
114
|
+
return (
|
|
115
|
+
<li key={step.id} className={cn("flex", vertical ? "flex-col items-start" : "items-center")}>
|
|
116
|
+
{index > 0 && (
|
|
117
|
+
<span
|
|
118
|
+
aria-hidden
|
|
119
|
+
className={cn("bg-line-strong", vertical ? "ml-4 h-3 w-px" : "mx-1 h-px w-6")}
|
|
120
|
+
/>
|
|
121
|
+
)}
|
|
122
|
+
{blocked ? <Tooltip content={step.blockedBy}>{button}</Tooltip> : button}
|
|
123
|
+
{blocked && (
|
|
124
|
+
<span id={reasonId} className="sr-only">
|
|
125
|
+
{step.blockedBy}
|
|
126
|
+
</span>
|
|
127
|
+
)}
|
|
128
|
+
</li>
|
|
129
|
+
);
|
|
130
|
+
})}
|
|
131
|
+
</ol>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The step's number in a circle; a check when done, a lock when blocked. Decorative. */
|
|
136
|
+
function StepMarker({ state, number }: { state: StepState; number: number }) {
|
|
137
|
+
return (
|
|
138
|
+
<span
|
|
139
|
+
aria-hidden
|
|
140
|
+
className={cn(
|
|
141
|
+
"grid size-5 shrink-0 place-items-center rounded-full border font-mono text-[11px] tabular-nums [&>svg]:size-3",
|
|
142
|
+
state === "current" && "border-signal bg-signal text-signal-fg",
|
|
143
|
+
state === "complete" && "border-signal text-signal",
|
|
144
|
+
state === "blocked" && "border-line-strong text-fg-muted",
|
|
145
|
+
state === "upcoming" && "border-line-strong text-fg-muted",
|
|
146
|
+
)}
|
|
147
|
+
>
|
|
148
|
+
{state === "complete" ? <Check /> : state === "blocked" ? <Lock /> : number}
|
|
149
|
+
</span>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What each step of a `Stepper` is, as a pure function, so the rules (a blocked step cannot
|
|
3
|
+
* be entered, the current step outranks every other state) are tested without a DOM.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a step stands: `current` (the one a person is on), `blocked` (cannot be entered
|
|
8
|
+
* yet; it says why), `complete` (done) or `upcoming` (not done, and open).
|
|
9
|
+
*/
|
|
10
|
+
export type StepState = "current" | "complete" | "blocked" | "upcoming";
|
|
11
|
+
|
|
12
|
+
/** The part of a step its state depends on. */
|
|
13
|
+
export interface StepGate {
|
|
14
|
+
/** Its identity, unique among the steps. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Why it cannot be entered yet. A step with a non-empty reason is blocked. */
|
|
17
|
+
blockedBy?: string | undefined;
|
|
18
|
+
/** Whether it is done. */
|
|
19
|
+
complete?: boolean | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One step's state, and whether choosing it would make it current. */
|
|
23
|
+
export interface StepView {
|
|
24
|
+
/** The step's id. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Where the step stands. */
|
|
27
|
+
state: StepState;
|
|
28
|
+
/** True when choosing it makes it current: it is neither blocked nor current already. */
|
|
29
|
+
canActivate: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Each step's state, in order.
|
|
34
|
+
*
|
|
35
|
+
* The step whose id is `current` is `current`, whatever else is true of it: the app put the
|
|
36
|
+
* person there. Of the others, one with a `blockedBy` reason is `blocked` (even if `complete`:
|
|
37
|
+
* a step can be done and then fall behind a newer gate), then `complete`, then `upcoming`.
|
|
38
|
+
* Only a step that is neither current nor blocked can be activated.
|
|
39
|
+
*
|
|
40
|
+
* @param steps - The steps, in order.
|
|
41
|
+
* @param current - The current step's id, or `null` for none.
|
|
42
|
+
*/
|
|
43
|
+
export function stepStates(steps: readonly StepGate[], current: string | null): StepView[] {
|
|
44
|
+
return steps.map(({ id, blockedBy, complete }) => {
|
|
45
|
+
const state: StepState =
|
|
46
|
+
id === current ? "current" : blockedBy ? "blocked" : complete ? "complete" : "upcoming";
|
|
47
|
+
return { id, state, canActivate: state === "complete" || state === "upcoming" };
|
|
48
|
+
});
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@vitavision/workbench` — the building blocks of a studio app on `@vitavision/ui`: the
|
|
3
|
-
* shell
|
|
4
|
-
* file opening, and (re-exported from
|
|
3
|
+
* shell, its split panes, workspace rail and status bar, a tree navigator, a stepper, a
|
|
4
|
+
* playback transport over a sampled timeline, file opening, and (re-exported from
|
|
5
|
+
* `@vitavision/ui`) notifications.
|
|
5
6
|
*
|
|
6
7
|
* Import `@vitavision/workbench/styles.css` after `@vitavision/ui/styles.css`.
|
|
7
8
|
*
|
|
@@ -9,6 +10,14 @@
|
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
export { AppShell, type AppShellProps, type SidePanelSize } from "./components/AppShell";
|
|
13
|
+
export { StatusBar, type StatusBarProps } from "./components/StatusBar";
|
|
14
|
+
export {
|
|
15
|
+
NavRail,
|
|
16
|
+
NavRailItem,
|
|
17
|
+
type NavRailItemProps,
|
|
18
|
+
type NavRailLabels,
|
|
19
|
+
type NavRailProps,
|
|
20
|
+
} from "./components/NavRail";
|
|
12
21
|
export { SplitPane, type SplitPaneProps } from "./components/SplitPane";
|
|
13
22
|
export {
|
|
14
23
|
type PaneSize,
|
|
@@ -58,10 +67,14 @@ export { acceptsFile, acceptsPath, collectDroppedFiles, type DropEntry } from ".
|
|
|
58
67
|
export {
|
|
59
68
|
SequenceNavigator,
|
|
60
69
|
type SequenceItem,
|
|
70
|
+
type SequenceItemStatus,
|
|
61
71
|
type SequenceNavigatorProps,
|
|
62
72
|
} from "./components/SequenceNavigator";
|
|
63
73
|
export { stepIndex } from "./components/sequence";
|
|
64
74
|
|
|
75
|
+
export { Stepper, type StepperProps, type StepperStep } from "./components/Stepper";
|
|
76
|
+
export { type StepGate, type StepState, type StepView, stepStates } from "./components/stepperModel";
|
|
77
|
+
|
|
65
78
|
// Notifications moved to `@vitavision/ui` (a second app needed them). These are re-exports of
|
|
66
79
|
// the same bindings, so there is still one default store; prefer importing from `@vitavision/ui`.
|
|
67
80
|
export {
|