@slotform/react-ui 0.0.0-stage → 0.1.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/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,76 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { type ReactNode, use, useMemo, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
type PaneKind,
|
|
5
|
+
PanesContainer,
|
|
6
|
+
ShellMenu,
|
|
7
|
+
} from "../../lib/container.ts";
|
|
8
|
+
import { DistanceContext } from "../../lib/media.ts";
|
|
9
|
+
|
|
10
|
+
// The Panes holds at most two Panes: docs/architecture/ui-core/layout.md, "Panes".
|
|
11
|
+
const PLACE = "@container/place flex grow min-h-0 min-w-0";
|
|
12
|
+
const SHARE =
|
|
13
|
+
"[&>[data-page]:not(:last-of-type)]:w-list [&>[data-page]:not(:last-of-type)]:min-w-region-min [&>[data-page]:not(:last-of-type)]:shrink [&>[data-page]:not(:last-of-type)]:grow-0 [&>[data-page]:not(:last-of-type)]:basis-auto [&>[data-page]:not(:last-of-type)]:border-e [&>[data-page]:not(:last-of-type)]:border-edge place-tablet:[&>[data-page]:last-of-type:not(:first-of-type)]:min-w-[min(var(--container-list),calc(100%-var(--container-region-min)))]";
|
|
14
|
+
const CANVAS =
|
|
15
|
+
"[&>[data-page][data-fill]:not(:last-of-type):has([data-wide])]:grow [&>[data-page][data-fill]:not(:last-of-type):has([data-wide])]:basis-0 place-tablet:[&>[data-fill]:has([data-wide])+[data-page]:last-of-type:not([data-expanded])]:grow-0 place-tablet:[&>[data-fill]:has([data-wide])+[data-page]:last-of-type:not([data-expanded])]:basis-auto place-tablet:[&>[data-fill]:has([data-wide])+[data-page]:last-of-type:not([data-expanded])]:w-list";
|
|
16
|
+
const FOLD =
|
|
17
|
+
"place-max-tablet:[&>[data-page]:not(:last-of-type)]:hidden [&>[data-page]:has(~[data-expanded])]:hidden";
|
|
18
|
+
// Only a record's head draws these acts: docs/architecture/ui-core/layout.md, "Panes".
|
|
19
|
+
const ACTS =
|
|
20
|
+
"[&>[data-page]]:[--pane-back:none] [&>[data-page]]:[--pane-close:flex] [&>[data-page]]:[--pane-expand:none] [&>[data-page]:not(:first-of-type)]:[--pane-expand:flex] place-max-tablet:[&>[data-page]]:[--pane-back:flex] place-max-tablet:[&>[data-page]]:[--pane-close:none] place-max-tablet:[&>[data-page]:not(:first-of-type)]:[--pane-expand:none]";
|
|
21
|
+
// A place read from across a room is one column that never splits: only its
|
|
22
|
+
// last Pane stands, alone, and its head draws the room's acts itself.
|
|
23
|
+
const ROOM = "[&>[data-page]:not(:last-of-type)]:hidden";
|
|
24
|
+
|
|
25
|
+
// The page's one `h1` is the Panes's: docs/architecture/ui-core/layout.md, "Headings".
|
|
26
|
+
const NAME = "sr-only";
|
|
27
|
+
|
|
28
|
+
// A room Panes states its distance: docs/architecture/ui-core/layout.md, "Panes".
|
|
29
|
+
export function Panes(props: {
|
|
30
|
+
distance?: "room";
|
|
31
|
+
/** The page's `h1`, the name of where you are, drawn apart from sight; the place's Pane takes it as its title and a record's Pane draws it before the record's name. The Shell gives it the current place's name, so a route inside a Shell writes none; a room page standing without a Shell writes it once. */
|
|
32
|
+
title?: string;
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
}) {
|
|
35
|
+
const far = props.distance === "room";
|
|
36
|
+
const menu = use(ShellMenu);
|
|
37
|
+
const [stand] = useState(standing);
|
|
38
|
+
const frame = useMemo(
|
|
39
|
+
() => ({ name: props.title, stand }),
|
|
40
|
+
[props.title, stand],
|
|
41
|
+
);
|
|
42
|
+
return (
|
|
43
|
+
<DistanceContext value={far}>
|
|
44
|
+
<ShellMenu value={far ? undefined : menu}>
|
|
45
|
+
<PanesContainer value={frame}>
|
|
46
|
+
<div
|
|
47
|
+
data-density={far ? "room" : undefined}
|
|
48
|
+
className={cn(PLACE, SHARE, CANVAS, FOLD, ACTS, far && ROOM)}
|
|
49
|
+
>
|
|
50
|
+
{props.title ? <h1 className={NAME}>{props.title}</h1> : null}
|
|
51
|
+
{props.children}
|
|
52
|
+
</div>
|
|
53
|
+
</PanesContainer>
|
|
54
|
+
</ShellMenu>
|
|
55
|
+
</DistanceContext>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// What a second Pane of a kind in one Panes breaks.
|
|
60
|
+
const SECOND: Record<PaneKind, string> = {
|
|
61
|
+
record:
|
|
62
|
+
"Panes: a second record's Pane; a record linked from a record opens in its own place",
|
|
63
|
+
place: "Panes: a second place's Pane; a place's tabs stand in its one Pane",
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// A Panes holds one Pane of each kind: docs/architecture/ui-core/layout.md, "Panes".
|
|
67
|
+
function standing(): (kind: PaneKind) => () => void {
|
|
68
|
+
const count: Record<PaneKind, number> = { place: 0, record: 0 };
|
|
69
|
+
return (kind) => {
|
|
70
|
+
if (count[kind] === 1) throw new Error(SECOND[kind]);
|
|
71
|
+
count[kind] += 1;
|
|
72
|
+
return () => {
|
|
73
|
+
count[kind] -= 1;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FocusEvent,
|
|
3
|
+
type KeyboardEvent,
|
|
4
|
+
type PointerEvent,
|
|
5
|
+
type RefObject,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import { keyed } from "../../lib/modality.ts";
|
|
11
|
+
|
|
12
|
+
// A pointer resting this long on an entry while no column stands opens that
|
|
13
|
+
// entry's column, so a sweep across the folded rail on the way to the page
|
|
14
|
+
// changes nothing; once a column stands, another entry's shows at once. One
|
|
15
|
+
// gone from the sidebar this long sends the preview back, so a slip past its
|
|
16
|
+
// edge changes nothing.
|
|
17
|
+
const DWELL = 120;
|
|
18
|
+
const LINGER = 150;
|
|
19
|
+
// A pointer that has not moved for this long rests. The aim reads the
|
|
20
|
+
// pointer's move over this last stretch, so a path from before a rest never
|
|
21
|
+
// says where it heads now, and reads it again this long later while it heads
|
|
22
|
+
// for the column, so a pointer that stops on an entry shows it a stretch on.
|
|
23
|
+
const STILL = 60;
|
|
24
|
+
|
|
25
|
+
// A spot in the viewport, and the pointer at one at a moment (`t`, the
|
|
26
|
+
// event's time).
|
|
27
|
+
interface Spot {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
}
|
|
31
|
+
interface Point extends Spot {
|
|
32
|
+
t: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What the rail's column shows, by entry key, and the handlers that move it. Outside the package's exports. */
|
|
36
|
+
interface Preview {
|
|
37
|
+
/** The entry the column shows now, inked on the rail; none while the folded rail stands at rest. */
|
|
38
|
+
shown: string | undefined;
|
|
39
|
+
/** The entry the column holds: `shown`, else (folded, the column gone) the one it showed last, so a column on its way out keeps its places. */
|
|
40
|
+
held: string | undefined;
|
|
41
|
+
/** A pointer came onto an entry (`wait`) or a focus landed on it (at once). */
|
|
42
|
+
point: (entry: string, wait: boolean) => void;
|
|
43
|
+
/** Drops an entry's pending preview: the pointer left it before the preview followed, or reached a part of the rail that previews nothing. */
|
|
44
|
+
hold: () => void;
|
|
45
|
+
/** Sends the preview back and drops anything pending, the column keeping what it shows now as the entry it showed last, so a column on its way out keeps its places. */
|
|
46
|
+
back: () => void;
|
|
47
|
+
/** The sidebar's handlers: where the pointer goes, where the focus stands, Escape. */
|
|
48
|
+
nav: {
|
|
49
|
+
onPointerEnter: () => void;
|
|
50
|
+
onPointerOut: (event: PointerEvent<HTMLElement>) => void;
|
|
51
|
+
onPointerMove: (event: PointerEvent<HTMLElement>) => void;
|
|
52
|
+
onPointerLeave: (event: PointerEvent<HTMLElement>) => void;
|
|
53
|
+
onFocus: (event: FocusEvent<HTMLElement>) => void;
|
|
54
|
+
onBlur: (event: FocusEvent<HTMLElement>) => void;
|
|
55
|
+
onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
|
|
56
|
+
};
|
|
57
|
+
/** The column's places (their ref, the runs a pointer aims for) and the column's handler: a pointer reaching it keeps what it shows. */
|
|
58
|
+
column: {
|
|
59
|
+
places: RefObject<HTMLDivElement | null>;
|
|
60
|
+
onPointerEnter: () => void;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The rail's column. A pointer resting on an entry or a focus on it previews
|
|
66
|
+
* that entry; a pointer heading for the column keeps what it shows while it
|
|
67
|
+
* crosses other entries. The preview goes back once the pointer and the focus
|
|
68
|
+
* have left the sidebar a moment, on Escape or when the route (`at`) changes;
|
|
69
|
+
* a menu open in the sidebar holds it, and so does a sheet one of its acts
|
|
70
|
+
* opened, whose pointer and focus stand inside it as React tells them, and a
|
|
71
|
+
* keyboard's focus inside it. At rest, docked, the column shows the entry of
|
|
72
|
+
* the current place (`owner`), else the one it showed last, else the first
|
|
73
|
+
* of `entries` (the rail's order); folded, nothing stands. A preview of an
|
|
74
|
+
* entry the rail no longer has shows nothing.
|
|
75
|
+
*/
|
|
76
|
+
export function usePreview(props: {
|
|
77
|
+
at: string;
|
|
78
|
+
docked: boolean;
|
|
79
|
+
owner: string | undefined;
|
|
80
|
+
entries: readonly string[];
|
|
81
|
+
}): Preview {
|
|
82
|
+
const { at, docked, owner, entries } = props;
|
|
83
|
+
const known = (entry: string | undefined) =>
|
|
84
|
+
entry !== undefined && entries.includes(entry) ? entry : undefined;
|
|
85
|
+
const top = entries[0];
|
|
86
|
+
const [shown, setShown] = useState<{
|
|
87
|
+
entry: string;
|
|
88
|
+
at: string;
|
|
89
|
+
open: boolean;
|
|
90
|
+
}>();
|
|
91
|
+
// The entry waiting to be shown, and the preview waiting to go back.
|
|
92
|
+
const opening = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
93
|
+
const closing = useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
94
|
+
const inside = useRef(false);
|
|
95
|
+
const focused = useRef(false);
|
|
96
|
+
// The pointer's last positions over the sidebar.
|
|
97
|
+
const path = useRef<readonly Point[]>([]);
|
|
98
|
+
const places = useRef<HTMLDivElement>(null);
|
|
99
|
+
useEffect(
|
|
100
|
+
() => () => {
|
|
101
|
+
clearTimeout(opening.current);
|
|
102
|
+
clearTimeout(closing.current);
|
|
103
|
+
},
|
|
104
|
+
[],
|
|
105
|
+
);
|
|
106
|
+
const live = shown?.open && shown.at === at ? known(shown.entry) : undefined;
|
|
107
|
+
const last = known(shown?.entry);
|
|
108
|
+
const standing = docked ? (live ?? owner ?? last ?? top) : live;
|
|
109
|
+
const show = (entry: string) => setShown({ entry, at, open: true });
|
|
110
|
+
const back = () => {
|
|
111
|
+
clearTimeout(opening.current);
|
|
112
|
+
clearTimeout(closing.current);
|
|
113
|
+
setShown((was) => {
|
|
114
|
+
const entry = standing ?? was?.entry;
|
|
115
|
+
return entry === undefined ? undefined : { entry, at, open: false };
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const point = (entry: string, wait: boolean) => {
|
|
119
|
+
clearTimeout(opening.current);
|
|
120
|
+
if (!wait) return show(entry);
|
|
121
|
+
// A pointer heading for the column's places keeps what it shows while it
|
|
122
|
+
// crosses other entries on the way: the switch waits until it rests,
|
|
123
|
+
// turns away, or reaches the column.
|
|
124
|
+
if (
|
|
125
|
+
standing !== undefined &&
|
|
126
|
+
standing !== entry &&
|
|
127
|
+
places.current &&
|
|
128
|
+
aiming(moving(path.current, performance.now()), places.current)
|
|
129
|
+
) {
|
|
130
|
+
opening.current = setTimeout(() => point(entry, true), STILL);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (standing !== undefined) return show(entry);
|
|
134
|
+
opening.current = setTimeout(() => show(entry), DWELL);
|
|
135
|
+
};
|
|
136
|
+
const hold = () => clearTimeout(opening.current);
|
|
137
|
+
const leave = (nav: HTMLElement) => {
|
|
138
|
+
clearTimeout(closing.current);
|
|
139
|
+
closing.current = setTimeout(() => {
|
|
140
|
+
const menu = nav.querySelector('[aria-haspopup][aria-expanded="true"]');
|
|
141
|
+
if (!(menu || (keyed() && focused.current) || inside.current)) back();
|
|
142
|
+
}, LINGER);
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
shown: standing,
|
|
146
|
+
held: standing ?? last ?? owner ?? top,
|
|
147
|
+
point,
|
|
148
|
+
hold,
|
|
149
|
+
back,
|
|
150
|
+
nav: {
|
|
151
|
+
onPointerEnter: () => {
|
|
152
|
+
inside.current = true;
|
|
153
|
+
},
|
|
154
|
+
// React tells an entry the pointer entered while it handles the
|
|
155
|
+
// `pointerout` of what the pointer left, ahead of any move to the new
|
|
156
|
+
// spot; that event carries the new spot, so the aim reads it first.
|
|
157
|
+
onPointerOut: (event) => {
|
|
158
|
+
path.current = tracked(path.current, event);
|
|
159
|
+
},
|
|
160
|
+
onPointerMove: (event) => {
|
|
161
|
+
path.current = tracked(path.current, event);
|
|
162
|
+
},
|
|
163
|
+
onPointerLeave: (event) => {
|
|
164
|
+
inside.current = false;
|
|
165
|
+
hold();
|
|
166
|
+
leave(event.currentTarget);
|
|
167
|
+
},
|
|
168
|
+
// A menu the column opened hands focus back as it closes: with the
|
|
169
|
+
// pointer gone, the preview goes back then.
|
|
170
|
+
onFocus: (event) => {
|
|
171
|
+
focused.current = true;
|
|
172
|
+
leave(event.currentTarget);
|
|
173
|
+
},
|
|
174
|
+
onBlur: (event) => {
|
|
175
|
+
focused.current = false;
|
|
176
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
177
|
+
leave(event.currentTarget);
|
|
178
|
+
},
|
|
179
|
+
onKeyDown: (event) => {
|
|
180
|
+
if (event.key === "Escape") back();
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
column: { places, onPointerEnter: hold },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The pointer's path with this position at its end (a repeated position kept
|
|
188
|
+
// once), cut to its move up to that moment.
|
|
189
|
+
function tracked(
|
|
190
|
+
path: readonly Point[],
|
|
191
|
+
event: { clientX: number; clientY: number; timeStamp: number },
|
|
192
|
+
): readonly Point[] {
|
|
193
|
+
const last = path.at(-1);
|
|
194
|
+
if (last && last.x === event.clientX && last.y === event.clientY) return path;
|
|
195
|
+
const point = { x: event.clientX, y: event.clientY, t: event.timeStamp };
|
|
196
|
+
return moving([...path, point], point.t);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// The pointer's move up to `at`: its positions over the last `STILL`, after
|
|
200
|
+
// the spot the move left from. None once it rests. An event's `timeStamp` and
|
|
201
|
+
// `performance.now()` share one clock.
|
|
202
|
+
function moving(path: readonly Point[], at: number): readonly Point[] {
|
|
203
|
+
const start = path.findIndex((one) => at - one.t <= STILL);
|
|
204
|
+
return start < 0 ? [] : path.slice(Math.max(0, start - 1));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Whether a pointer heads for the column's places, after Kamens's menu aim:
|
|
208
|
+
// its latest position stands inside the triangle from its oldest recent one
|
|
209
|
+
// to the near edge of the places it can reach, so its path points between
|
|
210
|
+
// that edge's two ends. The places' box runs the column's height while their
|
|
211
|
+
// rows end higher, so the edge ends at the last run's foot; a pointer drifting
|
|
212
|
+
// on its way down the rail aims at nothing below it. A pointer at or past the
|
|
213
|
+
// edge has reached the column. The places' `direction` puts the near edge on
|
|
214
|
+
// their left (`ltr`) or their right.
|
|
215
|
+
function aiming(path: readonly Point[], places: HTMLElement) {
|
|
216
|
+
const then = path[0];
|
|
217
|
+
const now = path.at(-1);
|
|
218
|
+
if (!then || !now || then === now) return false;
|
|
219
|
+
const box = places.getBoundingClientRect();
|
|
220
|
+
const foot = places.lastElementChild?.getBoundingClientRect().bottom;
|
|
221
|
+
const rtl = getComputedStyle(places).direction === "rtl";
|
|
222
|
+
const edge = rtl ? box.right : box.left;
|
|
223
|
+
if (rtl ? now.x <= edge : now.x >= edge) return false;
|
|
224
|
+
const top = { x: edge, y: box.top };
|
|
225
|
+
const bottom = { x: edge, y: Math.min(box.bottom, foot ?? box.top) };
|
|
226
|
+
const side = (a: Spot, b: Spot) =>
|
|
227
|
+
Math.sign((b.x - a.x) * (now.y - a.y) - (b.y - a.y) * (now.x - a.x));
|
|
228
|
+
const sides = [side(then, top), side(top, bottom), side(bottom, then)];
|
|
229
|
+
return !(sides.includes(1) && sides.includes(-1));
|
|
230
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { IconName } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import {
|
|
4
|
+
PRESS_WASH,
|
|
5
|
+
placeRow,
|
|
6
|
+
placeRowGlyph,
|
|
7
|
+
SHELL_RAIL_ENTRY,
|
|
8
|
+
SHELL_RAIL_GLYPH,
|
|
9
|
+
text,
|
|
10
|
+
} from "@slotform/ui-core/variants";
|
|
11
|
+
import type { PointerEvent } from "react";
|
|
12
|
+
import { Named } from "../../atoms/button/glyph.tsx";
|
|
13
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
14
|
+
import { follow } from "../../lib/navigate.ts";
|
|
15
|
+
import { GLYPH, LABEL, ROW_BOX, ROW_SELECTED_PRESS } from "./row.ts";
|
|
16
|
+
|
|
17
|
+
// The group's entry is a place row cut to an icon: the current bar and wash
|
|
18
|
+
// when the current place is in the group, the selected ink alone when its
|
|
19
|
+
// column is the one standing, as a branch on the path to the current place.
|
|
20
|
+
function look(current: boolean) {
|
|
21
|
+
return cn(
|
|
22
|
+
placeRow({ state: current ? "selected" : "rest" }),
|
|
23
|
+
ROW_BOX,
|
|
24
|
+
current ? ROW_SELECTED_PRESS : PRESS_WASH,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function glyph(icon: IconName, inked: boolean) {
|
|
29
|
+
return (
|
|
30
|
+
<span
|
|
31
|
+
className={cn(
|
|
32
|
+
placeRowGlyph({ state: inked ? "selected" : "rest" }),
|
|
33
|
+
GLYPH,
|
|
34
|
+
)}
|
|
35
|
+
>
|
|
36
|
+
<Icon name={icon} />
|
|
37
|
+
</span>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The rail entry's glyph keeps its control square at its start, so it stands
|
|
42
|
+
// still while the rail's clip uncovers the label after it.
|
|
43
|
+
function railFace(icon: IconName, label: string, inked: boolean) {
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<span className={SHELL_RAIL_GLYPH}>{glyph(icon, inked)}</span>
|
|
47
|
+
<span
|
|
48
|
+
className={cn(
|
|
49
|
+
text({ role: "body" }),
|
|
50
|
+
placeRowGlyph({ state: inked ? "selected" : "rest" }),
|
|
51
|
+
LABEL,
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{label}
|
|
55
|
+
</span>
|
|
56
|
+
</>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// An entry of the rail: a group's, whose press goes to its group's first place
|
|
61
|
+
// and which shows its group's column while a pointer rests on it or a focus
|
|
62
|
+
// stands on it, its label beside its glyph while the rail is open; a footer
|
|
63
|
+
// place's, which goes there; or the act that docks the column and folds it.
|
|
64
|
+
// The label is its accessible name; an entry given `named` wears it as its
|
|
65
|
+
// tooltip while it is true (the rail shut to its strip, which draws no label).
|
|
66
|
+
// Outside the package's exports.
|
|
67
|
+
export function RailEntry(props: {
|
|
68
|
+
icon: IconName;
|
|
69
|
+
label: string;
|
|
70
|
+
// The current place is the entry's own (`page`) or stands in its group.
|
|
71
|
+
current?: "page" | "true";
|
|
72
|
+
// Its group's column is the one standing.
|
|
73
|
+
shown?: boolean;
|
|
74
|
+
// Where a press goes: a footer place's route, a group's first place. None
|
|
75
|
+
// while the group's places wait, when a press shows its column.
|
|
76
|
+
href?: string;
|
|
77
|
+
// What a press runs where it goes nowhere (the dock act).
|
|
78
|
+
onPress?: () => void;
|
|
79
|
+
// A pointer came onto the entry (`wait`: its column follows a dwell later),
|
|
80
|
+
// or a focus or a press landed on it (at once).
|
|
81
|
+
onExpand?: (wait: boolean) => void;
|
|
82
|
+
// The pointer left the entry before its column followed.
|
|
83
|
+
onLeave?: () => void;
|
|
84
|
+
named?: boolean;
|
|
85
|
+
}) {
|
|
86
|
+
const {
|
|
87
|
+
icon,
|
|
88
|
+
label,
|
|
89
|
+
current,
|
|
90
|
+
shown,
|
|
91
|
+
href,
|
|
92
|
+
onPress,
|
|
93
|
+
onExpand,
|
|
94
|
+
onLeave,
|
|
95
|
+
named,
|
|
96
|
+
} = props;
|
|
97
|
+
const near = {
|
|
98
|
+
"aria-label": label,
|
|
99
|
+
"aria-current": current,
|
|
100
|
+
onPointerEnter: (event: PointerEvent<HTMLElement>) => {
|
|
101
|
+
if (event.pointerType !== "touch") onExpand?.(true);
|
|
102
|
+
},
|
|
103
|
+
onPointerLeave: () => onLeave?.(),
|
|
104
|
+
onFocus: () => onExpand?.(false),
|
|
105
|
+
className: cn(look(current !== undefined), SHELL_RAIL_ENTRY),
|
|
106
|
+
};
|
|
107
|
+
const face = railFace(icon, label, current !== undefined || shown === true);
|
|
108
|
+
const entry =
|
|
109
|
+
href === undefined ? (
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
{...near}
|
|
113
|
+
onClick={onPress ?? (() => onExpand?.(false))}
|
|
114
|
+
>
|
|
115
|
+
{face}
|
|
116
|
+
</button>
|
|
117
|
+
) : (
|
|
118
|
+
<a href={href} {...near} onClick={follow}>
|
|
119
|
+
{face}
|
|
120
|
+
</a>
|
|
121
|
+
);
|
|
122
|
+
// An entry that wears a tooltip some of the time keeps its place in the
|
|
123
|
+
// tree, so a strip opening and shutting never mounts it again.
|
|
124
|
+
return named === undefined ? (
|
|
125
|
+
entry
|
|
126
|
+
) : (
|
|
127
|
+
<Named label={label} off={!named}>
|
|
128
|
+
{entry}
|
|
129
|
+
</Named>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// A group on the touch layer's list: the rail's entry as a full row, with its
|
|
134
|
+
// label and a chevron on the way in. Outside the package's exports.
|
|
135
|
+
export function GroupRow(props: {
|
|
136
|
+
icon: IconName;
|
|
137
|
+
label: string;
|
|
138
|
+
current: boolean;
|
|
139
|
+
onPress: () => void;
|
|
140
|
+
}) {
|
|
141
|
+
return (
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
aria-current={props.current ? "true" : undefined}
|
|
145
|
+
onClick={props.onPress}
|
|
146
|
+
className={cn(look(props.current), "w-full text-start")}
|
|
147
|
+
>
|
|
148
|
+
{glyph(props.icon, props.current)}
|
|
149
|
+
<span
|
|
150
|
+
className={cn(
|
|
151
|
+
text({ role: "body" }),
|
|
152
|
+
placeRowGlyph({ state: props.current ? "selected" : "rest" }),
|
|
153
|
+
LABEL,
|
|
154
|
+
)}
|
|
155
|
+
>
|
|
156
|
+
{props.label}
|
|
157
|
+
</span>
|
|
158
|
+
<span className={cn(placeRowGlyph(), GLYPH)}>
|
|
159
|
+
<Icon name="ChevronRight" />
|
|
160
|
+
</span>
|
|
161
|
+
</button>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// What a place row in the sidebar is made of, shared by the flat row, the
|
|
2
|
+
// tree's (`tree.tsx`) and the switcher's trigger (`switcher.tsx`).
|
|
3
|
+
|
|
4
|
+
// A place's count: the meta ink, which holds its 4.5:1 on the current place's
|
|
5
|
+
// wash too, tabular figures, at the caption role.
|
|
6
|
+
export const PLACE_COUNT = "text-ink-meta tabular-nums";
|
|
7
|
+
// A place row rings inset, inside the sidebar's inset.
|
|
8
|
+
export const ROW_BOX = "flex items-center focus-visible:-outline-offset-2";
|
|
9
|
+
export const ROW_SELECTED_PRESS = "hover:bg-ink-body/10";
|
|
10
|
+
export const GLYPH = "flex shrink-0";
|
|
11
|
+
export const LABEL = "truncate grow";
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type {
|
|
3
|
+
IconLinkAct,
|
|
4
|
+
Option,
|
|
5
|
+
OptionGroup,
|
|
6
|
+
OptionPick,
|
|
7
|
+
} from "@slotform/ui-core/descriptors";
|
|
8
|
+
import { optionLeading } from "@slotform/ui-core/list-state";
|
|
9
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
10
|
+
import { type Datum, paints } from "@slotform/ui-core/read";
|
|
11
|
+
import {
|
|
12
|
+
FIELD_PLACEHOLDER,
|
|
13
|
+
PRESS_WASH,
|
|
14
|
+
placeRow,
|
|
15
|
+
placeRowGlyph,
|
|
16
|
+
SHELL_RAIL_ENTRY,
|
|
17
|
+
SHELL_RAIL_GLYPH,
|
|
18
|
+
text,
|
|
19
|
+
textStrong,
|
|
20
|
+
} from "@slotform/ui-core/variants";
|
|
21
|
+
import type { ReactNode } from "react";
|
|
22
|
+
import { AvatarBase } from "../../atoms/avatar/base.tsx";
|
|
23
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
24
|
+
import type { IconAct } from "../../lib/act.ts";
|
|
25
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
26
|
+
import { Avatar } from "../avatar/index.tsx";
|
|
27
|
+
import { HeldPicker } from "../picker/base.tsx";
|
|
28
|
+
import { GLYPH } from "./row.ts";
|
|
29
|
+
|
|
30
|
+
const END = "flex shrink-0 text-ink-mark";
|
|
31
|
+
// The trigger is a place row: its leading region holds the glyph the caller
|
|
32
|
+
// gives (the app's lockup), else the current option's icon at the row glyph's
|
|
33
|
+
// size, else its avatar.
|
|
34
|
+
const TRIGGER = "flex items-center w-full focus-visible:-outline-offset-2";
|
|
35
|
+
const NAME = "truncate grow text-left";
|
|
36
|
+
|
|
37
|
+
/** What the app is looking at and can switch to: an `OptionPick` whose `options` and `value` may be selections. A selection that waits paints the avatar and the name and keeps the chevron, the trigger inert; a read that ended, or a value no option matches, draws no name, and options that landed empty (none to switch to yet) draw the `placeholder` in its ink. */
|
|
38
|
+
export interface Switcher
|
|
39
|
+
extends Omit<OptionPick, "options" | "value" | "act"> {
|
|
40
|
+
options: Datum<readonly Option[] | readonly OptionGroup[]>;
|
|
41
|
+
value?: Datum<string>;
|
|
42
|
+
/** The act that makes a new option, ending the list under a hairline: an act that runs, a sheet it opens, or a link to where it is made. */
|
|
43
|
+
act?: IconAct | IconLinkAct;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function flatten(
|
|
47
|
+
options: readonly Option[] | readonly OptionGroup[],
|
|
48
|
+
): readonly Option[] {
|
|
49
|
+
const entries: readonly (Option | OptionGroup)[] = options;
|
|
50
|
+
return entries.flatMap((entry) =>
|
|
51
|
+
"options" in entry ? entry.options : [entry],
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The switcher is a pick (its options with their avatars, the current one
|
|
56
|
+
// ticked, the act that makes a new one under a hairline), drawn as a place
|
|
57
|
+
// row in the Shell's sidebar and on its touch layer. Outside the package's
|
|
58
|
+
// exports.
|
|
59
|
+
export function SwitcherPick(props: {
|
|
60
|
+
switcher: Switcher;
|
|
61
|
+
glyph?: ReactNode;
|
|
62
|
+
// Drawn on the rail: its glyph keeps the control square, its name and
|
|
63
|
+
// chevron uncovered with the rail's labels, and a pointer coming onto it (`wait`)
|
|
64
|
+
// or a focus opens the rail.
|
|
65
|
+
onExpand?: (wait: boolean) => void;
|
|
66
|
+
}) {
|
|
67
|
+
const { switcher, glyph, onExpand } = props;
|
|
68
|
+
const rail = onExpand !== undefined;
|
|
69
|
+
const [options, value] = useSelections([
|
|
70
|
+
switcher.options,
|
|
71
|
+
switcher.value,
|
|
72
|
+
] as const);
|
|
73
|
+
// Pending: a read still to land. Absent: it ended, or no option matches the
|
|
74
|
+
// value; the name region then draws nothing, never the switcher's own label.
|
|
75
|
+
// Empty: the options landed and there are none, so the placeholder stands.
|
|
76
|
+
const pending = paints(options) || paints(value);
|
|
77
|
+
const listed = options.painted ? undefined : flatten(options.value);
|
|
78
|
+
const current = value.painted
|
|
79
|
+
? undefined
|
|
80
|
+
: listed?.find((option) => option.value === value.value);
|
|
81
|
+
const name = current?.label;
|
|
82
|
+
const hint = listed?.length === 0 ? switcher.placeholder : undefined;
|
|
83
|
+
const lead = optionLeading(current);
|
|
84
|
+
return (
|
|
85
|
+
<HeldPicker
|
|
86
|
+
label={switcher.label}
|
|
87
|
+
options={switcher.options}
|
|
88
|
+
value={switcher.value}
|
|
89
|
+
onChange={switcher.onChange}
|
|
90
|
+
act={switcher.act}
|
|
91
|
+
drawn={(handed, open) => (
|
|
92
|
+
<button
|
|
93
|
+
{...handed}
|
|
94
|
+
onPointerEnter={(event) => {
|
|
95
|
+
handed.onPointerEnter?.(event);
|
|
96
|
+
if (event.pointerType !== "touch") onExpand?.(true);
|
|
97
|
+
}}
|
|
98
|
+
onFocus={(event) => {
|
|
99
|
+
handed.onFocus?.(event);
|
|
100
|
+
onExpand?.(false);
|
|
101
|
+
}}
|
|
102
|
+
type="button"
|
|
103
|
+
inert={pending || undefined}
|
|
104
|
+
aria-label={name ? `${switcher.label}, ${name}` : switcher.label}
|
|
105
|
+
className={cn(
|
|
106
|
+
placeRow({ state: open ? "active" : "rest" }),
|
|
107
|
+
TRIGGER,
|
|
108
|
+
rail && SHELL_RAIL_ENTRY,
|
|
109
|
+
!open && !pending && PRESS_WASH,
|
|
110
|
+
)}
|
|
111
|
+
>
|
|
112
|
+
<span
|
|
113
|
+
aria-hidden
|
|
114
|
+
className={cn(placeRowGlyph(), GLYPH, rail && SHELL_RAIL_GLYPH)}
|
|
115
|
+
>
|
|
116
|
+
{glyph ??
|
|
117
|
+
(pending ? (
|
|
118
|
+
<AvatarBase name="" painted />
|
|
119
|
+
) : lead.icon ? (
|
|
120
|
+
<Icon name={lead.icon} />
|
|
121
|
+
) : name ? (
|
|
122
|
+
<Avatar name={name} src={lead.avatar?.src} />
|
|
123
|
+
) : null)}
|
|
124
|
+
</span>
|
|
125
|
+
<span
|
|
126
|
+
className={cn(
|
|
127
|
+
text({ role: "body" }),
|
|
128
|
+
hint === undefined
|
|
129
|
+
? textStrong({ role: "body" })
|
|
130
|
+
: FIELD_PLACEHOLDER,
|
|
131
|
+
NAME,
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
{pending ? <Painted role="name" /> : (name ?? hint)}
|
|
135
|
+
</span>
|
|
136
|
+
<span className={END}>
|
|
137
|
+
<Icon name="ChevronsUpDown" />
|
|
138
|
+
</span>
|
|
139
|
+
</button>
|
|
140
|
+
)}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
}
|