@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,207 @@
|
|
|
1
|
+
import { type Offered, offered } from "@slotform/ui-core/acts";
|
|
2
|
+
import { GLYPHS } from "@slotform/ui-core/banner";
|
|
3
|
+
import { timeLeft } from "@slotform/ui-core/clock";
|
|
4
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
5
|
+
import type { LinkAct, Run, Runs } from "@slotform/ui-core/descriptors";
|
|
6
|
+
import { usePending } from "@slotform/ui-core/react/clock";
|
|
7
|
+
import { useDrawsFailure, useSelections } from "@slotform/ui-core/react/read";
|
|
8
|
+
import { ReasonHostContext } from "@slotform/ui-core/react/reason";
|
|
9
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
10
|
+
import { type Datum, endedReason } from "@slotform/ui-core/read";
|
|
11
|
+
import { partRuns } from "@slotform/ui-core/runs";
|
|
12
|
+
import type { Tone } from "@slotform/ui-core/tokens";
|
|
13
|
+
import {
|
|
14
|
+
BANNER_MAIN,
|
|
15
|
+
BANNER_ROW,
|
|
16
|
+
BLOCK_IN,
|
|
17
|
+
banner,
|
|
18
|
+
bannerGlyph,
|
|
19
|
+
PENDING_LEFT,
|
|
20
|
+
text,
|
|
21
|
+
YIELDS_FIRST,
|
|
22
|
+
} from "@slotform/ui-core/variants";
|
|
23
|
+
import { useReasonLine } from "../../atoms/button/reason.tsx";
|
|
24
|
+
import { Icon, IconBase } from "../../atoms/icon/index.tsx";
|
|
25
|
+
import { Spinner } from "../../atoms/spinner/index.tsx";
|
|
26
|
+
import type { Act } from "../../lib/act.ts";
|
|
27
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
28
|
+
import { RunText } from "../../lib/code.tsx";
|
|
29
|
+
import { ButtonBase } from "../button/base.tsx";
|
|
30
|
+
import { ActFace } from "../button/face.tsx";
|
|
31
|
+
import { Fill } from "./pending.tsx";
|
|
32
|
+
|
|
33
|
+
const BOX = "flex flex-col justify-center";
|
|
34
|
+
// With a deadline the strip holds the fill along its foot, clipped to its radius.
|
|
35
|
+
const PENDING = "relative overflow-hidden";
|
|
36
|
+
// The line beside its end group (the time left and the act) at every density
|
|
37
|
+
// while the sentence keeps its floor (two thirds of the banner's width, a
|
|
38
|
+
// fraction, never a width: the glyph and its gap come off it, so the column
|
|
39
|
+
// stays a readable measure and an end that would squeeze it takes its own
|
|
40
|
+
// line), the end under it only when it does not fit there. A run with a
|
|
41
|
+
// deadline and an act stands its end on the sentence's first line, the line
|
|
42
|
+
// holding the act's height with the air a one-line sentence has above and below
|
|
43
|
+
// it, so a wrapped sentence keeps the glyph, the time and the act on one line;
|
|
44
|
+
// on touch that end stands under the sentence, as a `PendingBar` stands its act.
|
|
45
|
+
const MAIN = "relative flex flex-wrap items-center";
|
|
46
|
+
const MAIN_RUN = "items-start touch:flex-col touch:items-stretch";
|
|
47
|
+
const LINE = `items-start flex grow ${YIELDS_FIRST} basis-0 min-w-2/3`;
|
|
48
|
+
const LINE_RUN = "py-[calc((var(--spacing-control)-1lh)/2)] touch:py-0";
|
|
49
|
+
// The glyph in a box of the sentence's line height, so it stays on the
|
|
50
|
+
// first line of a wrapped sentence.
|
|
51
|
+
const GLYPH_BOX = "flex shrink-0 items-center h-lh";
|
|
52
|
+
const TIME = "shrink-0";
|
|
53
|
+
const SENTENCE = "min-w-0 grow";
|
|
54
|
+
// A banner with no deadline stands its act in the sentence's column, so an act
|
|
55
|
+
// that wraps starts at the sentence's own inset, never under the glyph. The
|
|
56
|
+
// column is a row of the sentence and the act where the act fits beside it; on
|
|
57
|
+
// touch it is a column, the act always under the sentence at the banner's gap
|
|
58
|
+
// and at the sentence's inset, so the strip is as tall as its words, the gap
|
|
59
|
+
// and the act's box.
|
|
60
|
+
const FLOW =
|
|
61
|
+
"flex flex-wrap items-center gap-x-gap grow min-w-0 touch:flex-col touch:items-start touch:gap-y-gap";
|
|
62
|
+
const FLOW_SENTENCE = `grow ${YIELDS_FIRST} basis-0 min-w-2/3 touch:grow-0 touch:shrink touch:basis-auto touch:min-w-0`;
|
|
63
|
+
// An act stands beside the sentence: the glyph's box is the act's height and
|
|
64
|
+
// the sentence keeps the air a one-line sentence has above and below it, as
|
|
65
|
+
// `LINE_RUN` does, so the glyph, the sentence's first line and the act share
|
|
66
|
+
// one centre; on touch the act stands under the line and the glyph keeps the
|
|
67
|
+
// line's height.
|
|
68
|
+
const FLOW_ACTED = "items-start";
|
|
69
|
+
const FLOW_SENTENCE_ACTED =
|
|
70
|
+
"py-[calc((var(--spacing-control)-1lh)/2)] touch:py-0";
|
|
71
|
+
const GLYPH_ACTED = "h-control touch:h-lh";
|
|
72
|
+
// The end gives way only once the sentence has (its shrink weight is 10^7
|
|
73
|
+
// against the end's 1), so a long label cuts and an ordinary one never narrows.
|
|
74
|
+
const END = "flex items-center gap-gap min-w-0 max-w-full";
|
|
75
|
+
const ACT_REGION = "flex min-w-0 max-w-full";
|
|
76
|
+
|
|
77
|
+
/** A sentence about the state of the page, the app or a Section, in the flow. */
|
|
78
|
+
export interface BannerProps extends Closed {
|
|
79
|
+
/** What it tells: news (`active`, the default), a caution (`attention`), or a failure (`failed`, announced at once). A selection paints the glyph, in the news tint, until its read lands. */
|
|
80
|
+
tone?: Datum<Tone | undefined>;
|
|
81
|
+
/** The text beside the glyph (a sentence; wraps): words, or runs, whose `{ code }` stands boxed in the mono and wraps whole inside its box (a refused path). A selection draws no banner while its read waits, and nor does one that answers `undefined`, so a banner that stands only with its data is always placed and the page moves once, by its height, when it arrives (the shift check reports that move). */
|
|
82
|
+
sentence: Datum<Run | Runs | undefined>;
|
|
83
|
+
/** The one act it offers, at the line's end (a `{ label, href }` is a link to a route, an anchor); a blocked act's reason draws on the banner's own line, under it. A selection paints the act's box until its read lands, and stands blocked with the failed sentence once that read failed or is missing. */
|
|
84
|
+
act?: Offered<Act | LinkAct | undefined>;
|
|
85
|
+
/** When the run the banner tells of ends (use with `tone="running"`): the banner draws the time left after the sentence, before the act as one end (on the sentence's first line, under the sentence on touch), and a line along its foot that fills toward it at a constant pace, and the clock stops at 0:00. Its `act` stands as the cancel. A moved `until` carries the fill on from where it stood. */
|
|
86
|
+
until?: Date;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A block in the flow: it fades in on `base` as it mounts. With `until` it is a run in progress: a line fills along its foot toward the deadline and the time left stands after the sentence, beside the act as one end group on the sentence's first line, the two under the sentence on touch as a `PendingBar` stands them. A tinted strip at its content's height, its tone and act painted in their place when they are selections, and the banner inert, until their reads land (a sentence still to land draws no banner): the tone's glyph in the tone's ink beside the sentence in the body ink, and the act, an outlined Button at the bar fit, beside the sentence (its height holds the sentence's line, so the glyph, the sentence and the act share one centre) where the sentence keeps two thirds of the banner's width and under it where it would not. */
|
|
90
|
+
export function Banner({ tone, sentence, act, until }: BannerProps) {
|
|
91
|
+
const lifted = offered<Act | LinkAct | undefined>(act);
|
|
92
|
+
const [picked, said, offer] = useSelections([tone, sentence, lifted]);
|
|
93
|
+
useDrawsFailure([lifted]);
|
|
94
|
+
const drawn = (picked.painted ? undefined : picked.value) ?? "active";
|
|
95
|
+
const { end, attempt, now } = usePending(until);
|
|
96
|
+
const words = useWords();
|
|
97
|
+
// An act whose own read ended stands blocked with its sentence, never a
|
|
98
|
+
// false yes; one still to land paints the banner inert.
|
|
99
|
+
const ended = offer.painted ? endedReason(words, offer.phase) : undefined;
|
|
100
|
+
const waits = picked.painted || (offer.painted && ended === undefined);
|
|
101
|
+
const given = offer.painted ? undefined : offer.value;
|
|
102
|
+
const blocked =
|
|
103
|
+
ended ?? (given && "blocked" in given ? given.blocked : undefined);
|
|
104
|
+
const reason = useReasonLine(blocked, "desktop");
|
|
105
|
+
// A run with a deadline and an act: its end stands on the sentence's first
|
|
106
|
+
// line, under the sentence on touch.
|
|
107
|
+
const running = end !== undefined && (offer.painted || given !== undefined);
|
|
108
|
+
// Whether there is anything to say is not known until the sentence's read
|
|
109
|
+
// lands, so nothing stands while it waits (or ended): a banner painted then
|
|
110
|
+
// and gone loaded would be a block that stood for nothing. The page moves
|
|
111
|
+
// once, by its height, when the banner arrives with its data, which the
|
|
112
|
+
// shift check reports.
|
|
113
|
+
if (said.painted || said.value === undefined) return null;
|
|
114
|
+
const beside = !running && end === undefined && (offer.painted || given);
|
|
115
|
+
const line = (
|
|
116
|
+
<p
|
|
117
|
+
className={cn(
|
|
118
|
+
text({ role: "body" }),
|
|
119
|
+
running ? SENTENCE : FLOW_SENTENCE,
|
|
120
|
+
beside && FLOW_SENTENCE_ACTED,
|
|
121
|
+
)}
|
|
122
|
+
>
|
|
123
|
+
{typeof said.value === "string" ? (
|
|
124
|
+
said.value
|
|
125
|
+
) : (
|
|
126
|
+
<RunText runs={partRuns(said.value)} whole />
|
|
127
|
+
)}
|
|
128
|
+
</p>
|
|
129
|
+
);
|
|
130
|
+
const ending =
|
|
131
|
+
end === undefined && !offer.painted && !given ? null : (
|
|
132
|
+
<div className={END}>
|
|
133
|
+
{end === undefined ? null : (
|
|
134
|
+
// Out of the live region: a tick a second would be announced.
|
|
135
|
+
<span aria-hidden className={cn(TIME, PENDING_LEFT)}>
|
|
136
|
+
{timeLeft(end, now)}
|
|
137
|
+
</span>
|
|
138
|
+
)}
|
|
139
|
+
{offer.painted ? (
|
|
140
|
+
<span className={ACT_REGION}>
|
|
141
|
+
{ended === undefined ? (
|
|
142
|
+
<ButtonBase act="secondary" label="" painted />
|
|
143
|
+
) : (
|
|
144
|
+
<ReasonHostContext value={reason.host}>
|
|
145
|
+
<ButtonBase act="secondary" label={ended} blocked={ended} />
|
|
146
|
+
</ReasonHostContext>
|
|
147
|
+
)}
|
|
148
|
+
</span>
|
|
149
|
+
) : given ? (
|
|
150
|
+
<span className={ACT_REGION}>
|
|
151
|
+
<ReasonHostContext value={reason.host}>
|
|
152
|
+
<ActFace act={given} kind="secondary" blocked={blocked} />
|
|
153
|
+
</ReasonHostContext>
|
|
154
|
+
</span>
|
|
155
|
+
) : null}
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
return (
|
|
159
|
+
<div
|
|
160
|
+
role={drawn === "failed" ? "alert" : "status"}
|
|
161
|
+
inert={waits || undefined}
|
|
162
|
+
className={cn(
|
|
163
|
+
banner({ tone: drawn }),
|
|
164
|
+
BOX,
|
|
165
|
+
BLOCK_IN,
|
|
166
|
+
end !== undefined && PENDING,
|
|
167
|
+
)}
|
|
168
|
+
>
|
|
169
|
+
{attempt === undefined ? null : (
|
|
170
|
+
<Fill
|
|
171
|
+
key={`${attempt.start}-${attempt.end}`}
|
|
172
|
+
attempt={attempt}
|
|
173
|
+
now={now}
|
|
174
|
+
/>
|
|
175
|
+
)}
|
|
176
|
+
<div className={cn(BANNER_MAIN, MAIN, running && MAIN_RUN)}>
|
|
177
|
+
<div className={cn(BANNER_ROW, LINE, running && LINE_RUN)}>
|
|
178
|
+
<span
|
|
179
|
+
className={cn(
|
|
180
|
+
GLYPH_BOX,
|
|
181
|
+
bannerGlyph({ tone: drawn }),
|
|
182
|
+
beside && GLYPH_ACTED,
|
|
183
|
+
)}
|
|
184
|
+
>
|
|
185
|
+
{picked.painted ? (
|
|
186
|
+
<IconBase name="Info" stroke="line" painted />
|
|
187
|
+
) : drawn === "running" ? (
|
|
188
|
+
// A run in progress turns where a status turns.
|
|
189
|
+
<Spinner />
|
|
190
|
+
) : (
|
|
191
|
+
<Icon name={GLYPHS[drawn]} />
|
|
192
|
+
)}
|
|
193
|
+
</span>
|
|
194
|
+
{running ? (
|
|
195
|
+
line
|
|
196
|
+
) : (
|
|
197
|
+
<div className={cn(FLOW, beside && FLOW_ACTED)}>
|
|
198
|
+
{line} {ending}
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</div>
|
|
202
|
+
{running ? ending : null}
|
|
203
|
+
</div>
|
|
204
|
+
{reason.line}
|
|
205
|
+
</div>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type PendingAttempt,
|
|
3
|
+
pendingShare,
|
|
4
|
+
timeLeft,
|
|
5
|
+
} from "@slotform/ui-core/clock";
|
|
6
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
7
|
+
import type { LinkAct } from "@slotform/ui-core/descriptors";
|
|
8
|
+
import { usePending } from "@slotform/ui-core/react/clock";
|
|
9
|
+
import { ReasonHostContext } from "@slotform/ui-core/react/reason";
|
|
10
|
+
import {
|
|
11
|
+
PENDING_BAR,
|
|
12
|
+
PENDING_FILL,
|
|
13
|
+
PENDING_LEFT,
|
|
14
|
+
PENDING_ROW,
|
|
15
|
+
PENDING_TRACK,
|
|
16
|
+
text,
|
|
17
|
+
YIELDS_FIRST,
|
|
18
|
+
} from "@slotform/ui-core/variants";
|
|
19
|
+
import { useState } from "react";
|
|
20
|
+
import { useReasonLine } from "../../atoms/button/reason.tsx";
|
|
21
|
+
import { Spinner } from "../../atoms/spinner/index.tsx";
|
|
22
|
+
import type { Act } from "../../lib/act.ts";
|
|
23
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
24
|
+
import { useReducedMotion } from "../../lib/media.ts";
|
|
25
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
26
|
+
import { ActFace } from "../button/face.tsx";
|
|
27
|
+
|
|
28
|
+
// The bar over a blocked act's reason, at the end on the desktop; on touch
|
|
29
|
+
// the track stacks over the act as an ActionBar's acts do.
|
|
30
|
+
const BAR = "flex flex-col items-end touch:items-stretch";
|
|
31
|
+
const ROW = "flex items-center self-stretch touch:flex-col touch:items-stretch";
|
|
32
|
+
const TRACK = `relative flex items-center grow ${YIELDS_FIRST} min-w-0 overflow-hidden`;
|
|
33
|
+
// The elapsed share: the track's full width, scaled from its start to the
|
|
34
|
+
// runtime fraction, so the fill moves on the compositor and never lays out.
|
|
35
|
+
const FILL = "absolute bottom-0 inset-x-0 motion-safe:animate-pending-fill";
|
|
36
|
+
// The track's parts stand over the fill.
|
|
37
|
+
const SPINNER_REGION = "relative flex shrink-0 text-ink-meta";
|
|
38
|
+
// The sentence wraps in a narrow column, never clips: the track grows by a
|
|
39
|
+
// line. It stands in the control's height with the air a one-line sentence has
|
|
40
|
+
// above and below it, so one line is the control's height and a wrapped one
|
|
41
|
+
// keeps the same air.
|
|
42
|
+
const SENTENCE =
|
|
43
|
+
"relative min-w-0 grow py-[calc((var(--spacing-control)-1lh)/2)]";
|
|
44
|
+
const LEFT = "relative shrink-0";
|
|
45
|
+
|
|
46
|
+
// The elapsed share, moving on its own from where the attempt stands to full at
|
|
47
|
+
// its end (`pending-fill`, `globals.css`); the clock's tick redraws only the
|
|
48
|
+
// time left. The Fill mounts per attempt and takes its start once, so a tick never
|
|
49
|
+
// retimes it. Under reduced motion it steps with the clock instead, the share
|
|
50
|
+
// set once a tick.
|
|
51
|
+
export function Fill(props: { attempt: PendingAttempt; now: number }) {
|
|
52
|
+
const { attempt } = props;
|
|
53
|
+
const [at] = useState(Date.now);
|
|
54
|
+
const reduced = useReducedMotion();
|
|
55
|
+
const fill: VarStyle = {
|
|
56
|
+
"--fill": reduced ? pendingShare(attempt, props.now) : 1,
|
|
57
|
+
"--from": pendingShare(attempt, at),
|
|
58
|
+
"--ms": Math.max(0, attempt.end - at),
|
|
59
|
+
};
|
|
60
|
+
return <span aria-hidden className={cn(PENDING_FILL, FILL)} style={fill} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Work the page waits on, in an ActionBar's place: the `pending` an `ActionBar` takes, at the bar's own height. Outside the package's exports; a place that held no bar draws a `Banner` with `until`. */
|
|
64
|
+
export interface PendingBarProps extends Closed {
|
|
65
|
+
/** What is happening, announced as it changes (a short phrase; wraps in a narrow column). */
|
|
66
|
+
sentence: string;
|
|
67
|
+
/** When the work ends: the track fills toward it and shows the time left; unset, a spinner turns. */
|
|
68
|
+
until?: Date;
|
|
69
|
+
/** The one act, a hairline Button beside the track (a `{ label, href }` is a link to a route, an anchor); a blocked act's reason draws under the bar. */
|
|
70
|
+
act?: Act | LinkAct;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One line on the group ground: the spinner, or a meta-ink line along the track's foot filling toward `until` with the time left beside the sentence, which alone is the live region; the act beside it on the desktop, under it on touch. */
|
|
74
|
+
export function PendingBar({ sentence, until, act }: PendingBarProps) {
|
|
75
|
+
const { end, attempt, now } = usePending(until);
|
|
76
|
+
const blocked = act && "blocked" in act ? act.blocked : undefined;
|
|
77
|
+
const { host, line } = useReasonLine(blocked);
|
|
78
|
+
return (
|
|
79
|
+
<div className={cn(PENDING_BAR, BAR)}>
|
|
80
|
+
<div className={cn(PENDING_ROW, ROW)}>
|
|
81
|
+
<div className={cn(PENDING_TRACK, TRACK)}>
|
|
82
|
+
{end === undefined || attempt === undefined ? (
|
|
83
|
+
<span className={SPINNER_REGION}>
|
|
84
|
+
<Spinner />
|
|
85
|
+
</span>
|
|
86
|
+
) : (
|
|
87
|
+
<Fill
|
|
88
|
+
key={`${attempt.start}-${attempt.end}`}
|
|
89
|
+
attempt={attempt}
|
|
90
|
+
now={now}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
<span role="status" className={cn(text({ role: "body" }), SENTENCE)}>
|
|
94
|
+
{sentence}
|
|
95
|
+
</span>
|
|
96
|
+
{end === undefined ? null : (
|
|
97
|
+
<span className={cn(PENDING_LEFT, LEFT)}>{timeLeft(end, now)}</span>
|
|
98
|
+
)}
|
|
99
|
+
</div>
|
|
100
|
+
{act ? (
|
|
101
|
+
<ReasonHostContext value={host}>
|
|
102
|
+
<ActFace act={act} kind="secondary" blocked={blocked} />
|
|
103
|
+
</ReasonHostContext>
|
|
104
|
+
) : null}
|
|
105
|
+
</div>
|
|
106
|
+
{line}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|