@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,203 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { StatSpec } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
5
|
+
import { useRow, useSelections } from "@slotform/ui-core/react/read";
|
|
6
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
7
|
+
import {
|
|
8
|
+
type Datum,
|
|
9
|
+
endedSentence,
|
|
10
|
+
isEnded,
|
|
11
|
+
paints,
|
|
12
|
+
shownText,
|
|
13
|
+
} from "@slotform/ui-core/read";
|
|
14
|
+
import {
|
|
15
|
+
lineBox,
|
|
16
|
+
PRESS_WASH,
|
|
17
|
+
STATS,
|
|
18
|
+
STATS_CELL,
|
|
19
|
+
STATS_EDGE,
|
|
20
|
+
STATS_FIGURE,
|
|
21
|
+
STATS_OPENS,
|
|
22
|
+
text,
|
|
23
|
+
} from "@slotform/ui-core/variants";
|
|
24
|
+
import { Icon } from "../../atoms/icon/index.tsx";
|
|
25
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
26
|
+
import { follow } from "../../lib/navigate.ts";
|
|
27
|
+
import { Painted } from "../../lib/paint.tsx";
|
|
28
|
+
import { FailedMark, RetryMark } from "../../lib/read.tsx";
|
|
29
|
+
import { Decoded } from "../../lib/region.tsx";
|
|
30
|
+
import { CountLinks } from "./count-links.tsx";
|
|
31
|
+
import { Meter } from "./meter.tsx";
|
|
32
|
+
import { FIGURE, FIGURE_DIGITS, LABEL } from "./parts.ts";
|
|
33
|
+
|
|
34
|
+
const CLIP = "shrink-0 overflow-hidden";
|
|
35
|
+
// Each cell draws its own top and start hairline; the card's edge is drawn over
|
|
36
|
+
// them, so the outer ones are the edge's own.
|
|
37
|
+
const CELLS = "flex flex-wrap";
|
|
38
|
+
const EDGE = "pointer-events-none";
|
|
39
|
+
// Two to a row below `tablet` of the page, one row from it. A cell never
|
|
40
|
+
// narrows below its label's longest word and its unit (`min-w-min`, over a
|
|
41
|
+
// label that holds its words with `wrap-normal`), so a strip too narrow for its
|
|
42
|
+
// cells to share a row wraps them to a further row, the last growing across it.
|
|
43
|
+
const CELL =
|
|
44
|
+
"relative flex flex-col min-w-min grow basis-1/2 page-tablet:basis-0";
|
|
45
|
+
// The label's line: the label, and where the cell opens its chevron at the end
|
|
46
|
+
// of the label's first line (the lane a row's status dot stands in).
|
|
47
|
+
const LABEL_LINE = "flex items-start gap-gap";
|
|
48
|
+
const GLYPH = "flex items-center h-[1lh]";
|
|
49
|
+
const HIT = "absolute inset-0 focus-visible:-outline-offset-2";
|
|
50
|
+
const UNIT = "shrink-0 whitespace-nowrap";
|
|
51
|
+
|
|
52
|
+
/** A cell: a `StatSpec` whose figure and line are each a constant or a selection. */
|
|
53
|
+
export type StatsItem = StatSpec extends infer S
|
|
54
|
+
? S extends StatSpec
|
|
55
|
+
? Omit<S, "value" | "bound" | "label" | "line"> & {
|
|
56
|
+
value: Datum<number>;
|
|
57
|
+
line?: Datum<string>;
|
|
58
|
+
} & (S extends { bound: number }
|
|
59
|
+
? { label: Datum<string>; bound: Datum<number> }
|
|
60
|
+
: { label: string; bound?: never })
|
|
61
|
+
: never
|
|
62
|
+
: never;
|
|
63
|
+
|
|
64
|
+
/** A strip of counts. */
|
|
65
|
+
export interface StatsProps extends Closed {
|
|
66
|
+
/** The cells, in order: each a label over its figure, or a share of its `bound` drawn as a meter (its label a selection too). A cell whose `value` or `bound` is a selection paints its figure, and is inert and no link, until its read lands; a `line` that is a selection paints in its place until its own read lands. */
|
|
67
|
+
items: readonly StatsItem[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A failed cell's figure line is the retry, as a failed meter's label is: the
|
|
71
|
+
// failure mark and the retry icon stand where the figure would, at the cell's
|
|
72
|
+
// start, on a line no shorter than a target.
|
|
73
|
+
const RETRY = "flex min-w-0 items-center text-start min-h-target";
|
|
74
|
+
|
|
75
|
+
// A cell without a bound: its label over its figure. The cell is the frame of
|
|
76
|
+
// the selection it draws, as a meter is: its read failed with no enclosing frame
|
|
77
|
+
// holding it, it draws the failed shape itself (the label stays, the figure region
|
|
78
|
+
// shows the failure mark and the retry icon, the line under reads "This didn't
|
|
79
|
+
// load."); a read an enclosing frame holds draws nothing of its own.
|
|
80
|
+
function Cell({
|
|
81
|
+
item,
|
|
82
|
+
at,
|
|
83
|
+
}: {
|
|
84
|
+
item: Extract<StatsItem, { bound?: never }>;
|
|
85
|
+
at: number;
|
|
86
|
+
}) {
|
|
87
|
+
const words = useWords();
|
|
88
|
+
const [figure, sentence] = useSelections([item.value, item.line]);
|
|
89
|
+
const { ended: held, busy, retry } = useRow([item.value, item.line]);
|
|
90
|
+
const painted = paints(figure);
|
|
91
|
+
const line = shownText(sentence);
|
|
92
|
+
const ended = figure.painted && isEnded(figure.phase);
|
|
93
|
+
const opens = item.href !== undefined && !figure.painted;
|
|
94
|
+
const unit = item.unit ? (
|
|
95
|
+
<span className={cn(text({ role: "meta" }), UNIT)}>{item.unit}</span>
|
|
96
|
+
) : null;
|
|
97
|
+
const digits = (
|
|
98
|
+
<span className={cn(text({ role: "figure" }), FIGURE_DIGITS)}>
|
|
99
|
+
{ended ? (
|
|
100
|
+
<span aria-hidden className="invisible">
|
|
101
|
+
{"0"}
|
|
102
|
+
</span>
|
|
103
|
+
) : (
|
|
104
|
+
<Decoded
|
|
105
|
+
role="figure"
|
|
106
|
+
at={at}
|
|
107
|
+
painted={painted}
|
|
108
|
+
text={figure.painted ? undefined : number.format(figure.value)}
|
|
109
|
+
of={figure.painted ? undefined : figure.value}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
</span>
|
|
113
|
+
);
|
|
114
|
+
return (
|
|
115
|
+
<li
|
|
116
|
+
inert={painted || undefined}
|
|
117
|
+
className={cn(STATS_CELL, CELL, opens && PRESS_WASH)}
|
|
118
|
+
>
|
|
119
|
+
{opens ? (
|
|
120
|
+
// biome-ignore lint/a11y/useAnchorContent: the hit covers the cell, named by its label
|
|
121
|
+
<a
|
|
122
|
+
href={item.href}
|
|
123
|
+
onClick={follow}
|
|
124
|
+
aria-label={item.label}
|
|
125
|
+
className={HIT}
|
|
126
|
+
/>
|
|
127
|
+
) : null}
|
|
128
|
+
<span className={LABEL_LINE}>
|
|
129
|
+
<span className={cn(text({ role: "meta" }), LABEL, "min-w-0 grow")}>
|
|
130
|
+
{item.label}
|
|
131
|
+
</span>
|
|
132
|
+
{opens ? (
|
|
133
|
+
<span
|
|
134
|
+
aria-hidden
|
|
135
|
+
className={cn(lineBox({ role: "meta" }), GLYPH, STATS_OPENS)}
|
|
136
|
+
>
|
|
137
|
+
<Icon name="ChevronRight" fit="meta" />
|
|
138
|
+
</span>
|
|
139
|
+
) : null}
|
|
140
|
+
</span>
|
|
141
|
+
{held ? (
|
|
142
|
+
<BaseButton
|
|
143
|
+
onClick={() => {
|
|
144
|
+
if (!busy) void retry();
|
|
145
|
+
}}
|
|
146
|
+
aria-label={`${words.retry} ${item.label}`}
|
|
147
|
+
className={cn(STATS_FIGURE, RETRY)}
|
|
148
|
+
>
|
|
149
|
+
<FailedMark />
|
|
150
|
+
{held === "failed" ? <RetryMark busy={busy} /> : null}
|
|
151
|
+
</BaseButton>
|
|
152
|
+
) : (
|
|
153
|
+
<p className={cn(STATS_FIGURE, FIGURE)}>
|
|
154
|
+
{digits}
|
|
155
|
+
{unit}
|
|
156
|
+
</p>
|
|
157
|
+
)}
|
|
158
|
+
{held ? (
|
|
159
|
+
<p className={text({ role: "meta" })}>{endedSentence(words, held)}</p>
|
|
160
|
+
) : (
|
|
161
|
+
<>
|
|
162
|
+
{line ? (
|
|
163
|
+
<p className={text({ role: "meta" })}>
|
|
164
|
+
{line.painted ? <Painted role="phrase" at={at} /> : line.text}
|
|
165
|
+
</p>
|
|
166
|
+
) : null}
|
|
167
|
+
{item.counts ? <CountLinks counts={item.counts} /> : null}
|
|
168
|
+
</>
|
|
169
|
+
)}
|
|
170
|
+
</li>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const number = formatterFor("number");
|
|
175
|
+
|
|
176
|
+
/** One hairline card of counts split by hairlines, each cell its label in meta over its figure in tabular figures (its unit muted beside it), then a `line` or sub-counts as links, or the whole cell a link to its list, a chevron at its label's end. Zeros are drawn. Two cells to a row below `tablet` of the page. Each cell is the frame of the selection it draws: held by no enclosing frame (a `Pane` given its `read`), a failed cell draws its own failed shape with a retry. */
|
|
177
|
+
export function Stats({ items }: StatsProps) {
|
|
178
|
+
return (
|
|
179
|
+
<div className={cn(STATS, CLIP)}>
|
|
180
|
+
<ul className={CELLS}>
|
|
181
|
+
{items.map((item, at) =>
|
|
182
|
+
item.bound !== undefined ? (
|
|
183
|
+
<li key={at} className={cn(STATS_CELL, CELL)}>
|
|
184
|
+
<Meter
|
|
185
|
+
label={item.label}
|
|
186
|
+
value={item.value}
|
|
187
|
+
max={item.bound}
|
|
188
|
+
mark={item.mark}
|
|
189
|
+
goal={item.goal}
|
|
190
|
+
line={item.line}
|
|
191
|
+
counts={item.counts}
|
|
192
|
+
at={at}
|
|
193
|
+
/>
|
|
194
|
+
</li>
|
|
195
|
+
) : (
|
|
196
|
+
<Cell key={at} item={item} at={at} />
|
|
197
|
+
),
|
|
198
|
+
)}
|
|
199
|
+
</ul>
|
|
200
|
+
<div aria-hidden className={cn(STATS_EDGE, EDGE)} />
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { CountLink, MeterMark } from "@slotform/ui-core/descriptors";
|
|
4
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
5
|
+
import { levelOf } from "@slotform/ui-core/list-state";
|
|
6
|
+
import { type PaintRole, paintText } from "@slotform/ui-core/paint";
|
|
7
|
+
import { useRow, useSelections } from "@slotform/ui-core/react/read";
|
|
8
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
9
|
+
import {
|
|
10
|
+
type Datum,
|
|
11
|
+
endedSentence,
|
|
12
|
+
isEnded,
|
|
13
|
+
shownText,
|
|
14
|
+
} from "@slotform/ui-core/read";
|
|
15
|
+
import {
|
|
16
|
+
METER,
|
|
17
|
+
METER_MARK,
|
|
18
|
+
METER_TRACK,
|
|
19
|
+
meterFill,
|
|
20
|
+
STATS_FIGURE,
|
|
21
|
+
TRAVEL_X,
|
|
22
|
+
text,
|
|
23
|
+
} from "@slotform/ui-core/variants";
|
|
24
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
25
|
+
import { PAINT_BOX, Painted } from "../../lib/paint.tsx";
|
|
26
|
+
import { FailedMark, RetryMark } from "../../lib/read.tsx";
|
|
27
|
+
import { Decoded } from "../../lib/region.tsx";
|
|
28
|
+
import type { VarStyle } from "../../lib/style.ts";
|
|
29
|
+
import { CountLinks } from "./count-links.tsx";
|
|
30
|
+
import { FIGURE, FIGURE_DIGITS, LABEL } from "./parts.ts";
|
|
31
|
+
|
|
32
|
+
const STACK = "flex flex-col min-w-0";
|
|
33
|
+
const ROOT = "relative";
|
|
34
|
+
// A failed meter's label is the retry: its after layer covers the meter, so
|
|
35
|
+
// pressing anywhere on it retries, and draws the ring inset at its edge.
|
|
36
|
+
const RETRY =
|
|
37
|
+
"text-left after:absolute after:inset-0 focus-visible:outline-none in-data-[modality=keyboard]:focus-visible:after:outline-2 focus-visible:after:-outline-offset-2 focus-visible:after:outline-ring";
|
|
38
|
+
// The failure marks stand on a line no shorter than a target, as a plain cell's.
|
|
39
|
+
const FAILED = "flex min-w-0 items-center min-h-target";
|
|
40
|
+
// The bar is a container so the tick travels in the track's own widths (`cqw`), by transform; its box is no wider than a point, so a mark at the end adds no scroll.
|
|
41
|
+
const BAR = "relative @container";
|
|
42
|
+
const TRACK = "overflow-hidden";
|
|
43
|
+
const TICK = "absolute";
|
|
44
|
+
const TRAVEL = "absolute inset-y-0 left-0 w-0";
|
|
45
|
+
|
|
46
|
+
interface MeterBase extends Closed {
|
|
47
|
+
/** What is measured (a short phrase; wraps). A selection paints, inert, until its read lands. */
|
|
48
|
+
label: Datum<string>;
|
|
49
|
+
/** How much is used; past `max` the meter is over. */
|
|
50
|
+
value: Datum<number>;
|
|
51
|
+
/** The limit. */
|
|
52
|
+
max: Datum<number>;
|
|
53
|
+
/** A tick across the track at the mark's value: the point the fill turns amber at, in place of the near share. */
|
|
54
|
+
mark?: MeterMark;
|
|
55
|
+
/** The max is a goal reached, not a limit stayed under: the fill is the meta ink short of it and the good tone once the value reaches it, never amber or `danger`. */
|
|
56
|
+
goal?: true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The line under the bar: words, the counts as links, or both. */
|
|
60
|
+
interface MeterLine {
|
|
61
|
+
/** A line under the bar: the value in words, when it resets (a sentence; wraps). A selection paints until its read lands. */
|
|
62
|
+
line?: Datum<string>;
|
|
63
|
+
/** The line under the bar as links: counts that lead to their lists. */
|
|
64
|
+
counts?: readonly CountLink[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type MeterProps = MeterBase & MeterLine;
|
|
68
|
+
|
|
69
|
+
// The region of a value an ended read left out: the loaded line's height and
|
|
70
|
+
// width held, nothing drawn, so the meter does not move.
|
|
71
|
+
function Blank({ role, at }: { role: PaintRole; at: number }) {
|
|
72
|
+
return (
|
|
73
|
+
<span aria-hidden className="invisible">
|
|
74
|
+
{paintText(role, at)}
|
|
75
|
+
</span>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The meter form of a bound stat, a cell like the plain one: the label in meta (it wraps at its words), the share in percent as its figure under it, the bar under them filling by the share in the meta ink, amber once near full (at its `mark` when it has one) and `danger` once over, or, for a `goal` (tests passing of all of them), the meta ink short of it and the good tone once reached, never amber or `danger`; the line under the bar: the `line`, or the counts as links. A `value` or `bound` that is a selection paints in its place, the meter inert, until its read lands; once its read ended the meter stands empty (no share, no fill) in the same box. The meter is the frame of the selections it draws: when one failed and no enclosing frame holds that read, the label stays, the failure mark and the retry icon stand in the figure's place, the line under the bar reads "This didn't load." and pressing the meter retries. Outside the package's exports. */
|
|
80
|
+
export function Meter({
|
|
81
|
+
label,
|
|
82
|
+
value,
|
|
83
|
+
max,
|
|
84
|
+
line,
|
|
85
|
+
counts,
|
|
86
|
+
mark,
|
|
87
|
+
goal,
|
|
88
|
+
at,
|
|
89
|
+
}: MeterProps & { at: number }) {
|
|
90
|
+
const words = useWords();
|
|
91
|
+
const [l, v, m, n] = useSelections([label, value, max, line]);
|
|
92
|
+
const { ended: held, busy, retry } = useRow([label, value, max, line]);
|
|
93
|
+
// A read that ended leaves the meter empty, unpainted: no share, no track
|
|
94
|
+
// fill, the label standing if its own read answered. Held by the meter, its
|
|
95
|
+
// failed shape stands in the same box.
|
|
96
|
+
const ended = [l, v, m].some((one) => one.painted && isEnded(one.phase));
|
|
97
|
+
const absent = l.painted || v.painted || m.painted;
|
|
98
|
+
const painted = absent && !ended;
|
|
99
|
+
// The drawn numbers and the label are read only once absence is ruled out
|
|
100
|
+
// (a placeholder is a function proxy), which `absent` holds apart from the
|
|
101
|
+
// three it tests, so the casts name what they then hold.
|
|
102
|
+
const used = absent ? 0 : (v.value as number);
|
|
103
|
+
const limit = absent ? 0 : (m.value as number);
|
|
104
|
+
const share = limit > 0 ? used / limit : 0;
|
|
105
|
+
const markShare = mark && limit > 0 ? mark.value / limit : undefined;
|
|
106
|
+
// The fill is the whole track scaled to the data's share; the tick's place
|
|
107
|
+
// is the data's, the mark's share of the track.
|
|
108
|
+
const fill: VarStyle = {
|
|
109
|
+
"--fill": Math.min(share, 1),
|
|
110
|
+
};
|
|
111
|
+
const tick: VarStyle | undefined =
|
|
112
|
+
markShare === undefined
|
|
113
|
+
? undefined
|
|
114
|
+
: { "--travel": `${Math.min(Math.max(markShare, 0), 1) * 100}cqw` };
|
|
115
|
+
const percent = formatterFor("number", undefined, {
|
|
116
|
+
style: "percent",
|
|
117
|
+
maximumFractionDigits: 0,
|
|
118
|
+
}).format(share);
|
|
119
|
+
// A painted meter is no meter: its numbers are not here to be read, and
|
|
120
|
+
// neither are an ended one's.
|
|
121
|
+
const reads = absent
|
|
122
|
+
? painted
|
|
123
|
+
? { "aria-hidden": true }
|
|
124
|
+
: {}
|
|
125
|
+
: {
|
|
126
|
+
role: "meter",
|
|
127
|
+
"aria-label": l.value as string,
|
|
128
|
+
"aria-valuemin": 0,
|
|
129
|
+
"aria-valuemax": limit,
|
|
130
|
+
"aria-valuenow": Math.min(used, limit),
|
|
131
|
+
};
|
|
132
|
+
const said = shownText(n);
|
|
133
|
+
const name = cn(text({ role: "meta" }), LABEL);
|
|
134
|
+
const named = painted ? (
|
|
135
|
+
<Painted role="name" at={at} />
|
|
136
|
+
) : l.painted ? (
|
|
137
|
+
<Blank role="name" at={at} />
|
|
138
|
+
) : (
|
|
139
|
+
l.value
|
|
140
|
+
);
|
|
141
|
+
// A failed meter's label is the retry; the rest are the label alone.
|
|
142
|
+
const title =
|
|
143
|
+
held === "failed" ? (
|
|
144
|
+
<BaseButton
|
|
145
|
+
onClick={() => {
|
|
146
|
+
if (!busy) void retry();
|
|
147
|
+
}}
|
|
148
|
+
aria-label={`${words.retry} ${l.painted ? "" : l.value}`.trim()}
|
|
149
|
+
className={cn(name, RETRY)}
|
|
150
|
+
>
|
|
151
|
+
{named}
|
|
152
|
+
</BaseButton>
|
|
153
|
+
) : (
|
|
154
|
+
<span className={name}>{named}</span>
|
|
155
|
+
);
|
|
156
|
+
return (
|
|
157
|
+
<div inert={painted || undefined} className={cn(METER, STACK, ROOT)}>
|
|
158
|
+
{/* The role's children are presentational: the counts stand outside it, as links. */}
|
|
159
|
+
<div {...reads} className={cn(METER, STACK)}>
|
|
160
|
+
{title}
|
|
161
|
+
<p className={cn(STATS_FIGURE, FIGURE)}>
|
|
162
|
+
{held ? (
|
|
163
|
+
<span className={FAILED}>
|
|
164
|
+
<FailedMark />
|
|
165
|
+
{held === "failed" ? <RetryMark busy={busy} /> : null}
|
|
166
|
+
</span>
|
|
167
|
+
) : (
|
|
168
|
+
<span className={cn(text({ role: "figure" }), FIGURE_DIGITS)}>
|
|
169
|
+
{absent && !painted ? (
|
|
170
|
+
<Blank role="figure" at={at} />
|
|
171
|
+
) : (
|
|
172
|
+
<Decoded
|
|
173
|
+
role="figure"
|
|
174
|
+
at={at}
|
|
175
|
+
painted={painted}
|
|
176
|
+
text={percent}
|
|
177
|
+
of={share}
|
|
178
|
+
/>
|
|
179
|
+
)}
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</p>
|
|
183
|
+
<div className={BAR}>
|
|
184
|
+
<div className={cn(METER_TRACK, TRACK, painted && PAINT_BOX)}>
|
|
185
|
+
{absent ? null : (
|
|
186
|
+
<div
|
|
187
|
+
className={meterFill({
|
|
188
|
+
level: levelOf(share, markShare, goal === true),
|
|
189
|
+
})}
|
|
190
|
+
style={fill}
|
|
191
|
+
/>
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
{markShare !== undefined ? (
|
|
195
|
+
<div className={cn(TRAVEL_X, TRAVEL)} style={tick}>
|
|
196
|
+
<div className={cn(METER_MARK, TICK)} />
|
|
197
|
+
</div>
|
|
198
|
+
) : null}
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
{held ? (
|
|
202
|
+
<p className={text({ role: "meta" })}>{endedSentence(words, held)}</p>
|
|
203
|
+
) : counts ? (
|
|
204
|
+
<CountLinks counts={counts} painted={painted} />
|
|
205
|
+
) : null}
|
|
206
|
+
{!held && said ? (
|
|
207
|
+
<p className={text({ role: "meta" })}>
|
|
208
|
+
{said.painted ? <Painted role="phrase" at={at} /> : said.text}
|
|
209
|
+
</p>
|
|
210
|
+
) : null}
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// A cell's label holds its words, so a strip too narrow wraps a label whole and
|
|
2
|
+
// never cuts it (held by the cell's `min-w-min`).
|
|
3
|
+
export const LABEL = "wrap-normal";
|
|
4
|
+
// The figure stands whole, as wide as its digits, so the cell's floor holds it
|
|
5
|
+
// with the label's longest word (`min-w-min`): a strip too narrow for its cells
|
|
6
|
+
// to share a row wraps them. The unit stands whole after the figure's last
|
|
7
|
+
// digit, and under it where the cell has not the room for both, never cutting
|
|
8
|
+
// the figure.
|
|
9
|
+
export const FIGURE = "flex flex-wrap items-baseline gap-y-0 min-w-0";
|
|
10
|
+
export const FIGURE_DIGITS = "shrink-0 max-w-full";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import { stepStateOf } from "@slotform/ui-core/list-state";
|
|
3
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
4
|
+
import { filled } from "@slotform/ui-core/tokens";
|
|
5
|
+
import {
|
|
6
|
+
STEP_COUNT,
|
|
7
|
+
STEP_COUNT_SEGMENTS,
|
|
8
|
+
stepCountSegment,
|
|
9
|
+
text,
|
|
10
|
+
} from "@slotform/ui-core/variants";
|
|
11
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
12
|
+
|
|
13
|
+
const STACK = "flex flex-col min-w-0";
|
|
14
|
+
const SEGMENTS = "flex";
|
|
15
|
+
const SEGMENT = "flex-1";
|
|
16
|
+
|
|
17
|
+
/** Where an onboarding flow stands in its steps. */
|
|
18
|
+
interface StepCountProps extends Closed {
|
|
19
|
+
/** The current step, counted from one. */
|
|
20
|
+
at: number;
|
|
21
|
+
/** How many steps the flow has, two to four. */
|
|
22
|
+
of: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** One segment per step at the meter's height, the steps up to the current one in the meta ink and the later ones a wash, over "Step n of m" at meta. */
|
|
26
|
+
export function StepCount({ at, of }: StepCountProps) {
|
|
27
|
+
const words = useWords();
|
|
28
|
+
const sentence = filled(words.stepOf, { at: String(at), of: String(of) });
|
|
29
|
+
return (
|
|
30
|
+
<div className={cn(STEP_COUNT, STACK)}>
|
|
31
|
+
<div className={cn(STEP_COUNT_SEGMENTS, SEGMENTS)}>
|
|
32
|
+
{Array.from({ length: of }, (_, index) => index + 1).map((step) => (
|
|
33
|
+
<div
|
|
34
|
+
key={step}
|
|
35
|
+
className={cn(
|
|
36
|
+
stepCountSegment({ state: stepStateOf(step, at) }),
|
|
37
|
+
SEGMENT,
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
))}
|
|
41
|
+
</div>
|
|
42
|
+
<span className={text({ role: "meta" })}>{sentence}</span>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Switch as Base } from "@base-ui/react/switch";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import type { Draft } from "@slotform/ui-core/react/acts";
|
|
4
|
+
import { switchThumb, switchTrack } from "@slotform/ui-core/variants";
|
|
5
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
6
|
+
import { PAINT_CONTROL } from "../../lib/paint.tsx";
|
|
7
|
+
import type { SwitchProps } from "./index.tsx";
|
|
8
|
+
|
|
9
|
+
// The switch element is the target-sized hit box, so a press anywhere in it
|
|
10
|
+
// toggles; the track inside draws the states and the focus ring.
|
|
11
|
+
const HIT =
|
|
12
|
+
"group/toggle inline-flex shrink-0 items-center justify-center min-h-target min-w-target outline-none";
|
|
13
|
+
const RING =
|
|
14
|
+
"in-data-[modality=keyboard]:group-focus-visible/toggle:outline-2 group-focus-visible/toggle:outline-offset-2 group-focus-visible/toggle:outline-ring";
|
|
15
|
+
const OFF =
|
|
16
|
+
"inline-flex shrink-0 items-center justify-start group-not-data-disabled/toggle:group-hover/toggle:bg-switch-off-hover group-not-data-disabled/toggle:group-active/toggle:bg-switch-off-hover group-data-disabled/toggle:bg-fill-disabled";
|
|
17
|
+
const ON =
|
|
18
|
+
"inline-flex shrink-0 items-center justify-start group-not-data-disabled/toggle:group-hover/toggle:bg-toggle-on-hover group-not-data-disabled/toggle:group-active/toggle:bg-toggle-on-hover group-data-disabled/toggle:bg-fill-disabled";
|
|
19
|
+
const THUMB = "data-disabled:bg-ink-disabled";
|
|
20
|
+
|
|
21
|
+
/** The track and thumb every Switch renders, on the `draft` its host holds: a field hosts the draft of its switch and draws a rejection in its own line. `painted` is the track while its data is not here: filled, the thumb not drawn, inert. `disabled` (a row's lock) takes the control out of use for everyone: the disabled attribute, the disabled fill and ink, no press. A read that ended leaves the track unfilled with no thumb, blocked: a press says why and changes nothing. Outside the package's exports. */
|
|
22
|
+
export function SwitchBase({
|
|
23
|
+
draft,
|
|
24
|
+
onChange,
|
|
25
|
+
label,
|
|
26
|
+
painted: given,
|
|
27
|
+
disabled,
|
|
28
|
+
}: Omit<SwitchProps, "checked"> & {
|
|
29
|
+
draft: Draft<boolean>;
|
|
30
|
+
painted?: boolean;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
}) {
|
|
33
|
+
const ended = draft.ended;
|
|
34
|
+
const painted = given || (draft.painted && !ended);
|
|
35
|
+
const absent = painted || ended;
|
|
36
|
+
const on = draft.value && !absent;
|
|
37
|
+
const state = on ? "on" : "off";
|
|
38
|
+
// A field disables the switch through Base UI's field context: docs/architecture/plugins/react-ui.md, "Field box and focus rings".
|
|
39
|
+
return (
|
|
40
|
+
<Base.Root
|
|
41
|
+
nativeButton
|
|
42
|
+
render={<button type="button" />}
|
|
43
|
+
checked={on}
|
|
44
|
+
onCheckedChange={(next) => {
|
|
45
|
+
draft.change(next, () => onChange(next));
|
|
46
|
+
}}
|
|
47
|
+
aria-label={label}
|
|
48
|
+
inert={painted || undefined}
|
|
49
|
+
disabled={disabled}
|
|
50
|
+
aria-disabled={ended || undefined}
|
|
51
|
+
className={HIT}
|
|
52
|
+
>
|
|
53
|
+
<span
|
|
54
|
+
className={cn(
|
|
55
|
+
switchTrack({ state }),
|
|
56
|
+
on ? ON : OFF,
|
|
57
|
+
RING,
|
|
58
|
+
painted && PAINT_CONTROL,
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
<Base.Thumb
|
|
62
|
+
className={cn(switchThumb({ state }), THUMB, absent && "invisible")}
|
|
63
|
+
/>
|
|
64
|
+
</span>
|
|
65
|
+
</Base.Root>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A Switch that holds its own draft, as a bare one and a row's toggle do; a rejection toasts. Outside the package's exports. */
|
|
70
|
+
export function HeldSwitch({
|
|
71
|
+
checked,
|
|
72
|
+
onChange,
|
|
73
|
+
label,
|
|
74
|
+
painted,
|
|
75
|
+
disabled,
|
|
76
|
+
}: SwitchProps & { painted?: boolean; disabled?: boolean }) {
|
|
77
|
+
return (
|
|
78
|
+
<SwitchBase
|
|
79
|
+
draft={useHeldDraft(checked)}
|
|
80
|
+
onChange={onChange}
|
|
81
|
+
label={label}
|
|
82
|
+
painted={painted}
|
|
83
|
+
disabled={disabled}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FieldOwned } from "@slotform/ui-core/react/field";
|
|
2
|
+
import type { Datum } from "@slotform/ui-core/read";
|
|
3
|
+
import { use } from "react";
|
|
4
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
5
|
+
import type { Fielded } from "../../lib/field.ts";
|
|
6
|
+
import { FieldBody } from "../form-field/index.tsx";
|
|
7
|
+
import { HeldSwitch } from "./base.tsx";
|
|
8
|
+
|
|
9
|
+
/** A setting that takes effect at once, on or off. */
|
|
10
|
+
export interface SwitchProps extends Closed, Fielded {
|
|
11
|
+
/** Whether it is on. A selection paints the track, inert, until its read lands and follows it until the viewer flips it. Once its read ended the control stands with no value and a change says why instead. */
|
|
12
|
+
checked: Datum<boolean>;
|
|
13
|
+
/** Hears the next value when the viewer flips it. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
14
|
+
onChange: (checked: boolean) => unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A track and its thumb, drawn inside a target-sized hit box. Placed alone it is its field: the label on its line with the switch at the line's end, the description or the error under it. */
|
|
18
|
+
export function Switch({
|
|
19
|
+
checked,
|
|
20
|
+
onChange,
|
|
21
|
+
label,
|
|
22
|
+
description,
|
|
23
|
+
optional,
|
|
24
|
+
error,
|
|
25
|
+
}: SwitchProps) {
|
|
26
|
+
if (use(FieldOwned))
|
|
27
|
+
return <HeldSwitch checked={checked} onChange={onChange} label={label} />;
|
|
28
|
+
return (
|
|
29
|
+
<FieldBody
|
|
30
|
+
alone
|
|
31
|
+
label={label}
|
|
32
|
+
description={description}
|
|
33
|
+
optional={optional}
|
|
34
|
+
error={error}
|
|
35
|
+
switch={{ checked, onChange }}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|