@slotform/react-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/density.d.ts +4 -0
- package/dist/density.d.ts.map +1 -0
- package/dist/density.js +8 -0
- package/dist/density.js.map +1 -0
- package/dist/index.d.ts +400 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/node/canvas.d.ts +3 -0
- package/dist/node/canvas.d.ts.map +1 -0
- package/dist/node/canvas.js +13 -0
- package/dist/node/canvas.js.map +1 -0
- package/dist/node/codegen.d.ts +6 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +70 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/css-escape.d.ts +8 -0
- package/dist/node/css-escape.d.ts.map +1 -0
- package/dist/node/css-escape.js +12 -0
- package/dist/node/css-escape.js.map +1 -0
- package/dist/node/fonts.d.ts +6 -0
- package/dist/node/fonts.d.ts.map +1 -0
- package/dist/node/fonts.js +219 -0
- package/dist/node/fonts.js.map +1 -0
- package/dist/node/lint.d.ts +3 -0
- package/dist/node/lint.d.ts.map +1 -0
- package/dist/node/lint.js +23 -0
- package/dist/node/lint.js.map +1 -0
- package/dist/node/mode.d.ts +9 -0
- package/dist/node/mode.d.ts.map +1 -0
- package/dist/node/mode.js +38 -0
- package/dist/node/mode.js.map +1 -0
- package/dist/node/theme.d.ts +13 -0
- package/dist/node/theme.d.ts.map +1 -0
- package/dist/node/theme.js +160 -0
- package/dist/node/theme.js.map +1 -0
- package/dist/types.d.ts +250 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +80 -0
- package/dist/types.js.map +1 -0
- package/guide/acts.md +61 -0
- package/guide/audio.md +77 -0
- package/guide/blocks.md +82 -0
- package/guide/canvas-choosing.md +34 -0
- package/guide/canvas-editing.md +36 -0
- package/guide/canvas-layout.md +46 -0
- package/guide/canvas-opening.md +47 -0
- package/guide/canvas-overview.md +24 -0
- package/guide/canvas-states.md +37 -0
- package/guide/canvas-view.md +46 -0
- package/guide/canvas.md +94 -0
- package/guide/containers.md +60 -0
- package/guide/content.md +40 -0
- package/guide/controls.md +89 -0
- package/guide/density.md +48 -0
- package/guide/dock.md +42 -0
- package/guide/drag.md +38 -0
- package/guide/figures.md +25 -0
- package/guide/forms.md +82 -0
- package/guide/pane-bar.md +11 -0
- package/guide/pane.md +50 -0
- package/guide/reference.md +74 -0
- package/guide/rules.md +109 -0
- package/guide/section.md +29 -0
- package/guide/shell.md +26 -0
- package/guide/shots.md +37 -0
- package/guide/sidebar.md +30 -0
- package/guide/table.md +119 -0
- package/lint/no-arbitrary-value.grit +9 -0
- package/lint/no-class-on-component.grit +12 -0
- package/lint/no-density.grit +8 -0
- package/lint/no-host-look.grit +38 -0
- package/lint/no-img.grit +10 -0
- package/lint/no-navigate-act.grit +22 -0
- package/lint/no-raw-style.grit +8 -0
- package/package.json +150 -3
- package/src/density.ts +9 -0
- package/src/index.ts +503 -0
- package/src/node/canvas.ts +14 -0
- package/src/node/codegen.ts +100 -0
- package/src/node/css-escape.ts +27 -0
- package/src/node/fonts.ts +260 -0
- package/src/node/lint.ts +25 -0
- package/src/node/mode.ts +64 -0
- package/src/node/theme.ts +232 -0
- package/src/types.ts +120 -0
- package/src/ui/atoms/avatar/base.tsx +42 -0
- package/src/ui/atoms/button/glyph.tsx +244 -0
- package/src/ui/atoms/button/link.tsx +81 -0
- package/src/ui/atoms/button/look.ts +32 -0
- package/src/ui/atoms/button/reason.tsx +69 -0
- package/src/ui/atoms/chip/base.tsx +85 -0
- package/src/ui/atoms/count/base.tsx +27 -0
- package/src/ui/atoms/icon/index.tsx +51 -0
- package/src/ui/atoms/message/waiting.tsx +19 -0
- package/src/ui/atoms/prose/painted.tsx +35 -0
- package/src/ui/atoms/row/badges.tsx +226 -0
- package/src/ui/atoms/row/leading.tsx +166 -0
- package/src/ui/atoms/row/lock.tsx +17 -0
- package/src/ui/atoms/row/marks.tsx +79 -0
- package/src/ui/atoms/section/card.tsx +27 -0
- package/src/ui/atoms/spinner/index.tsx +42 -0
- package/src/ui/atoms/status/base.tsx +51 -0
- package/src/ui/atoms/status/change.tsx +29 -0
- package/src/ui/atoms/status/dot.tsx +45 -0
- package/src/ui/atoms/switch/checkbox.tsx +121 -0
- package/src/ui/atoms/turn.tsx +28 -0
- package/src/ui/components/action-bar/base.tsx +276 -0
- package/src/ui/components/action-bar/index.tsx +20 -0
- package/src/ui/components/avatar/index.tsx +21 -0
- package/src/ui/components/banner/index.tsx +207 -0
- package/src/ui/components/banner/pending.tsx +109 -0
- package/src/ui/components/bar-chart/index.tsx +701 -0
- package/src/ui/components/button/base.tsx +214 -0
- package/src/ui/components/button/face.tsx +84 -0
- package/src/ui/components/button/index.tsx +206 -0
- package/src/ui/components/canvas/connection.tsx +26 -0
- package/src/ui/components/canvas/edges.tsx +116 -0
- package/src/ui/components/canvas/elk.ts +260 -0
- package/src/ui/components/canvas/floor.ts +173 -0
- package/src/ui/components/canvas/geometry.ts +772 -0
- package/src/ui/components/canvas/ground.tsx +97 -0
- package/src/ui/components/canvas/group.tsx +156 -0
- package/src/ui/components/canvas/hit.ts +40 -0
- package/src/ui/components/canvas/index.tsx +497 -0
- package/src/ui/components/canvas/label.tsx +53 -0
- package/src/ui/components/canvas/layout.ts +543 -0
- package/src/ui/components/canvas/lift.ts +272 -0
- package/src/ui/components/canvas/look.ts +129 -0
- package/src/ui/components/canvas/node.tsx +689 -0
- package/src/ui/components/canvas/open.ts +243 -0
- package/src/ui/components/canvas/opening.ts +240 -0
- package/src/ui/components/canvas/view.ts +621 -0
- package/src/ui/components/canvas/viewport.ts +417 -0
- package/src/ui/components/canvas/zoom.tsx +113 -0
- package/src/ui/components/card/index.tsx +20 -0
- package/src/ui/components/chip/index.tsx +24 -0
- package/src/ui/components/code/frame.ts +2 -0
- package/src/ui/components/code/index.tsx +234 -0
- package/src/ui/components/columns/index.tsx +51 -0
- package/src/ui/components/count/index.tsx +17 -0
- package/src/ui/components/diff/index.tsx +249 -0
- package/src/ui/components/diff/word.tsx +104 -0
- package/src/ui/components/dock/index.tsx +262 -0
- package/src/ui/components/file-row/index.tsx +213 -0
- package/src/ui/components/form/base.tsx +280 -0
- package/src/ui/components/form/derive.tsx +269 -0
- package/src/ui/components/form/index.tsx +49 -0
- package/src/ui/components/form/saved.tsx +39 -0
- package/src/ui/components/form-field/index.tsx +658 -0
- package/src/ui/components/gallery/index.tsx +83 -0
- package/src/ui/components/gate/index.tsx +183 -0
- package/src/ui/components/image/base.tsx +245 -0
- package/src/ui/components/image/index.tsx +58 -0
- package/src/ui/components/input/base.tsx +246 -0
- package/src/ui/components/input/code.tsx +108 -0
- package/src/ui/components/input/drop.ts +37 -0
- package/src/ui/components/input/file.tsx +154 -0
- package/src/ui/components/input/index.tsx +132 -0
- package/src/ui/components/input/prose.tsx +107 -0
- package/src/ui/components/input/refusal.tsx +30 -0
- package/src/ui/components/item-header/base.tsx +410 -0
- package/src/ui/components/menu/base.tsx +319 -0
- package/src/ui/components/message/attachments.tsx +101 -0
- package/src/ui/components/message/base.tsx +266 -0
- package/src/ui/components/message-input/index.tsx +377 -0
- package/src/ui/components/missing/base.tsx +45 -0
- package/src/ui/components/pane/head.tsx +399 -0
- package/src/ui/components/pane/index.tsx +325 -0
- package/src/ui/components/picker/base.tsx +1551 -0
- package/src/ui/components/picker/index.tsx +224 -0
- package/src/ui/components/picker/list.tsx +423 -0
- package/src/ui/components/picker/segments.tsx +183 -0
- package/src/ui/components/prose/index.tsx +259 -0
- package/src/ui/components/qr-code/index.tsx +65 -0
- package/src/ui/components/row/acts.tsx +126 -0
- package/src/ui/components/row/fact.tsx +54 -0
- package/src/ui/components/row/index.tsx +1370 -0
- package/src/ui/components/row/progress.tsx +38 -0
- package/src/ui/components/row/status.tsx +54 -0
- package/src/ui/components/row/title.ts +7 -0
- package/src/ui/components/rules/index.tsx +290 -0
- package/src/ui/components/section/band.tsx +39 -0
- package/src/ui/components/section/head.tsx +267 -0
- package/src/ui/components/section/index.tsx +409 -0
- package/src/ui/components/section/rows.tsx +356 -0
- package/src/ui/components/sheet/base.tsx +272 -0
- package/src/ui/components/sheet/confirm.tsx +79 -0
- package/src/ui/components/sheet/docked.tsx +218 -0
- package/src/ui/components/sheet/form.tsx +76 -0
- package/src/ui/components/sheet/head.tsx +120 -0
- package/src/ui/components/sheet/index.tsx +45 -0
- package/src/ui/components/sheet/layer.tsx +168 -0
- package/src/ui/components/sheet/outlet.tsx +58 -0
- package/src/ui/components/sheet/task.tsx +41 -0
- package/src/ui/components/shell/cut.tsx +116 -0
- package/src/ui/components/shell/drag.tsx +45 -0
- package/src/ui/components/shell/host.tsx +71 -0
- package/src/ui/components/shell/index.tsx +737 -0
- package/src/ui/components/shell/panes.tsx +76 -0
- package/src/ui/components/shell/preview.ts +230 -0
- package/src/ui/components/shell/rail.tsx +163 -0
- package/src/ui/components/shell/row.ts +11 -0
- package/src/ui/components/shell/switcher.tsx +143 -0
- package/src/ui/components/shell/tree.tsx +252 -0
- package/src/ui/components/slider/base.tsx +139 -0
- package/src/ui/components/slider/index.tsx +57 -0
- package/src/ui/components/stages/index.tsx +198 -0
- package/src/ui/components/stats/count-links.tsx +47 -0
- package/src/ui/components/stats/index.tsx +203 -0
- package/src/ui/components/stats/meter.tsx +213 -0
- package/src/ui/components/stats/parts.ts +10 -0
- package/src/ui/components/step-count/index.tsx +45 -0
- package/src/ui/components/switch/base.tsx +86 -0
- package/src/ui/components/switch/index.tsx +38 -0
- package/src/ui/components/table/columns.tsx +131 -0
- package/src/ui/components/table/index.tsx +2215 -0
- package/src/ui/components/text/index.tsx +37 -0
- package/src/ui/components/thread/index.tsx +503 -0
- package/src/ui/components/thread/latest.tsx +59 -0
- package/src/ui/components/toast/index.tsx +113 -0
- package/src/ui/components/toast/layer.tsx +26 -0
- package/src/ui/components/toolbar/filters.tsx +161 -0
- package/src/ui/components/toolbar/index.tsx +125 -0
- package/src/ui/components/waveform/index.tsx +205 -0
- package/src/ui/globals.css +427 -0
- package/src/ui/lib/act.ts +60 -0
- package/src/ui/lib/age.ts +49 -0
- package/src/ui/lib/bound.ts +16 -0
- package/src/ui/lib/canvas-layout.ts +11 -0
- package/src/ui/lib/caret.ts +9 -0
- package/src/ui/lib/chip-lines.ts +3 -0
- package/src/ui/lib/closed.ts +8 -0
- package/src/ui/lib/code.tsx +184 -0
- package/src/ui/lib/columns.ts +39 -0
- package/src/ui/lib/commit.ts +24 -0
- package/src/ui/lib/container.ts +112 -0
- package/src/ui/lib/copy.ts +29 -0
- package/src/ui/lib/drag.ts +575 -0
- package/src/ui/lib/empty.tsx +85 -0
- package/src/ui/lib/field.ts +39 -0
- package/src/ui/lib/focus.ts +175 -0
- package/src/ui/lib/folds.ts +67 -0
- package/src/ui/lib/follow.ts +220 -0
- package/src/ui/lib/form.ts +19 -0
- package/src/ui/lib/guards.ts +38 -0
- package/src/ui/lib/heading.ts +14 -0
- package/src/ui/lib/ink.ts +26 -0
- package/src/ui/lib/lang.ts +7 -0
- package/src/ui/lib/leave.ts +14 -0
- package/src/ui/lib/lockup.tsx +145 -0
- package/src/ui/lib/measure.ts +22 -0
- package/src/ui/lib/media.ts +63 -0
- package/src/ui/lib/modality.ts +69 -0
- package/src/ui/lib/moment.ts +13 -0
- package/src/ui/lib/more.tsx +76 -0
- package/src/ui/lib/navigate.ts +210 -0
- package/src/ui/lib/noop.ts +3 -0
- package/src/ui/lib/not-found.tsx +40 -0
- package/src/ui/lib/paint.tsx +55 -0
- package/src/ui/lib/parts-line.tsx +54 -0
- package/src/ui/lib/picked.ts +18 -0
- package/src/ui/lib/player-store.ts +38 -0
- package/src/ui/lib/player.ts +139 -0
- package/src/ui/lib/portal.ts +12 -0
- package/src/ui/lib/read.tsx +269 -0
- package/src/ui/lib/region.tsx +49 -0
- package/src/ui/lib/reorder.ts +154 -0
- package/src/ui/lib/rest.ts +16 -0
- package/src/ui/lib/saved.ts +29 -0
- package/src/ui/lib/scramble.tsx +147 -0
- package/src/ui/lib/scrolls.ts +70 -0
- package/src/ui/lib/style.ts +6 -0
- package/src/ui/lib/swap.tsx +107 -0
- package/src/ui/lib/toast.ts +39 -0
- package/src/ui/lib/walk-classes.ts +16 -0
- package/src/ui/lib/window.tsx +376 -0
- package/src/ui/worker.d.ts +4 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChoiceSegment,
|
|
3
|
+
IconLinkAct,
|
|
4
|
+
LinkSegment,
|
|
5
|
+
Option,
|
|
6
|
+
OptionGroup,
|
|
7
|
+
} from "@slotform/ui-core/descriptors";
|
|
8
|
+
import type { OptionRegions } from "@slotform/ui-core/list-state";
|
|
9
|
+
import { linked } from "@slotform/ui-core/pick";
|
|
10
|
+
import { FieldOwned } from "@slotform/ui-core/react/field";
|
|
11
|
+
import type { Datum, Fielded as WithText } from "@slotform/ui-core/read";
|
|
12
|
+
import type { OptionText } from "@slotform/ui-core/reason";
|
|
13
|
+
import type { PickerFit } from "@slotform/ui-core/variants";
|
|
14
|
+
import { type ReactElement, type ReactNode, use } from "react";
|
|
15
|
+
import type { IconAct } from "../../lib/act.ts";
|
|
16
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
17
|
+
import type { Fielded } from "../../lib/field.ts";
|
|
18
|
+
import { FieldBody } from "../form-field/index.tsx";
|
|
19
|
+
import { HeldPicker } from "./base.tsx";
|
|
20
|
+
import { HeldList } from "./list.tsx";
|
|
21
|
+
import { HeldSegments, LinkSegments } from "./segments.tsx";
|
|
22
|
+
|
|
23
|
+
interface Shared<V extends string | null> extends Closed, Fielded {
|
|
24
|
+
/** The hint drawn while nothing is chosen, in the placeholder's ink (a short phrase; truncates). None, it is nothing in a field, whose label stands over the box, the word for choosing at the `row` fit, and `label` at the other fits. The label is also the touch sheet's title. */
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
/** The choices, flat or under group labels; an option may carry a status, an avatar or a chip. A selection paints the trigger, inert, until its read lands; an option's `label`, `description` and `blocked` may be selections on their own, which paint it the same way. */
|
|
27
|
+
options: WithText<
|
|
28
|
+
readonly Option<V>[] | readonly OptionGroup<V>[],
|
|
29
|
+
OptionText
|
|
30
|
+
>;
|
|
31
|
+
/** Where it stands: a `FormField`'s field box (the default), a bar (`bar`: a toolbar's filter, a rule's term: the field box in the meta ink, quiet while empty, a filter reading its label then its value), a row's trailing value (`row`) in a control-radius box (where the chosen option carries a state, the compact state pill holding its chevron), or a pill (`pill`) in a Pane's bar: the control height, a hairline border, the chosen label truncating at the popover's width and a mark-ink chevron. `list` stands the options in the page as rows, `segments` as one row of segments. */
|
|
32
|
+
fit?: PickerFit;
|
|
33
|
+
/** The act that makes a new option, ending the list under a hairline: an act that runs, or a link to where it is made. */
|
|
34
|
+
act?: IconAct | IconLinkAct;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A pick of one option. */
|
|
38
|
+
export interface PickOneProps<V extends string | null = string>
|
|
39
|
+
extends Shared<V> {
|
|
40
|
+
/** The chosen option's value. A selection paints the trigger, inert, until its read lands and follows it until the viewer picks. Once its read ended the control stands with no value and a change says why instead. */
|
|
41
|
+
value?: Datum<NoInfer<V>>;
|
|
42
|
+
/** Hears the picked option's value. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
43
|
+
onChange: (value: NoInfer<V>) => unknown;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A pick of several options. */
|
|
47
|
+
export interface PickSeveralProps<V extends string | null = string>
|
|
48
|
+
extends Shared<V> {
|
|
49
|
+
/** The chosen options' values. A selection of them paints as a single pick, the stand-in being no array. */
|
|
50
|
+
value: Datum<readonly NoInfer<V>[]>;
|
|
51
|
+
/** Hears the chosen values once an option is ticked or a chip removed. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
52
|
+
onChange: (value: NoInfer<V>[]) => unknown;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The menu fits: a pick that applies at once, outside a form: in a toolbar, a row, a definition or a rule. `V` is read off the options, so an enum's options pick that enum; an option whose value is `null` is the empty choice. A `value` that is an array picks several. */
|
|
56
|
+
export type PickerMenuProps<V extends string | null = string> =
|
|
57
|
+
| PickOneProps<V>
|
|
58
|
+
| PickSeveralProps<V>;
|
|
59
|
+
|
|
60
|
+
/** Where a list's options come from. */
|
|
61
|
+
type OptionSource<T, V extends string> =
|
|
62
|
+
| {
|
|
63
|
+
/** The choices, flat or under group labels. They are constants: they never paint. */
|
|
64
|
+
options: readonly Option<V>[] | readonly OptionGroup<V>[];
|
|
65
|
+
items?: never;
|
|
66
|
+
option?: never;
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
/** The items the check rows draw, constants or a selection. While its read waits, `PAINT_ROWS` rows paint in the regions `option` declares, inert. */
|
|
70
|
+
items: Datum<readonly T[]>;
|
|
71
|
+
/** One function per check row region, each called with an item; the regions given are the shape the painted rows draw. */
|
|
72
|
+
option: OptionRegions<T, V>;
|
|
73
|
+
options?: never;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** The options of a list and what a chosen option opens. */
|
|
77
|
+
export type PickerListBody<V extends string, T> = OptionSource<T, V> & {
|
|
78
|
+
/** What a chosen option opens, under the first one chosen at its label's start. */
|
|
79
|
+
children?: ReactNode;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// What every list fit holds: its name, its fit and its body.
|
|
83
|
+
type PickerListShape<V extends string, T> = PickerListBody<V, T> &
|
|
84
|
+
Closed &
|
|
85
|
+
Fielded & {
|
|
86
|
+
fit: "list";
|
|
87
|
+
} & (
|
|
88
|
+
| { headed?: never }
|
|
89
|
+
| {
|
|
90
|
+
/** The list is the body of a titled `Section` that heads it: it draws no field, so the name stands once, as the Section's title. `label` is then only its accessible name (the title's words), and the Section's `description` describes it, so it takes no description, `optional` word or `error` of its own. */
|
|
91
|
+
headed: true;
|
|
92
|
+
description?: never;
|
|
93
|
+
optional?: never;
|
|
94
|
+
error?: never;
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/** A list of one choice: the chosen value or null, radio rows. A selection paints the radios, inert, until its read lands and follows it until the viewer chooses. Once its read ended the control stands with no value and a change says why instead. */
|
|
99
|
+
export type PickerListOneProps<
|
|
100
|
+
V extends string = string,
|
|
101
|
+
T = unknown,
|
|
102
|
+
> = PickerListShape<V, T> & {
|
|
103
|
+
value: Datum<NoInfer<V> | null>;
|
|
104
|
+
/** Hears the option chosen. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
105
|
+
onChange: (value: V) => unknown;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** A list of several choices: the chosen set, check rows. A selection of it paints as one choice, the stand-in being no array. */
|
|
109
|
+
export type PickerListSetProps<
|
|
110
|
+
V extends string = string,
|
|
111
|
+
T = unknown,
|
|
112
|
+
> = PickerListShape<V, T> & {
|
|
113
|
+
value: Datum<readonly NoInfer<V>[]>;
|
|
114
|
+
/** Hears the whole chosen set after a toggle. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
115
|
+
onChange: (value: V[]) => unknown;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** The list fit: one choice or several from one list, static or from items. `V` is read off the options or the `option` map's `value`. */
|
|
119
|
+
export type PickerListProps<V extends string = string, T = unknown> =
|
|
120
|
+
| PickerListOneProps<V, T>
|
|
121
|
+
| PickerListSetProps<V, T>;
|
|
122
|
+
|
|
123
|
+
/** The segments fit over choices: a view switch over a few options, one chosen. */
|
|
124
|
+
export interface PickerSegmentsProps<V extends string = string>
|
|
125
|
+
extends Closed,
|
|
126
|
+
Fielded {
|
|
127
|
+
fit: "segments";
|
|
128
|
+
/** The options in order, each a word up to the short measure; the track scrolls sideways where the segments do not fit, so no label is cut for room. */
|
|
129
|
+
options: readonly ChoiceSegment<V>[];
|
|
130
|
+
/** The chosen option's value. A selection paints the track, inert, until its read lands and follows it until the viewer chooses. Once its read ended the control stands with no value and a change says why instead. */
|
|
131
|
+
value: Datum<NoInfer<V>>;
|
|
132
|
+
/** Hears the chosen option's value. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
133
|
+
onChange: (value: NoInfer<V>) => unknown;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The segments fit over links, the tabs of a place: each option an `href` and a label. The one whose href is the location's path or its nearest parent is selected, and a press opens its href in place; where the tabs do not fit, the track scrolls sideways (no label is cut for room) with the selected tab scrolled into view. It holds no value and hears no change: the location is its value. */
|
|
137
|
+
export interface PickerTabsProps extends Closed {
|
|
138
|
+
fit: "segments";
|
|
139
|
+
options: readonly LinkSegment[];
|
|
140
|
+
label?: never;
|
|
141
|
+
description?: never;
|
|
142
|
+
optional?: never;
|
|
143
|
+
error?: never;
|
|
144
|
+
value?: never;
|
|
145
|
+
onChange?: never;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A Picker in any of its fits, `V` the option value type: a menu (a field box or a row's value opening a popover), a `list` of rows in the page, or `segments`. */
|
|
149
|
+
export type PickerProps<V extends string | null = string, T = unknown> =
|
|
150
|
+
| PickerMenuProps<V>
|
|
151
|
+
| PickerListProps<Extract<V, string>, T>
|
|
152
|
+
| PickerSegmentsProps<Extract<V, string>>
|
|
153
|
+
| PickerTabsProps;
|
|
154
|
+
|
|
155
|
+
/** The pick of a place's options. As a menu, the field box showing the chosen label (the empty choice, and no choice, in the placeholder's ink), or a row's value and a chevron in a control-radius box: it opens a popover of rows under the trigger's end on the desktop, the chosen one ticked, a search leading past six options and the act under a hairline after them, and with no option a line saying there is nothing to choose yet; on touch a sheet of the same rows titled `label`. Given an array it picks several: the rows tick and the list stays open, and the box holds one removable compact pill per value, inset in the box with room above and below it. As a `list` (`fit="list"`), option rows on a hairline card, each the Checkbox (several choices) or the radio (one choice, a radiogroup) on its label's first line, the recommended mark (a glyph and its word) leading the line under it, then a `line`; the row under the pointer washes, the checked box or the ringed dot is the choice. The children stand under the first chosen option. Placed alone it draws its field; `headed`, the body of a titled `Section`, it draws none, the title naming it. Static `options` never paint; `items` paint `PAINT_ROWS` rows in the regions `option` declares while their read waits, and a `value` selection paints the marks, inert. The frame that holds the read draws its failed, missing and empty shapes. A pick whose options failed, in a row or a head, draws the failed row's mark and a retry icon at its end, so it stands on one line whatever the width. As `segments` (`fit="segments"`), segments an inside gap apart on no ground and no border, the chosen one under the selection wash in body ink at weight 500, the others in meta ink, washing and taking the body ink under the pointer; a radio group whose arrow keys move the choice; a strip that scrolls sideways fades at each end that holds more. Given `href`s and no values, the segments are links, the tabs of a place. */
|
|
156
|
+
export function Picker<V extends string | null = string>(
|
|
157
|
+
props: PickOneProps<V>,
|
|
158
|
+
): ReactElement;
|
|
159
|
+
export function Picker<V extends string | null = string>(
|
|
160
|
+
props: PickSeveralProps<V>,
|
|
161
|
+
): ReactElement;
|
|
162
|
+
export function Picker<V extends string = string, T = unknown>(
|
|
163
|
+
props: PickerListOneProps<V, T>,
|
|
164
|
+
): ReactElement;
|
|
165
|
+
export function Picker<V extends string = string, T = unknown>(
|
|
166
|
+
props: PickerListSetProps<V, T>,
|
|
167
|
+
): ReactElement;
|
|
168
|
+
export function Picker<V extends string = string>(
|
|
169
|
+
props: PickerSegmentsProps<V>,
|
|
170
|
+
): ReactElement;
|
|
171
|
+
export function Picker(props: PickerTabsProps): ReactElement;
|
|
172
|
+
export function Picker<V extends string | null = string, T = unknown>(
|
|
173
|
+
props: PickerProps<V, T>,
|
|
174
|
+
) {
|
|
175
|
+
// The overloads type each fit's value and handler pairing; this call
|
|
176
|
+
// reads them off the fit alone, so it cannot. Placed alone, the field fit,
|
|
177
|
+
// a list and choice segments draw their field; the tabs are a place's
|
|
178
|
+
// links, and the bar, row and pill fits read their label in their box.
|
|
179
|
+
const owned = use(FieldOwned);
|
|
180
|
+
if (props.fit === "segments" && linked(props.options))
|
|
181
|
+
return <LinkSegments options={props.options} />;
|
|
182
|
+
if (
|
|
183
|
+
props.fit === "list" ||
|
|
184
|
+
props.fit === "segments" ||
|
|
185
|
+
!props.fit ||
|
|
186
|
+
props.fit === "field"
|
|
187
|
+
) {
|
|
188
|
+
const { label, description, optional, error, fit, headed, ...control } =
|
|
189
|
+
props as Fielded & { fit?: string; headed?: true };
|
|
190
|
+
// An owner names the control, and a `headed` list's name is its Section's
|
|
191
|
+
// title: neither draws a field.
|
|
192
|
+
if (owned || (headed && fit === "list")) {
|
|
193
|
+
if (fit === "list")
|
|
194
|
+
return (
|
|
195
|
+
<HeldList {...(props as PickerListProps<Extract<V, string>, T>)} />
|
|
196
|
+
);
|
|
197
|
+
if (fit === "segments")
|
|
198
|
+
return (
|
|
199
|
+
<HeldSegments
|
|
200
|
+
{...(props as PickerSegmentsProps<Extract<V, string>>)}
|
|
201
|
+
/>
|
|
202
|
+
);
|
|
203
|
+
} else {
|
|
204
|
+
const field = { label, description, optional, error, alone: true };
|
|
205
|
+
if (fit === "list")
|
|
206
|
+
return <FieldBody {...field} options={control as never} />;
|
|
207
|
+
if (fit === "segments")
|
|
208
|
+
return <FieldBody {...field} segments={control as never} />;
|
|
209
|
+
return <FieldBody {...field} picker={control as never} />;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const menu = props as PickerMenuProps<V>;
|
|
213
|
+
return (
|
|
214
|
+
<HeldPicker
|
|
215
|
+
label={menu.label}
|
|
216
|
+
placeholder={menu.placeholder}
|
|
217
|
+
options={menu.options}
|
|
218
|
+
fit={menu.fit}
|
|
219
|
+
act={menu.act}
|
|
220
|
+
value={menu.value as never}
|
|
221
|
+
onChange={menu.onChange as never}
|
|
222
|
+
/>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { Field } from "@base-ui/react/field";
|
|
2
|
+
import { Radio } from "@base-ui/react/radio";
|
|
3
|
+
import { RadioGroup } from "@base-ui/react/radio-group";
|
|
4
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
5
|
+
import type { Option } from "@slotform/ui-core/descriptors";
|
|
6
|
+
import {
|
|
7
|
+
choose,
|
|
8
|
+
chosenOf,
|
|
9
|
+
type OptionChoice,
|
|
10
|
+
type OptionRegions,
|
|
11
|
+
optionBlocked,
|
|
12
|
+
optionMeta,
|
|
13
|
+
optionsOf,
|
|
14
|
+
} from "@slotform/ui-core/list-state";
|
|
15
|
+
import { groupsOf, paintedGroups } from "@slotform/ui-core/pick";
|
|
16
|
+
import type { Draft } from "@slotform/ui-core/react/acts";
|
|
17
|
+
import { useDrawn } from "@slotform/ui-core/react/arrive";
|
|
18
|
+
import { useOptions } from "@slotform/ui-core/react/read";
|
|
19
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
20
|
+
import { isEnded } from "@slotform/ui-core/read";
|
|
21
|
+
import { sameBy } from "@slotform/ui-core/same-by";
|
|
22
|
+
import {
|
|
23
|
+
BLOCK_IN,
|
|
24
|
+
FLOW_IN,
|
|
25
|
+
lineBox,
|
|
26
|
+
OPTION_CHILDREN,
|
|
27
|
+
OPTION_INDENT,
|
|
28
|
+
OPTION_LINE,
|
|
29
|
+
OPTION_LIST,
|
|
30
|
+
OPTION_RADIO_DOT,
|
|
31
|
+
OPTION_ROW,
|
|
32
|
+
optionRadio,
|
|
33
|
+
PRESS_WASH,
|
|
34
|
+
row,
|
|
35
|
+
text,
|
|
36
|
+
} from "@slotform/ui-core/variants";
|
|
37
|
+
import {
|
|
38
|
+
memo,
|
|
39
|
+
type ReactNode,
|
|
40
|
+
use,
|
|
41
|
+
useId,
|
|
42
|
+
useMemo,
|
|
43
|
+
useRef,
|
|
44
|
+
useState,
|
|
45
|
+
} from "react";
|
|
46
|
+
import { MarkBadge } from "../../atoms/row/badges.tsx";
|
|
47
|
+
import { Leading } from "../../atoms/row/leading.tsx";
|
|
48
|
+
import { HeldCheckbox } from "../../atoms/switch/checkbox.tsx";
|
|
49
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
50
|
+
import { GroupName } from "../../lib/field.ts";
|
|
51
|
+
import { PAINT_CONTROL, Painted } from "../../lib/paint.tsx";
|
|
52
|
+
import { OptionsLine } from "../../lib/read.tsx";
|
|
53
|
+
import { Window } from "../../lib/window.tsx";
|
|
54
|
+
import { GROUP_LABEL } from "./base.tsx";
|
|
55
|
+
import type { PickerListBody, PickerListProps } from "./index.tsx";
|
|
56
|
+
|
|
57
|
+
const LIST = "flex flex-col";
|
|
58
|
+
const GROUP = "flex flex-col";
|
|
59
|
+
// A fieldset's floor is its content's width; the rows' is their column's.
|
|
60
|
+
const FIELDSET = "min-w-0";
|
|
61
|
+
// The row is the label of its box or radio: a press anywhere toggles or
|
|
62
|
+
// chooses it, except while it is blocked.
|
|
63
|
+
const OPTION = "flex items-center";
|
|
64
|
+
// A blocked option's label and reason.
|
|
65
|
+
const BLOCKED_INK = "text-ink-disabled";
|
|
66
|
+
// A label is the whole text of a choice: it wraps, and an unmarked row keeps
|
|
67
|
+
// the one-line row's height as its floor.
|
|
68
|
+
const OPTION_WHOLE = "py-gap";
|
|
69
|
+
const LINE = "flex grow min-w-0 items-start";
|
|
70
|
+
// The box stands on its label's first line, a box one body line tall; the
|
|
71
|
+
// row is its target.
|
|
72
|
+
const BOX_LINE = "flex shrink-0 items-center h-lh";
|
|
73
|
+
// The field wrapper that disables the box is a flex box itself, so the box
|
|
74
|
+
// stays a flex item on the line.
|
|
75
|
+
const FIELD = "flex";
|
|
76
|
+
const LABEL = "min-w-0 grow";
|
|
77
|
+
const TEXT = "flex flex-col min-w-0 grow";
|
|
78
|
+
// The recommended mark is a badge on a line of its own under the label, and the
|
|
79
|
+
// option's line is text under it.
|
|
80
|
+
const BADGE_ROW = "flex min-w-0";
|
|
81
|
+
// The radio is the box's size in its label's line, its dot centred; it is
|
|
82
|
+
// the focused element, so the base focus ring draws on it.
|
|
83
|
+
const RADIO =
|
|
84
|
+
"relative inline-flex shrink-0 items-center justify-center data-disabled:border-edge data-disabled:bg-fill-disabled";
|
|
85
|
+
const CHILDREN = "flex";
|
|
86
|
+
const CHILDREN_BODY = "flex flex-col grow min-w-0";
|
|
87
|
+
|
|
88
|
+
// One option's row, its children under it when it is the first chosen: a
|
|
89
|
+
// row's own element, so a window can place it. It reads its place among its
|
|
90
|
+
// group's options (`place` of `size`), which the rows a window leaves
|
|
91
|
+
// unmounted do not tell, and hears its press through `toggle`, so a refetch
|
|
92
|
+
// that changes one option renders that row alone.
|
|
93
|
+
interface OptionRowProps<V extends string> {
|
|
94
|
+
option: Option<V>;
|
|
95
|
+
place: number;
|
|
96
|
+
size: number;
|
|
97
|
+
chosen: boolean;
|
|
98
|
+
/** One choice (a radio) or several (a box). */
|
|
99
|
+
one: boolean;
|
|
100
|
+
/** The rows paint (their items wait). */
|
|
101
|
+
rowsPaint: boolean;
|
|
102
|
+
/** The marks paint, the rows or the value waiting. */
|
|
103
|
+
painted: boolean;
|
|
104
|
+
toggle: (value: V) => void;
|
|
105
|
+
/** The children of the list, on the first chosen option alone. */
|
|
106
|
+
children?: ReactNode;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// The chosen option's children: a block, in when the option is chosen and out
|
|
110
|
+
// when it is left. They fade in as they mount, when the list was already drawn.
|
|
111
|
+
function OptionChildren(props: { fade: boolean; children: ReactNode }) {
|
|
112
|
+
const [fades] = useState(props.fade);
|
|
113
|
+
return (
|
|
114
|
+
<div className={cn(OPTION_CHILDREN, CHILDREN, fades && BLOCK_IN)}>
|
|
115
|
+
<div className={cn(OPTION_INDENT, CHILDREN_BODY)}>{props.children}</div>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function OptionRowBase<V extends string>(props: OptionRowProps<V>) {
|
|
121
|
+
const { option, place, size, chosen, one, rowsPaint, painted, children } =
|
|
122
|
+
props;
|
|
123
|
+
const words = useWords();
|
|
124
|
+
const drawn = useDrawn();
|
|
125
|
+
const blocked = optionBlocked(option, chosen);
|
|
126
|
+
const meta = optionMeta(option, chosen);
|
|
127
|
+
// The recommended mark leads the meta line, so a recommended
|
|
128
|
+
// option is two lines, its label keeping the row's width at every size.
|
|
129
|
+
const recommended = !rowsPaint && option.recommended === true;
|
|
130
|
+
// A painted row is marked when the map declares a line.
|
|
131
|
+
const marked = rowsPaint
|
|
132
|
+
? option.line !== undefined
|
|
133
|
+
: Boolean(meta) || recommended;
|
|
134
|
+
const target = { labelledBy: useId() };
|
|
135
|
+
// The option's leading draws as a row's does: its glyph, status mark or avatar.
|
|
136
|
+
const leading = option.leading;
|
|
137
|
+
// The line under the label (and under the recommended badge), plain text.
|
|
138
|
+
const said = rowsPaint ? (
|
|
139
|
+
<span className={text({ role: "meta" })}>
|
|
140
|
+
<Painted role="phrase" at={place + 1} />
|
|
141
|
+
</span>
|
|
142
|
+
) : meta ? (
|
|
143
|
+
<span
|
|
144
|
+
key={blocked}
|
|
145
|
+
className={cn(
|
|
146
|
+
text({ role: "meta" }),
|
|
147
|
+
blocked !== undefined && cn(BLOCKED_INK, FLOW_IN),
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
{meta}
|
|
151
|
+
</span>
|
|
152
|
+
) : null;
|
|
153
|
+
return (
|
|
154
|
+
<div className={GROUP}>
|
|
155
|
+
{/* biome-ignore lint/a11y/noLabelWithoutControl: the Checkbox or the radio inside is its control */}
|
|
156
|
+
<label
|
|
157
|
+
inert={painted || undefined}
|
|
158
|
+
className={cn(
|
|
159
|
+
row(),
|
|
160
|
+
OPTION_ROW,
|
|
161
|
+
OPTION,
|
|
162
|
+
blocked === undefined && !painted && PRESS_WASH,
|
|
163
|
+
!marked && OPTION_WHOLE,
|
|
164
|
+
)}
|
|
165
|
+
>
|
|
166
|
+
<span className={cn(OPTION_LINE, LINE)}>
|
|
167
|
+
<span className={cn(lineBox({ role: "body" }), BOX_LINE)}>
|
|
168
|
+
{one ? (
|
|
169
|
+
<Radio.Root
|
|
170
|
+
value={option.value}
|
|
171
|
+
disabled={blocked !== undefined}
|
|
172
|
+
aria-labelledby={target.labelledBy}
|
|
173
|
+
aria-setsize={size}
|
|
174
|
+
aria-posinset={place + 1}
|
|
175
|
+
className={cn(
|
|
176
|
+
optionRadio({
|
|
177
|
+
state: chosen ? "checked" : "unchecked",
|
|
178
|
+
}),
|
|
179
|
+
RADIO,
|
|
180
|
+
painted && PAINT_CONTROL,
|
|
181
|
+
)}
|
|
182
|
+
>
|
|
183
|
+
<Radio.Indicator className={OPTION_RADIO_DOT} />
|
|
184
|
+
</Radio.Root>
|
|
185
|
+
) : (
|
|
186
|
+
<Field.Root disabled={blocked !== undefined} className={FIELD}>
|
|
187
|
+
<HeldCheckbox
|
|
188
|
+
target={target}
|
|
189
|
+
checked={chosen}
|
|
190
|
+
onChange={() => props.toggle(option.value)}
|
|
191
|
+
label={option.label}
|
|
192
|
+
painted={painted}
|
|
193
|
+
/>
|
|
194
|
+
</Field.Root>
|
|
195
|
+
)}
|
|
196
|
+
</span>
|
|
197
|
+
{leading ? (
|
|
198
|
+
<span className={cn(lineBox({ role: "body" }), BOX_LINE)}>
|
|
199
|
+
<Leading
|
|
200
|
+
leading={leading}
|
|
201
|
+
named={option.label}
|
|
202
|
+
painted={rowsPaint}
|
|
203
|
+
/>
|
|
204
|
+
</span>
|
|
205
|
+
) : null}
|
|
206
|
+
{marked ? (
|
|
207
|
+
<span className={TEXT}>
|
|
208
|
+
<span
|
|
209
|
+
id={target.labelledBy}
|
|
210
|
+
className={cn(
|
|
211
|
+
text({ role: "body" }),
|
|
212
|
+
blocked !== undefined && BLOCKED_INK,
|
|
213
|
+
)}
|
|
214
|
+
>
|
|
215
|
+
{rowsPaint ? (
|
|
216
|
+
<Painted role="phrase" at={place} />
|
|
217
|
+
) : (
|
|
218
|
+
option.label
|
|
219
|
+
)}
|
|
220
|
+
</span>
|
|
221
|
+
{recommended ? (
|
|
222
|
+
<span className={BADGE_ROW}>
|
|
223
|
+
<MarkBadge
|
|
224
|
+
mark={{ flag: "ThumbsUp", label: words.recommended }}
|
|
225
|
+
/>
|
|
226
|
+
</span>
|
|
227
|
+
) : null}
|
|
228
|
+
{said}
|
|
229
|
+
</span>
|
|
230
|
+
) : (
|
|
231
|
+
<span
|
|
232
|
+
id={target.labelledBy}
|
|
233
|
+
className={cn(text({ role: "body" }), LABEL)}
|
|
234
|
+
>
|
|
235
|
+
{rowsPaint ? <Painted role="phrase" at={place} /> : option.label}
|
|
236
|
+
</span>
|
|
237
|
+
)}
|
|
238
|
+
</span>
|
|
239
|
+
</label>
|
|
240
|
+
{children ? (
|
|
241
|
+
<OptionChildren fade={drawn}>{children}</OptionChildren>
|
|
242
|
+
) : null}
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// `memo` returns a component without the type parameter it wraps.
|
|
248
|
+
const OptionRow = memo(OptionRowBase, sameBy("option")) as typeof OptionRowBase;
|
|
249
|
+
|
|
250
|
+
// One group of options: its label over its rows. The rows stand in a box of
|
|
251
|
+
// their own, so a long group windows them (a label stays out of the box), the
|
|
252
|
+
// radio that holds the tab stop kept mounted.
|
|
253
|
+
function OptionGroupBox<V extends string>(props: {
|
|
254
|
+
group: { label?: string; options: readonly Option<V>[] };
|
|
255
|
+
one: boolean;
|
|
256
|
+
rowsPaint: boolean;
|
|
257
|
+
painted: boolean;
|
|
258
|
+
chosenValues: readonly V[];
|
|
259
|
+
toggle: (value: V) => void;
|
|
260
|
+
children?: ReactNode;
|
|
261
|
+
}) {
|
|
262
|
+
const { group, chosenValues } = props;
|
|
263
|
+
const box = useRef<HTMLDivElement>(null);
|
|
264
|
+
const first = chosenValues[0];
|
|
265
|
+
const { options } = group;
|
|
266
|
+
// The radios' one tab stop is the chosen one, else the first.
|
|
267
|
+
const stop = Math.max(
|
|
268
|
+
options.findIndex((option) => option.value === first),
|
|
269
|
+
0,
|
|
270
|
+
);
|
|
271
|
+
const rowAt = (place: number) => {
|
|
272
|
+
// `Window` hands only indexes under its `count`, the list's length.
|
|
273
|
+
const option = options[place] as Option<V>;
|
|
274
|
+
const chosen = chosenValues.includes(option.value);
|
|
275
|
+
return (
|
|
276
|
+
<OptionRow
|
|
277
|
+
key={String(option.value)}
|
|
278
|
+
option={option}
|
|
279
|
+
place={place}
|
|
280
|
+
size={options.length}
|
|
281
|
+
chosen={chosen}
|
|
282
|
+
one={props.one}
|
|
283
|
+
rowsPaint={props.rowsPaint}
|
|
284
|
+
painted={props.painted}
|
|
285
|
+
toggle={props.toggle}
|
|
286
|
+
>
|
|
287
|
+
{option.value === first && chosen ? props.children : undefined}
|
|
288
|
+
</OptionRow>
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
return (
|
|
292
|
+
<fieldset className={cn(GROUP, FIELDSET)}>
|
|
293
|
+
{group.label === undefined ? null : (
|
|
294
|
+
<legend className={GROUP_LABEL}>
|
|
295
|
+
{props.rowsPaint ? <Painted role="word" /> : group.label}
|
|
296
|
+
</legend>
|
|
297
|
+
)}
|
|
298
|
+
<div ref={box} className={GROUP}>
|
|
299
|
+
<Window
|
|
300
|
+
count={options.length}
|
|
301
|
+
keyOf={(place) => String(options[place]?.value)}
|
|
302
|
+
row={rowAt}
|
|
303
|
+
box={box}
|
|
304
|
+
keep={props.one ? stop : undefined}
|
|
305
|
+
/>
|
|
306
|
+
</div>
|
|
307
|
+
</fieldset>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The option rows every Picker in `fit: list` renders, on the `draft` its host holds: a field hosts the draft of its options and draws a rejection in its own line. Static `options` never paint; `items` paint `PAINT_ROWS` rows in the regions `option` declares while their read waits, and the draft paints the marks, inert. The frame that holds the read draws its failed, missing and empty shapes. From `VIRTUAL_FROM` options in a group, under a scroller, it draws only the rows near the scroller's view. Outside the package's exports. */
|
|
312
|
+
export function PickerListBase<V extends string = string, T = unknown>(
|
|
313
|
+
props: PickerListBody<V, T> & {
|
|
314
|
+
/** Names the group where no `FormField` does. */
|
|
315
|
+
label?: string;
|
|
316
|
+
draft: Draft<V | null | readonly V[]>;
|
|
317
|
+
onChange: (next: V | V[]) => unknown;
|
|
318
|
+
},
|
|
319
|
+
) {
|
|
320
|
+
const { children, draft } = props;
|
|
321
|
+
const named = use(GroupName);
|
|
322
|
+
const name = named
|
|
323
|
+
? { "aria-labelledby": named.labelledBy }
|
|
324
|
+
: { "aria-label": props.label };
|
|
325
|
+
// Waiting items paint the rows; ended ones say so in a line under them.
|
|
326
|
+
const { drawn: given, retry } = useOptions(props.items);
|
|
327
|
+
// The rows paint while their items wait; the marks paint too while the
|
|
328
|
+
// value does, the labels then standing. A value whose read ended leaves the
|
|
329
|
+
// marks empty and blocked: a press says why and chooses nothing.
|
|
330
|
+
const rowsPaint = given.painted;
|
|
331
|
+
const painted = rowsPaint || (draft.painted && !draft.ended);
|
|
332
|
+
// The placeholder is no array, so a painted value is one choice.
|
|
333
|
+
const one = !Array.isArray(draft.value);
|
|
334
|
+
// The value and `onChange` are typed apart, so the compiler cannot see
|
|
335
|
+
// that a set's value comes with a set's `onChange`.
|
|
336
|
+
const choice = {
|
|
337
|
+
value: draft.painted ? (one ? null : []) : draft.value,
|
|
338
|
+
onChange: (next: V | V[]) => {
|
|
339
|
+
draft.change(next, () => props.onChange(next));
|
|
340
|
+
},
|
|
341
|
+
} as OptionChoice<V>;
|
|
342
|
+
const { option } = props;
|
|
343
|
+
const items = rowsPaint ? undefined : given.value;
|
|
344
|
+
const options = useMemo(
|
|
345
|
+
() =>
|
|
346
|
+
rowsPaint
|
|
347
|
+
? paintedGroups<V>(option)
|
|
348
|
+
: // A source without `options` holds `items` and `option`; `??`
|
|
349
|
+
// does not narrow the union to that form.
|
|
350
|
+
(props.options ??
|
|
351
|
+
optionsOf(items as readonly T[], option as OptionRegions<T, V>)),
|
|
352
|
+
[rowsPaint, option, props.options, items],
|
|
353
|
+
);
|
|
354
|
+
// A row hears its press through one function, which reads the choice the
|
|
355
|
+
// latest render made, so no row renders for a choice that is not its own.
|
|
356
|
+
const latest = useRef(choice);
|
|
357
|
+
latest.current = choice;
|
|
358
|
+
const [toggle] = useState(() => (value: V) => choose(latest.current, value));
|
|
359
|
+
const chosenValues = painted ? [] : chosenOf(choice);
|
|
360
|
+
const rows = groupsOf(options).map((group, at) => (
|
|
361
|
+
<OptionGroupBox<V>
|
|
362
|
+
key={group.label ?? at}
|
|
363
|
+
group={group}
|
|
364
|
+
one={one}
|
|
365
|
+
rowsPaint={rowsPaint}
|
|
366
|
+
painted={painted}
|
|
367
|
+
chosenValues={chosenValues}
|
|
368
|
+
toggle={toggle}
|
|
369
|
+
>
|
|
370
|
+
{children}
|
|
371
|
+
</OptionGroupBox>
|
|
372
|
+
));
|
|
373
|
+
// One choice is a radiogroup: Base UI moves between its radios by the
|
|
374
|
+
// arrows and chooses the one it reaches. Null, not undefined, keeps it
|
|
375
|
+
// controlled while nothing is chosen.
|
|
376
|
+
const list = one ? (
|
|
377
|
+
<RadioGroup<V | null>
|
|
378
|
+
// `one` holds that the value is no array.
|
|
379
|
+
value={choice.value as V | null}
|
|
380
|
+
onValueChange={(next) => {
|
|
381
|
+
if (next !== null) choose(choice, next);
|
|
382
|
+
}}
|
|
383
|
+
{...name}
|
|
384
|
+
className={cn(OPTION_LIST, LIST)}
|
|
385
|
+
>
|
|
386
|
+
{rows}
|
|
387
|
+
</RadioGroup>
|
|
388
|
+
) : (
|
|
389
|
+
<fieldset {...name} className={cn(OPTION_LIST, LIST, FIELDSET)}>
|
|
390
|
+
{rows}
|
|
391
|
+
</fieldset>
|
|
392
|
+
);
|
|
393
|
+
// Options that ended leave nothing to choose from: the sentence and Retry stand
|
|
394
|
+
// in the value column in the rows' place, one control-high line the label
|
|
395
|
+
// shares its centre with, never an empty card with the line under it.
|
|
396
|
+
const lone = given.painted && isEnded(given.phase);
|
|
397
|
+
return (
|
|
398
|
+
<>
|
|
399
|
+
{lone ? null : list}
|
|
400
|
+
<OptionsLine drawn={given} retry={retry} lone={lone} />
|
|
401
|
+
</>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** A list that holds its own draft, as a bare one does; a rejection toasts. Outside the package's exports. */
|
|
406
|
+
export function HeldList<V extends string = string, T = unknown>(
|
|
407
|
+
props: PickerListProps<V, T>,
|
|
408
|
+
) {
|
|
409
|
+
const { value, onChange, label, children, ...source } = props;
|
|
410
|
+
return (
|
|
411
|
+
<PickerListBase<V, T>
|
|
412
|
+
// The rest of a union's props loses which form it was.
|
|
413
|
+
{...(source as PickerListBody<V, T>)}
|
|
414
|
+
label={label}
|
|
415
|
+
draft={useHeldDraft<V | null | readonly V[]>(value)}
|
|
416
|
+
// The props pair a set's value with a set's `onChange`; the
|
|
417
|
+
// destructured `onChange` lost that pairing.
|
|
418
|
+
onChange={onChange as (next: V | V[]) => unknown}
|
|
419
|
+
>
|
|
420
|
+
{children}
|
|
421
|
+
</PickerListBase>
|
|
422
|
+
);
|
|
423
|
+
}
|