@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,45 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { Tone } from "@slotform/ui-core/tokens";
|
|
3
|
+
import { STATUS_SPINNER, statusDot } from "@slotform/ui-core/variants";
|
|
4
|
+
import { PAINT_BOX } from "../../lib/paint.tsx";
|
|
5
|
+
import { Swap } from "../../lib/swap.tsx";
|
|
6
|
+
import { Spinner } from "../spinner/index.tsx";
|
|
7
|
+
|
|
8
|
+
const DOT = "shrink-0";
|
|
9
|
+
const SPIN = "flex shrink-0";
|
|
10
|
+
|
|
11
|
+
/** A status's mark alone (its dot, or a `Spinner` in the accent ink while `running`): beside its word in a `Status`, named by `label` as a list row's leading, or leading a status pick's option. Outside the package's exports. `painted` is the dot's box while its state is not here, nothing drawn in it. */
|
|
12
|
+
export function StatusDot(props: {
|
|
13
|
+
tone: Tone;
|
|
14
|
+
label?: string;
|
|
15
|
+
painted?: boolean;
|
|
16
|
+
}) {
|
|
17
|
+
const { tone, label } = props;
|
|
18
|
+
if (props.painted)
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
aria-hidden
|
|
22
|
+
className={cn(statusDot({ tone: "done" }), DOT, PAINT_BOX)}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
const running = tone === "running";
|
|
26
|
+
const drawn = running
|
|
27
|
+
? cn(STATUS_SPINNER, SPIN)
|
|
28
|
+
: cn(statusDot({ tone }), DOT);
|
|
29
|
+
const mark = running ? <Spinner /> : null;
|
|
30
|
+
// A state that changes while shown is a mark change: the new dot grows in
|
|
31
|
+
// as the old one fades out.
|
|
32
|
+
return (
|
|
33
|
+
<Swap id={tone} scale>
|
|
34
|
+
{label ? (
|
|
35
|
+
<span role="img" aria-label={label} className={drawn}>
|
|
36
|
+
{mark}
|
|
37
|
+
</span>
|
|
38
|
+
) : (
|
|
39
|
+
<span aria-hidden className={drawn}>
|
|
40
|
+
{mark}
|
|
41
|
+
</span>
|
|
42
|
+
)}
|
|
43
|
+
</Swap>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Checkbox as Base } from "@base-ui/react/checkbox";
|
|
2
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
3
|
+
import { STATES } from "@slotform/ui-core/controls";
|
|
4
|
+
import type { Datum } from "@slotform/ui-core/read";
|
|
5
|
+
import { ICON_STROKE } from "@slotform/ui-core/tokens";
|
|
6
|
+
import { ANSWER, CHECKBOX_MARK, checkbox } from "@slotform/ui-core/variants";
|
|
7
|
+
import { Check, type IconNode, Minus } from "lucide";
|
|
8
|
+
import { createElement } from "react";
|
|
9
|
+
import { useHeldDraft } from "../../lib/act.ts";
|
|
10
|
+
import type { LabelFit } from "../../lib/field.ts";
|
|
11
|
+
import { PAINT_CONTROL } from "../../lib/paint.tsx";
|
|
12
|
+
|
|
13
|
+
/** A choice among others, on, off, or mixed over a set: the tick a row, a table's cell or head or an option draws. Outside the package's exports. */
|
|
14
|
+
interface CheckboxProps {
|
|
15
|
+
/** Whether it is checked; `mixed` when some of the set it stands for are. A selection paints the box, inert, until its read lands and follows it until the viewer toggles it. Once its read ended the control stands with no value and a change says why instead. */
|
|
16
|
+
checked: Datum<boolean | "mixed">;
|
|
17
|
+
/** Hears the next value when the viewer toggles it; a mixed box checks. Return the save's promise and the viewer's value holds while it pends; a refusal puts it back, with its reason. */
|
|
18
|
+
onChange: (checked: boolean) => unknown;
|
|
19
|
+
/** Its name; the row around it draws the visible label (a short phrase; read aloud, never drawn). */
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// The checkbox element is the target-sized hit box, so a press anywhere in it
|
|
24
|
+
// toggles; the box inside draws the states and the focus ring. In a row whose
|
|
25
|
+
// label is its target the element is the box's size.
|
|
26
|
+
const HIT =
|
|
27
|
+
"group/toggle inline-flex shrink-0 items-center justify-center size-target outline-none";
|
|
28
|
+
const IN_LABEL =
|
|
29
|
+
"group/toggle inline-flex shrink-0 items-center justify-center outline-none";
|
|
30
|
+
const RING =
|
|
31
|
+
"in-data-[modality=keyboard]:group-focus-visible/toggle:outline-2 group-focus-visible/toggle:outline-offset-2 group-focus-visible/toggle:outline-ring";
|
|
32
|
+
const UNCHECKED =
|
|
33
|
+
"relative inline-flex shrink-0 items-center justify-center overflow-hidden group-data-disabled/toggle:border-edge group-data-disabled/toggle:bg-fill-disabled";
|
|
34
|
+
const FILLED =
|
|
35
|
+
"relative inline-flex shrink-0 items-center justify-center overflow-hidden group-hover/toggle:bg-toggle-on-hover group-active/toggle:bg-toggle-on-hover group-data-disabled/toggle:bg-fill-disabled";
|
|
36
|
+
const WASH = `absolute inset-0 ${ANSWER} group-not-data-disabled/toggle:group-hover/toggle:bg-wash-hover group-not-data-disabled/toggle:group-active/toggle:bg-wash-press`;
|
|
37
|
+
const MARK = "relative flex data-disabled:text-ink-disabled";
|
|
38
|
+
const GLYPH = "w-full";
|
|
39
|
+
// Checked and mixed stand one over the other and cross-fade when the box moves
|
|
40
|
+
// between them (the indicator stays mounted); the check is the mark at rest.
|
|
41
|
+
const CHECKED = "in-data-indeterminate:opacity-0";
|
|
42
|
+
const MIXED = "absolute inset-0 opacity-0 in-data-indeterminate:opacity-100";
|
|
43
|
+
|
|
44
|
+
/** The tick box every selection renders, holding its own draft, as a row's and a cell's do; a rejection toasts. `target` is the label a row makes its target; `painted` is the box while its data is not here: filled, unchecked, inert. Outside the package's exports. */
|
|
45
|
+
export function HeldCheckbox({
|
|
46
|
+
checked,
|
|
47
|
+
onChange,
|
|
48
|
+
label,
|
|
49
|
+
target,
|
|
50
|
+
tabIndex,
|
|
51
|
+
painted: given,
|
|
52
|
+
}: CheckboxProps & {
|
|
53
|
+
target?: LabelFit;
|
|
54
|
+
/** `-1` where the box's host holds the tab stop (a tree's row, a `Table` cell the grid's cursor reaches); absent, it keeps Base UI's own. */
|
|
55
|
+
tabIndex?: -1;
|
|
56
|
+
painted?: boolean;
|
|
57
|
+
}) {
|
|
58
|
+
const draft = useHeldDraft(checked);
|
|
59
|
+
// A read that ended leaves the box empty and blocked.
|
|
60
|
+
const ended = draft.ended;
|
|
61
|
+
const painted = given || (draft.painted && !ended);
|
|
62
|
+
const absent = painted || ended;
|
|
63
|
+
const value = draft.value;
|
|
64
|
+
const state = STATES[absent ? "false" : (`${value}` as const)];
|
|
65
|
+
// A field disables the checkbox through Base UI's field context: docs/architecture/plugins/react-ui.md, "Field box and focus rings".
|
|
66
|
+
return (
|
|
67
|
+
<Base.Root
|
|
68
|
+
nativeButton
|
|
69
|
+
render={<button type="button" />}
|
|
70
|
+
checked={!absent && value === true}
|
|
71
|
+
indeterminate={!absent && value === "mixed"}
|
|
72
|
+
inert={painted || undefined}
|
|
73
|
+
aria-disabled={ended || undefined}
|
|
74
|
+
onCheckedChange={(next) => {
|
|
75
|
+
draft.change(next, () => onChange(next));
|
|
76
|
+
}}
|
|
77
|
+
aria-label={label}
|
|
78
|
+
aria-labelledby={target?.labelledBy}
|
|
79
|
+
// Base UI keeps its own tab stop unless the host holds it, which a
|
|
80
|
+
// `tabIndex` prop given as `undefined` would override.
|
|
81
|
+
{...(tabIndex === -1 ? { tabIndex: -1 } : {})}
|
|
82
|
+
className={target ? IN_LABEL : HIT}
|
|
83
|
+
>
|
|
84
|
+
<span
|
|
85
|
+
className={cn(
|
|
86
|
+
checkbox({ state }),
|
|
87
|
+
state === "unchecked" ? UNCHECKED : FILLED,
|
|
88
|
+
RING,
|
|
89
|
+
painted && PAINT_CONTROL,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
{/* An unchecked box's pointer states are a wash over its own fill. */}
|
|
93
|
+
{state === "unchecked" ? <span className={WASH} /> : null}
|
|
94
|
+
<Base.Indicator className={cn(CHECKBOX_MARK, MARK)}>
|
|
95
|
+
<Mark node={Check} look={cn(ANSWER, CHECKED)} />
|
|
96
|
+
<Mark node={Minus} look={cn(ANSWER, MIXED)} />
|
|
97
|
+
</Base.Indicator>
|
|
98
|
+
</span>
|
|
99
|
+
</Base.Root>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Lucide's own path data, drawn at the check's own weight rather than `Icon`'s.
|
|
104
|
+
function Mark({ node, look }: { node: IconNode; look: string }) {
|
|
105
|
+
return (
|
|
106
|
+
<svg
|
|
107
|
+
className={cn(GLYPH, look)}
|
|
108
|
+
viewBox="0 0 24 24"
|
|
109
|
+
fill="none"
|
|
110
|
+
stroke="currentColor"
|
|
111
|
+
strokeWidth={ICON_STROKE.mark}
|
|
112
|
+
strokeLinecap="round"
|
|
113
|
+
strokeLinejoin="round"
|
|
114
|
+
aria-hidden="true"
|
|
115
|
+
>
|
|
116
|
+
{node.map(([tag, attrs], index) =>
|
|
117
|
+
createElement(tag, { key: index, ...attrs }),
|
|
118
|
+
)}
|
|
119
|
+
</svg>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
2
|
+
import type { IconName } from "@slotform/ui-core/descriptors";
|
|
3
|
+
import { CHEVRON, type IconFit } from "@slotform/ui-core/variants";
|
|
4
|
+
import { Icon } from "./icon/index.tsx";
|
|
5
|
+
|
|
6
|
+
// A quarter turn takes a chevron down to right (a fold closing); a half turn
|
|
7
|
+
// takes an arrow or a chevron over to its opposite.
|
|
8
|
+
const BY = { quarter: "-rotate-90", half: "rotate-180" } as const;
|
|
9
|
+
|
|
10
|
+
/** A glyph that turns instead of being swapped for its opposite: a disclosure chevron, a sort arrow. It stands as `name` and, `turned`, a quarter or a half turn from it, on `CHEVRON`'s rung. */
|
|
11
|
+
export function Turn(props: {
|
|
12
|
+
name: IconName;
|
|
13
|
+
fit?: IconFit;
|
|
14
|
+
turned: boolean;
|
|
15
|
+
by: keyof typeof BY;
|
|
16
|
+
}) {
|
|
17
|
+
return (
|
|
18
|
+
<span
|
|
19
|
+
className={cn(
|
|
20
|
+
"inline-flex shrink-0",
|
|
21
|
+
CHEVRON,
|
|
22
|
+
props.turned && BY[props.by],
|
|
23
|
+
)}
|
|
24
|
+
>
|
|
25
|
+
<Icon name={props.name} fit={props.fit} />
|
|
26
|
+
</span>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Button as BaseButton } from "@base-ui/react/button";
|
|
2
|
+
import { chosenAbsent, kindOf, NO_FAILURE } from "@slotform/ui-core/action-bar";
|
|
3
|
+
import { cn } from "@slotform/ui-core/cn";
|
|
4
|
+
import type { ChosenCount, LinkAct } from "@slotform/ui-core/descriptors";
|
|
5
|
+
import { formatterFor } from "@slotform/ui-core/format";
|
|
6
|
+
import type { Acting } from "@slotform/ui-core/react/acts";
|
|
7
|
+
import { ReasonHostContext } from "@slotform/ui-core/react/reason";
|
|
8
|
+
import { useTouched } from "@slotform/ui-core/react/touched";
|
|
9
|
+
import { useWords } from "@slotform/ui-core/react/words";
|
|
10
|
+
import { pressStands } from "@slotform/ui-core/reason";
|
|
11
|
+
import { filled } from "@slotform/ui-core/tokens";
|
|
12
|
+
import {
|
|
13
|
+
ACTION_BAR,
|
|
14
|
+
ACTION_BAR_ACTS,
|
|
15
|
+
ACTION_BAR_ALL,
|
|
16
|
+
ACTION_BAR_CHOSEN,
|
|
17
|
+
ACTION_BAR_CHOSEN_COLUMN,
|
|
18
|
+
PRESS_WASH,
|
|
19
|
+
text,
|
|
20
|
+
} from "@slotform/ui-core/variants";
|
|
21
|
+
import { useState } from "react";
|
|
22
|
+
import { IconButtonBase } from "../../atoms/button/glyph.tsx";
|
|
23
|
+
import { ButtonLink } from "../../atoms/button/link.tsx";
|
|
24
|
+
import { Reason } from "../../atoms/button/reason.tsx";
|
|
25
|
+
import type { Act } from "../../lib/act.ts";
|
|
26
|
+
import { useAct } from "../../lib/act.ts";
|
|
27
|
+
import { ActInert, SubmitContext } from "../../lib/form.ts";
|
|
28
|
+
import { PendingBar } from "../banner/pending.tsx";
|
|
29
|
+
import { ButtonBase } from "../button/base.tsx";
|
|
30
|
+
import { MenuBase } from "../menu/base.tsx";
|
|
31
|
+
import type { ActionBarProps } from "./index.tsx";
|
|
32
|
+
|
|
33
|
+
// The bar is the `acts` container, its acts laid out by its width alone
|
|
34
|
+
// (`acts-stacked:`): plugins/react-ui/guide/acts.md, "ActionBar". The tree
|
|
35
|
+
// holds the acts in reading order, the filled act
|
|
36
|
+
// last, so a stacked bar runs in reverse to draw it on top.
|
|
37
|
+
const BAR = "@container/acts flex flex-col w-full";
|
|
38
|
+
const ACTS =
|
|
39
|
+
"flex flex-wrap items-center justify-end min-w-0 acts-stacked:flex-col-reverse acts-stacked:items-stretch acts-stacked:*:w-full";
|
|
40
|
+
const LINE = "text-end acts-stacked:text-start";
|
|
41
|
+
|
|
42
|
+
// A pending bar stands over the bar it replaces: the loaded bar holds the
|
|
43
|
+
// row's height at every density and wrap, unseen, inert and out of the tree
|
|
44
|
+
// readers walk, and the pending bar fills that box.
|
|
45
|
+
const HOLD = "relative self-stretch";
|
|
46
|
+
const OVER = "absolute inset-0";
|
|
47
|
+
const GHOST = "invisible";
|
|
48
|
+
|
|
49
|
+
// A chosen bar is one row that wraps only when it must: the count, then the
|
|
50
|
+
// act that chooses every row while some stand unchosen and the icon that
|
|
51
|
+
// clears the choice, at its start, and the acts at its end (the more menu, then
|
|
52
|
+
// the filled act). The count sets tabular digits, so it moves only when its
|
|
53
|
+
// digits do.
|
|
54
|
+
const SELECTION = "flex flex-wrap items-center justify-between self-stretch";
|
|
55
|
+
const CHOSEN_ACTS = "flex items-center";
|
|
56
|
+
const COUNT = "flex items-center shrink-0";
|
|
57
|
+
const ALL = cn(
|
|
58
|
+
"inline-flex shrink-0 items-center whitespace-nowrap text-ink-meta",
|
|
59
|
+
PRESS_WASH,
|
|
60
|
+
);
|
|
61
|
+
const ALL_LABEL = "whitespace-nowrap";
|
|
62
|
+
const SENTENCE = "shrink-0 whitespace-nowrap tabular-nums";
|
|
63
|
+
const NUMBER = formatterFor("number");
|
|
64
|
+
/** What a docked foot gives the bar it draws; no app sets it, so it is outside `ActionBarProps`. */
|
|
65
|
+
interface ActionBarInternal {
|
|
66
|
+
/** The bar keeps the reason's line before a reason shows, so showing it never moves the act it describes. */
|
|
67
|
+
kept?: boolean;
|
|
68
|
+
/** The holder that hosts this bar's acts' attempt, when the bar is not the only host (a sheet holds its dismissal while its bar's act pends). Absent, the bar hosts its own. */
|
|
69
|
+
acting?: Acting<number>;
|
|
70
|
+
/** The read the filled act submits waits or stands still: the act paints, inert, in its loaded box. */
|
|
71
|
+
painted?: boolean;
|
|
72
|
+
/** The read the filled act submits has ended: the act stands blocked under this reason, the failed sentence or `words.missing`. The body already says why, so the bar draws the sentence on a press only, while that press stands. */
|
|
73
|
+
ended?: string;
|
|
74
|
+
/** The filled act is its form's submit button, so Enter in a field presses it. */
|
|
75
|
+
submits?: boolean;
|
|
76
|
+
/** A press of the filled act while it is blocked: the form it submits shows what blocks it. */
|
|
77
|
+
onBlocked?: () => void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function AllAct(props: { label: string; onAct: () => void }) {
|
|
81
|
+
return (
|
|
82
|
+
<BaseButton onClick={props.onAct} className={cn(ACTION_BAR_ALL, ALL)}>
|
|
83
|
+
<span className={cn(text({ role: "meta" }), ALL_LABEL)}>
|
|
84
|
+
{props.label}
|
|
85
|
+
</span>
|
|
86
|
+
</BaseButton>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A chosen bar's count, then the act that chooses every row while some stand unchosen and the one that clears the choice. */
|
|
91
|
+
function Count({ chosen }: { chosen: ChosenCount }) {
|
|
92
|
+
const words = useWords();
|
|
93
|
+
const { onAll } = chosen;
|
|
94
|
+
const counts = {
|
|
95
|
+
count: NUMBER.format(chosen.count),
|
|
96
|
+
of: NUMBER.format(chosen.of),
|
|
97
|
+
};
|
|
98
|
+
const said =
|
|
99
|
+
chosen.noun === undefined
|
|
100
|
+
? filled(words.chosenOf, counts)
|
|
101
|
+
: filled(words.chosenNounOf, { ...counts, noun: chosen.noun });
|
|
102
|
+
return (
|
|
103
|
+
<div className={cn(ACTION_BAR_CHOSEN, COUNT)}>
|
|
104
|
+
<span role="status" className={cn(text({ role: "meta" }), SENTENCE)}>
|
|
105
|
+
{said}
|
|
106
|
+
</span>
|
|
107
|
+
{onAll && chosen.count < chosen.of ? (
|
|
108
|
+
<AllAct label={words.chooseAll} onAct={() => onAll(true)} />
|
|
109
|
+
) : null}
|
|
110
|
+
{onAll && chosen.count > 0 ? (
|
|
111
|
+
<IconButtonBase
|
|
112
|
+
icon="X"
|
|
113
|
+
label={words.chooseNone}
|
|
114
|
+
onClick={() => onAll(false)}
|
|
115
|
+
/>
|
|
116
|
+
) : null}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function ActionBarBase({
|
|
122
|
+
acts: offered,
|
|
123
|
+
chosen,
|
|
124
|
+
pending,
|
|
125
|
+
kept,
|
|
126
|
+
acting: given,
|
|
127
|
+
painted = false,
|
|
128
|
+
ended,
|
|
129
|
+
submits = false,
|
|
130
|
+
onBlocked,
|
|
131
|
+
}: ActionBarProps & ActionBarInternal) {
|
|
132
|
+
const words = useWords();
|
|
133
|
+
const own = useAct<number>("line");
|
|
134
|
+
// A failure draws in the bar's line under the acts; the same line says the
|
|
135
|
+
// connection refused an act.
|
|
136
|
+
const acting = given ?? own;
|
|
137
|
+
// The filled act is the one a read's end blocks. Its sentence is the body's
|
|
138
|
+
// already, so it draws on a press, not at rest.
|
|
139
|
+
const acts =
|
|
140
|
+
ended === undefined
|
|
141
|
+
? offered
|
|
142
|
+
: offered.map((act, at) =>
|
|
143
|
+
at === offered.length - 1 ? { ...act, blocked: ended } : act,
|
|
144
|
+
);
|
|
145
|
+
const { touched, leave } = useTouched();
|
|
146
|
+
// The reason a blocked act was pressed under: the press stands while that act
|
|
147
|
+
// is blocked by it (`pressStands`).
|
|
148
|
+
const [pressedUnder, setPressedUnder] = useState<string>();
|
|
149
|
+
const pressed = pressStands(ended, pressedUnder);
|
|
150
|
+
// A blocked act waits for a touch: inert and silent until it is pressed, or
|
|
151
|
+
// until its form or sheet has taken input; then its reason stands, in the line
|
|
152
|
+
// a failure would draw in (the pressed act's, else the last blocked act's).
|
|
153
|
+
// The filled act's, once its read ended, is the body's and draws on a press
|
|
154
|
+
// alone.
|
|
155
|
+
const reasoned = ended === undefined ? acts : acts.slice(0, -1);
|
|
156
|
+
const reason = reasoned.findLast((act) => act.blocked !== undefined)?.blocked;
|
|
157
|
+
const pressedReason = reasoned.some((act) =>
|
|
158
|
+
pressStands(act.blocked, pressedUnder),
|
|
159
|
+
)
|
|
160
|
+
? pressedUnder
|
|
161
|
+
: undefined;
|
|
162
|
+
const standing = pressedReason ?? (touched ? reason : undefined);
|
|
163
|
+
// The line stands only while it says something: a failure, a reason standing
|
|
164
|
+
// in answer to the viewer's press or input, or the ended read's sentence on
|
|
165
|
+
// a press. A blocked act takes no room before then, and the line leaves
|
|
166
|
+
// with what it said; only a docked foot's bar keeps its box (`kept`).
|
|
167
|
+
const said = acting.line ?? standing ?? (pressed ? ended : undefined);
|
|
168
|
+
const failed =
|
|
169
|
+
acting.line !== undefined && acting.pending === undefined && !pressed;
|
|
170
|
+
const lastAt = acts.length - 1;
|
|
171
|
+
const ordered = acts.map((act, at) => [act, at] as const);
|
|
172
|
+
// The press ends the form's edit before the filled act runs, so an act that
|
|
173
|
+
// navigates is not asked; a rejection puts the edit back.
|
|
174
|
+
const press = (act: Act, at: number) => {
|
|
175
|
+
const { onAct } = act;
|
|
176
|
+
return acting.attempt(at, {
|
|
177
|
+
...act,
|
|
178
|
+
onAct: at === lastAt && onAct ? () => leave.run(onAct) : onAct,
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
// The bar under a `PendingBar` is drawn with no act that submits or presses.
|
|
182
|
+
// A link (a way back, a way home) goes to its route as an anchor, quiet
|
|
183
|
+
// unless it is the filled act; blocked, it stands as a blocked act does,
|
|
184
|
+
// its reason in the bar's line.
|
|
185
|
+
const button = (
|
|
186
|
+
[act, at]: readonly [Act | LinkAct, number],
|
|
187
|
+
ghost: boolean,
|
|
188
|
+
) => {
|
|
189
|
+
const last = at === lastAt;
|
|
190
|
+
const running = acting.pending === at;
|
|
191
|
+
if ("href" in act && act.blocked === undefined)
|
|
192
|
+
return (
|
|
193
|
+
<ButtonLink
|
|
194
|
+
key={act.label}
|
|
195
|
+
act={kindOf({ quiet: true }, last)}
|
|
196
|
+
icon={act.icon}
|
|
197
|
+
label={act.label}
|
|
198
|
+
href={act.href}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
return (
|
|
202
|
+
<ReasonHostContext
|
|
203
|
+
key={act.label}
|
|
204
|
+
value={() => {
|
|
205
|
+
setPressedUnder(act.blocked);
|
|
206
|
+
if (last) onBlocked?.();
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<SubmitContext value={!ghost && last && submits}>
|
|
210
|
+
<ActInert value={ghost || (acting.holds && !running)}>
|
|
211
|
+
<ButtonBase
|
|
212
|
+
act={kindOf("href" in act ? {} : act, last)}
|
|
213
|
+
label={act.label}
|
|
214
|
+
onAct={"href" in act ? undefined : () => press(act, at)}
|
|
215
|
+
pending={running}
|
|
216
|
+
blocked={act.blocked}
|
|
217
|
+
painted={last && painted}
|
|
218
|
+
/>
|
|
219
|
+
</ActInert>
|
|
220
|
+
</SubmitContext>
|
|
221
|
+
</ReasonHostContext>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
const acted = (ghost: boolean) => (
|
|
225
|
+
<div className={cn(ACTION_BAR_ACTS, ACTS)}>
|
|
226
|
+
{ordered.map((entry) => button(entry, ghost))}
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
229
|
+
// A chosen bar's acts: the filled act stands and the others fold into the
|
|
230
|
+
// more menu, by rule and not by room, so the row is the same at every width.
|
|
231
|
+
const primary = ordered.at(-1);
|
|
232
|
+
const folded = ordered.slice(0, -1).map(([act]) => act);
|
|
233
|
+
const chose = (ghost: boolean) => (
|
|
234
|
+
<div className={cn(ACTION_BAR_ACTS, CHOSEN_ACTS)}>
|
|
235
|
+
{folded.length > 0 ? (
|
|
236
|
+
<MenuBase label={words.more} title={words.more} items={folded} />
|
|
237
|
+
) : null}
|
|
238
|
+
{primary ? button(primary, ghost) : null}
|
|
239
|
+
</div>
|
|
240
|
+
);
|
|
241
|
+
// One act clears the rows while any are chosen, one chooses every row while
|
|
242
|
+
// some stand unchosen; the table's head tick is the second where it stands, and the
|
|
243
|
+
// bar cannot tell which form the table drew in its own column, so both stand.
|
|
244
|
+
const bar = (ghost: boolean) => (
|
|
245
|
+
<div className={cn(ACTION_BAR, BAR, chosen && ACTION_BAR_CHOSEN_COLUMN)}>
|
|
246
|
+
{chosen ? (
|
|
247
|
+
<div className={cn(ACTION_BAR_CHOSEN, SELECTION)}>
|
|
248
|
+
<Count chosen={chosen} />
|
|
249
|
+
{chose(ghost)}
|
|
250
|
+
</div>
|
|
251
|
+
) : (
|
|
252
|
+
acted(ghost)
|
|
253
|
+
)}
|
|
254
|
+
{said === undefined && !kept ? null : (
|
|
255
|
+
<div className={LINE}>
|
|
256
|
+
<Reason kept={kept} failed={failed} shown={said !== undefined}>
|
|
257
|
+
{said ?? NO_FAILURE}
|
|
258
|
+
</Reason>
|
|
259
|
+
</div>
|
|
260
|
+
)}
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
// Nothing chosen, or nothing to choose: no bar.
|
|
264
|
+
if (chosen && chosenAbsent(chosen)) return null;
|
|
265
|
+
if (pending === undefined) return bar(false);
|
|
266
|
+
return (
|
|
267
|
+
<div className={HOLD}>
|
|
268
|
+
<div inert aria-hidden className={GHOST}>
|
|
269
|
+
{bar(true)}
|
|
270
|
+
</div>
|
|
271
|
+
<div className={OVER}>
|
|
272
|
+
<PendingBar {...pending} />
|
|
273
|
+
</div>
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ChosenCount, LinkAct } from "@slotform/ui-core/descriptors";
|
|
2
|
+
import type { Act } from "../../lib/act.ts";
|
|
3
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
4
|
+
import type { PendingBarProps } from "../banner/pending.tsx";
|
|
5
|
+
import { ActionBarBase } from "./base.tsx";
|
|
6
|
+
|
|
7
|
+
/** The acts that close a block (a form, a step, a sheet, a confirm), or that apply to the rows chosen in a list. */
|
|
8
|
+
export interface ActionBarProps extends Closed {
|
|
9
|
+
/** The acts in reading order, the one filled act last; a `LinkAct` (a way back, a way home) goes to its route as an anchor, quiet unless it is the filled act. Inside a `Form` the filled act submits it. A promise an act's `onAct` returns keeps it pending until it settles, the others inert meanwhile; a rejection stands in the bar's line under the acts (the server's refusal, else the act's `failed`, else "That didn't go through."), the act ready again. */
|
|
10
|
+
acts: (Act | LinkAct)[];
|
|
11
|
+
/** A chosen bar: one row at the bar's column, with the count, "N of M chosen" at meta, its numbers formatted, at its start (a `Table`'s `choose` set against its rows), then, with `onAll`, a select-all act while the ticked are fewer than `of` and a clear icon while any are ticked, and at its end the more menu holding every act but the last, then the filled act. It draws nothing while no row is ticked or `of` is 0. The route gives it to the `Pane`'s `foot`, where it stands in the body's column (the reading width, the Pane's width with `wide`) at its start, so it keeps the rows' grid; `of` is the rows that can be ticked, and `onAll` hears the set to choose (every one of them, or none). */
|
|
12
|
+
chosen?: ChosenCount;
|
|
13
|
+
/** The server works on a decision: a pending bar takes the bar's place at the bar's own loaded height, so nothing below it moves when `pending` is set or cleared. The acts stay drawn under it, unseen and out of reach. */
|
|
14
|
+
pending?: PendingBarProps;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The acts row over its line, beside a chosen count when `chosen` is set; while one act is pending the others ignore the press. It holds its acts' attempt. The width of the block it closes lays it out, never the viewport, and a blocked act's reason stands in the line under the acts: plugins/react-ui/guide/acts.md, "ActionBar". */
|
|
18
|
+
export function ActionBar(bar: ActionBarProps) {
|
|
19
|
+
return <ActionBarBase {...bar} />;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useSelections } from "@slotform/ui-core/react/read";
|
|
2
|
+
import { type Datum, paints } from "@slotform/ui-core/read";
|
|
3
|
+
import { AvatarBase } from "../../atoms/avatar/base.tsx";
|
|
4
|
+
import type { Closed } from "../../lib/closed.ts";
|
|
5
|
+
|
|
6
|
+
/** A person's circle. */
|
|
7
|
+
interface AvatarProps extends Closed {
|
|
8
|
+
/** The person's name: the accessible name, and the initials of its first two words without an image (a short phrase; only the initials draw; spaces, dots, underscores and hyphens part words, and an email address reads by its local part). A selection paints the circle until its read lands. */
|
|
9
|
+
name: Datum<string>;
|
|
10
|
+
/** The image's URL; without it, or when it fails to load, the circle draws the name's initials. A selection paints the circle like a `name` does, so the initials do not swap for the image. */
|
|
11
|
+
src?: Datum<string | undefined>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The image, else (none, or one that failed to load) the name's initials on the fill step its hash picks, so one name keeps one fill. */
|
|
15
|
+
export function Avatar({ name, src }: AvatarProps) {
|
|
16
|
+
const [person, picture] = useSelections([name, src]);
|
|
17
|
+
if (paints(person) || paints(picture)) return <AvatarBase name="" painted />;
|
|
18
|
+
// An ended read draws no circle; the frame that holds it says why.
|
|
19
|
+
if (person.painted || picture.painted) return null;
|
|
20
|
+
return <AvatarBase name={person.value} src={picture.value} />;
|
|
21
|
+
}
|