@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.
Files changed (280) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/density.d.ts +4 -0
  4. package/dist/density.d.ts.map +1 -0
  5. package/dist/density.js +8 -0
  6. package/dist/density.js.map +1 -0
  7. package/dist/index.d.ts +400 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +388 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/node/canvas.d.ts +3 -0
  12. package/dist/node/canvas.d.ts.map +1 -0
  13. package/dist/node/canvas.js +13 -0
  14. package/dist/node/canvas.js.map +1 -0
  15. package/dist/node/codegen.d.ts +6 -0
  16. package/dist/node/codegen.d.ts.map +1 -0
  17. package/dist/node/codegen.js +70 -0
  18. package/dist/node/codegen.js.map +1 -0
  19. package/dist/node/css-escape.d.ts +8 -0
  20. package/dist/node/css-escape.d.ts.map +1 -0
  21. package/dist/node/css-escape.js +12 -0
  22. package/dist/node/css-escape.js.map +1 -0
  23. package/dist/node/fonts.d.ts +6 -0
  24. package/dist/node/fonts.d.ts.map +1 -0
  25. package/dist/node/fonts.js +219 -0
  26. package/dist/node/fonts.js.map +1 -0
  27. package/dist/node/lint.d.ts +3 -0
  28. package/dist/node/lint.d.ts.map +1 -0
  29. package/dist/node/lint.js +23 -0
  30. package/dist/node/lint.js.map +1 -0
  31. package/dist/node/mode.d.ts +9 -0
  32. package/dist/node/mode.d.ts.map +1 -0
  33. package/dist/node/mode.js +38 -0
  34. package/dist/node/mode.js.map +1 -0
  35. package/dist/node/theme.d.ts +13 -0
  36. package/dist/node/theme.d.ts.map +1 -0
  37. package/dist/node/theme.js +160 -0
  38. package/dist/node/theme.js.map +1 -0
  39. package/dist/types.d.ts +250 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +80 -0
  42. package/dist/types.js.map +1 -0
  43. package/guide/acts.md +61 -0
  44. package/guide/audio.md +77 -0
  45. package/guide/blocks.md +82 -0
  46. package/guide/canvas-choosing.md +34 -0
  47. package/guide/canvas-editing.md +36 -0
  48. package/guide/canvas-layout.md +46 -0
  49. package/guide/canvas-opening.md +47 -0
  50. package/guide/canvas-overview.md +24 -0
  51. package/guide/canvas-states.md +37 -0
  52. package/guide/canvas-view.md +46 -0
  53. package/guide/canvas.md +94 -0
  54. package/guide/containers.md +60 -0
  55. package/guide/content.md +40 -0
  56. package/guide/controls.md +89 -0
  57. package/guide/density.md +48 -0
  58. package/guide/dock.md +42 -0
  59. package/guide/drag.md +38 -0
  60. package/guide/figures.md +25 -0
  61. package/guide/forms.md +82 -0
  62. package/guide/pane-bar.md +11 -0
  63. package/guide/pane.md +50 -0
  64. package/guide/reference.md +74 -0
  65. package/guide/rules.md +109 -0
  66. package/guide/section.md +29 -0
  67. package/guide/shell.md +26 -0
  68. package/guide/shots.md +37 -0
  69. package/guide/sidebar.md +30 -0
  70. package/guide/table.md +119 -0
  71. package/lint/no-arbitrary-value.grit +9 -0
  72. package/lint/no-class-on-component.grit +12 -0
  73. package/lint/no-density.grit +8 -0
  74. package/lint/no-host-look.grit +38 -0
  75. package/lint/no-img.grit +10 -0
  76. package/lint/no-navigate-act.grit +22 -0
  77. package/lint/no-raw-style.grit +8 -0
  78. package/package.json +150 -3
  79. package/src/density.ts +9 -0
  80. package/src/index.ts +503 -0
  81. package/src/node/canvas.ts +14 -0
  82. package/src/node/codegen.ts +100 -0
  83. package/src/node/css-escape.ts +27 -0
  84. package/src/node/fonts.ts +260 -0
  85. package/src/node/lint.ts +25 -0
  86. package/src/node/mode.ts +64 -0
  87. package/src/node/theme.ts +232 -0
  88. package/src/types.ts +120 -0
  89. package/src/ui/atoms/avatar/base.tsx +42 -0
  90. package/src/ui/atoms/button/glyph.tsx +244 -0
  91. package/src/ui/atoms/button/link.tsx +81 -0
  92. package/src/ui/atoms/button/look.ts +32 -0
  93. package/src/ui/atoms/button/reason.tsx +69 -0
  94. package/src/ui/atoms/chip/base.tsx +85 -0
  95. package/src/ui/atoms/count/base.tsx +27 -0
  96. package/src/ui/atoms/icon/index.tsx +51 -0
  97. package/src/ui/atoms/message/waiting.tsx +19 -0
  98. package/src/ui/atoms/prose/painted.tsx +35 -0
  99. package/src/ui/atoms/row/badges.tsx +226 -0
  100. package/src/ui/atoms/row/leading.tsx +166 -0
  101. package/src/ui/atoms/row/lock.tsx +17 -0
  102. package/src/ui/atoms/row/marks.tsx +79 -0
  103. package/src/ui/atoms/section/card.tsx +27 -0
  104. package/src/ui/atoms/spinner/index.tsx +42 -0
  105. package/src/ui/atoms/status/base.tsx +51 -0
  106. package/src/ui/atoms/status/change.tsx +29 -0
  107. package/src/ui/atoms/status/dot.tsx +45 -0
  108. package/src/ui/atoms/switch/checkbox.tsx +121 -0
  109. package/src/ui/atoms/turn.tsx +28 -0
  110. package/src/ui/components/action-bar/base.tsx +276 -0
  111. package/src/ui/components/action-bar/index.tsx +20 -0
  112. package/src/ui/components/avatar/index.tsx +21 -0
  113. package/src/ui/components/banner/index.tsx +207 -0
  114. package/src/ui/components/banner/pending.tsx +109 -0
  115. package/src/ui/components/bar-chart/index.tsx +701 -0
  116. package/src/ui/components/button/base.tsx +214 -0
  117. package/src/ui/components/button/face.tsx +84 -0
  118. package/src/ui/components/button/index.tsx +206 -0
  119. package/src/ui/components/canvas/connection.tsx +26 -0
  120. package/src/ui/components/canvas/edges.tsx +116 -0
  121. package/src/ui/components/canvas/elk.ts +260 -0
  122. package/src/ui/components/canvas/floor.ts +173 -0
  123. package/src/ui/components/canvas/geometry.ts +772 -0
  124. package/src/ui/components/canvas/ground.tsx +97 -0
  125. package/src/ui/components/canvas/group.tsx +156 -0
  126. package/src/ui/components/canvas/hit.ts +40 -0
  127. package/src/ui/components/canvas/index.tsx +497 -0
  128. package/src/ui/components/canvas/label.tsx +53 -0
  129. package/src/ui/components/canvas/layout.ts +543 -0
  130. package/src/ui/components/canvas/lift.ts +272 -0
  131. package/src/ui/components/canvas/look.ts +129 -0
  132. package/src/ui/components/canvas/node.tsx +689 -0
  133. package/src/ui/components/canvas/open.ts +243 -0
  134. package/src/ui/components/canvas/opening.ts +240 -0
  135. package/src/ui/components/canvas/view.ts +621 -0
  136. package/src/ui/components/canvas/viewport.ts +417 -0
  137. package/src/ui/components/canvas/zoom.tsx +113 -0
  138. package/src/ui/components/card/index.tsx +20 -0
  139. package/src/ui/components/chip/index.tsx +24 -0
  140. package/src/ui/components/code/frame.ts +2 -0
  141. package/src/ui/components/code/index.tsx +234 -0
  142. package/src/ui/components/columns/index.tsx +51 -0
  143. package/src/ui/components/count/index.tsx +17 -0
  144. package/src/ui/components/diff/index.tsx +249 -0
  145. package/src/ui/components/diff/word.tsx +104 -0
  146. package/src/ui/components/dock/index.tsx +262 -0
  147. package/src/ui/components/file-row/index.tsx +213 -0
  148. package/src/ui/components/form/base.tsx +280 -0
  149. package/src/ui/components/form/derive.tsx +269 -0
  150. package/src/ui/components/form/index.tsx +49 -0
  151. package/src/ui/components/form/saved.tsx +39 -0
  152. package/src/ui/components/form-field/index.tsx +658 -0
  153. package/src/ui/components/gallery/index.tsx +83 -0
  154. package/src/ui/components/gate/index.tsx +183 -0
  155. package/src/ui/components/image/base.tsx +245 -0
  156. package/src/ui/components/image/index.tsx +58 -0
  157. package/src/ui/components/input/base.tsx +246 -0
  158. package/src/ui/components/input/code.tsx +108 -0
  159. package/src/ui/components/input/drop.ts +37 -0
  160. package/src/ui/components/input/file.tsx +154 -0
  161. package/src/ui/components/input/index.tsx +132 -0
  162. package/src/ui/components/input/prose.tsx +107 -0
  163. package/src/ui/components/input/refusal.tsx +30 -0
  164. package/src/ui/components/item-header/base.tsx +410 -0
  165. package/src/ui/components/menu/base.tsx +319 -0
  166. package/src/ui/components/message/attachments.tsx +101 -0
  167. package/src/ui/components/message/base.tsx +266 -0
  168. package/src/ui/components/message-input/index.tsx +377 -0
  169. package/src/ui/components/missing/base.tsx +45 -0
  170. package/src/ui/components/pane/head.tsx +399 -0
  171. package/src/ui/components/pane/index.tsx +325 -0
  172. package/src/ui/components/picker/base.tsx +1551 -0
  173. package/src/ui/components/picker/index.tsx +224 -0
  174. package/src/ui/components/picker/list.tsx +423 -0
  175. package/src/ui/components/picker/segments.tsx +183 -0
  176. package/src/ui/components/prose/index.tsx +259 -0
  177. package/src/ui/components/qr-code/index.tsx +65 -0
  178. package/src/ui/components/row/acts.tsx +126 -0
  179. package/src/ui/components/row/fact.tsx +54 -0
  180. package/src/ui/components/row/index.tsx +1370 -0
  181. package/src/ui/components/row/progress.tsx +38 -0
  182. package/src/ui/components/row/status.tsx +54 -0
  183. package/src/ui/components/row/title.ts +7 -0
  184. package/src/ui/components/rules/index.tsx +290 -0
  185. package/src/ui/components/section/band.tsx +39 -0
  186. package/src/ui/components/section/head.tsx +267 -0
  187. package/src/ui/components/section/index.tsx +409 -0
  188. package/src/ui/components/section/rows.tsx +356 -0
  189. package/src/ui/components/sheet/base.tsx +272 -0
  190. package/src/ui/components/sheet/confirm.tsx +79 -0
  191. package/src/ui/components/sheet/docked.tsx +218 -0
  192. package/src/ui/components/sheet/form.tsx +76 -0
  193. package/src/ui/components/sheet/head.tsx +120 -0
  194. package/src/ui/components/sheet/index.tsx +45 -0
  195. package/src/ui/components/sheet/layer.tsx +168 -0
  196. package/src/ui/components/sheet/outlet.tsx +58 -0
  197. package/src/ui/components/sheet/task.tsx +41 -0
  198. package/src/ui/components/shell/cut.tsx +116 -0
  199. package/src/ui/components/shell/drag.tsx +45 -0
  200. package/src/ui/components/shell/host.tsx +71 -0
  201. package/src/ui/components/shell/index.tsx +737 -0
  202. package/src/ui/components/shell/panes.tsx +76 -0
  203. package/src/ui/components/shell/preview.ts +230 -0
  204. package/src/ui/components/shell/rail.tsx +163 -0
  205. package/src/ui/components/shell/row.ts +11 -0
  206. package/src/ui/components/shell/switcher.tsx +143 -0
  207. package/src/ui/components/shell/tree.tsx +252 -0
  208. package/src/ui/components/slider/base.tsx +139 -0
  209. package/src/ui/components/slider/index.tsx +57 -0
  210. package/src/ui/components/stages/index.tsx +198 -0
  211. package/src/ui/components/stats/count-links.tsx +47 -0
  212. package/src/ui/components/stats/index.tsx +203 -0
  213. package/src/ui/components/stats/meter.tsx +213 -0
  214. package/src/ui/components/stats/parts.ts +10 -0
  215. package/src/ui/components/step-count/index.tsx +45 -0
  216. package/src/ui/components/switch/base.tsx +86 -0
  217. package/src/ui/components/switch/index.tsx +38 -0
  218. package/src/ui/components/table/columns.tsx +131 -0
  219. package/src/ui/components/table/index.tsx +2215 -0
  220. package/src/ui/components/text/index.tsx +37 -0
  221. package/src/ui/components/thread/index.tsx +503 -0
  222. package/src/ui/components/thread/latest.tsx +59 -0
  223. package/src/ui/components/toast/index.tsx +113 -0
  224. package/src/ui/components/toast/layer.tsx +26 -0
  225. package/src/ui/components/toolbar/filters.tsx +161 -0
  226. package/src/ui/components/toolbar/index.tsx +125 -0
  227. package/src/ui/components/waveform/index.tsx +205 -0
  228. package/src/ui/globals.css +427 -0
  229. package/src/ui/lib/act.ts +60 -0
  230. package/src/ui/lib/age.ts +49 -0
  231. package/src/ui/lib/bound.ts +16 -0
  232. package/src/ui/lib/canvas-layout.ts +11 -0
  233. package/src/ui/lib/caret.ts +9 -0
  234. package/src/ui/lib/chip-lines.ts +3 -0
  235. package/src/ui/lib/closed.ts +8 -0
  236. package/src/ui/lib/code.tsx +184 -0
  237. package/src/ui/lib/columns.ts +39 -0
  238. package/src/ui/lib/commit.ts +24 -0
  239. package/src/ui/lib/container.ts +112 -0
  240. package/src/ui/lib/copy.ts +29 -0
  241. package/src/ui/lib/drag.ts +575 -0
  242. package/src/ui/lib/empty.tsx +85 -0
  243. package/src/ui/lib/field.ts +39 -0
  244. package/src/ui/lib/focus.ts +175 -0
  245. package/src/ui/lib/folds.ts +67 -0
  246. package/src/ui/lib/follow.ts +220 -0
  247. package/src/ui/lib/form.ts +19 -0
  248. package/src/ui/lib/guards.ts +38 -0
  249. package/src/ui/lib/heading.ts +14 -0
  250. package/src/ui/lib/ink.ts +26 -0
  251. package/src/ui/lib/lang.ts +7 -0
  252. package/src/ui/lib/leave.ts +14 -0
  253. package/src/ui/lib/lockup.tsx +145 -0
  254. package/src/ui/lib/measure.ts +22 -0
  255. package/src/ui/lib/media.ts +63 -0
  256. package/src/ui/lib/modality.ts +69 -0
  257. package/src/ui/lib/moment.ts +13 -0
  258. package/src/ui/lib/more.tsx +76 -0
  259. package/src/ui/lib/navigate.ts +210 -0
  260. package/src/ui/lib/noop.ts +3 -0
  261. package/src/ui/lib/not-found.tsx +40 -0
  262. package/src/ui/lib/paint.tsx +55 -0
  263. package/src/ui/lib/parts-line.tsx +54 -0
  264. package/src/ui/lib/picked.ts +18 -0
  265. package/src/ui/lib/player-store.ts +38 -0
  266. package/src/ui/lib/player.ts +139 -0
  267. package/src/ui/lib/portal.ts +12 -0
  268. package/src/ui/lib/read.tsx +269 -0
  269. package/src/ui/lib/region.tsx +49 -0
  270. package/src/ui/lib/reorder.ts +154 -0
  271. package/src/ui/lib/rest.ts +16 -0
  272. package/src/ui/lib/saved.ts +29 -0
  273. package/src/ui/lib/scramble.tsx +147 -0
  274. package/src/ui/lib/scrolls.ts +70 -0
  275. package/src/ui/lib/style.ts +6 -0
  276. package/src/ui/lib/swap.tsx +107 -0
  277. package/src/ui/lib/toast.ts +39 -0
  278. package/src/ui/lib/walk-classes.ts +16 -0
  279. package/src/ui/lib/window.tsx +376 -0
  280. package/src/ui/worker.d.ts +4 -0
@@ -0,0 +1,214 @@
1
+ import { Button as BaseButton } from "@base-ui/react/button";
2
+ import { cn } from "@slotform/ui-core/cn";
3
+ import { ReasonHostContext, usePressed } from "@slotform/ui-core/react/reason";
4
+ import { useTouched } from "@slotform/ui-core/react/touched";
5
+ import {
6
+ type ButtonAct,
7
+ type ButtonFit,
8
+ button,
9
+ buttonLabel,
10
+ } from "@slotform/ui-core/variants";
11
+ import { use } from "react";
12
+ import {
13
+ BLOCKED,
14
+ BOX,
15
+ FADE_IN,
16
+ FADE_OUT,
17
+ type Handed,
18
+ LABEL,
19
+ PRESS,
20
+ } from "../../atoms/button/look.ts";
21
+ import { Reason } from "../../atoms/button/reason.tsx";
22
+ import { CountBase } from "../../atoms/count/base.tsx";
23
+ import { Icon } from "../../atoms/icon/index.tsx";
24
+ import { Spinner } from "../../atoms/spinner/index.tsx";
25
+ import { useAct } from "../../lib/act.ts";
26
+ import { ActInert, endSubmit, SubmitContext } from "../../lib/form.ts";
27
+ import { PAINT_CONTROL } from "../../lib/paint.tsx";
28
+ import type { ButtonAttemptProps } from "./index.tsx";
29
+
30
+ const STACK =
31
+ "flex flex-col items-start gap-gap min-w-0 max-w-full *:max-w-full";
32
+ const GLYPH = "shrink-0";
33
+ const PENDING = "opacity-0";
34
+ // Painted, the act keeps its loaded box and draws none of its content.
35
+ const HIDDEN = "invisible";
36
+ const SPINNER_LAYER =
37
+ "absolute inset-0 flex items-center justify-center rounded-[inherit]";
38
+
39
+ const FILL_PENDING: Record<ButtonAct, string> = {
40
+ primary: "bg-act-accent-pending",
41
+ danger: "bg-act-danger-pending",
42
+ secondary: "",
43
+ destructive: "",
44
+ quiet: "",
45
+ };
46
+
47
+ // A filled act's label reads in the meta ink on the disabled fill, which holds
48
+ // 4.5:1; the unfilled acts' words are in the disabled ink.
49
+ const LABEL_BLOCKED: Record<ButtonAct, string> = {
50
+ primary: "text-ink-meta",
51
+ danger: "text-ink-meta",
52
+ secondary: "text-ink-disabled",
53
+ destructive: "text-ink-disabled",
54
+ quiet: "text-ink-disabled",
55
+ };
56
+
57
+ // Pending and blocked both set aria-disabled, so one look is chosen: pending
58
+ // over blocked, and neither takes the press. A pending act keeps its rest box
59
+ // until the delay has run, then the fill layer fades over it.
60
+ function lookOf(kind: ButtonAct, pending: boolean, muted: boolean): string {
61
+ if (pending) return "";
62
+ if (muted) return BLOCKED[kind];
63
+ return PRESS[kind];
64
+ }
65
+
66
+ /** The act every Button renders; it holds its own attempt: inert and `aria-busy` at the press, the pending look after `tuned.actDelay`, a rejection drawn in a failed toast with Retry. `painted` is the act while its data is not here: its box filled, its content not drawn, inert. `pending` is a host's state handed down: the host holds the run, so a press calls the handler as it is and the act holds none of its own. `line` draws a rejection in a reason line under the act instead (the public Button standing alone). The props a Base UI trigger hands through its `render` (a popup's trigger) reach the button, its own press after them. Outside the package's exports. */
67
+ export function ButtonBase({
68
+ act,
69
+ fit,
70
+ icon,
71
+ label,
72
+ count,
73
+ wait,
74
+ onAct,
75
+ confirm,
76
+ done,
77
+ to,
78
+ sheet,
79
+ blocked,
80
+ painted,
81
+ pending: given,
82
+ line,
83
+ tabIndex,
84
+ onClick,
85
+ ...handed
86
+ }: Omit<ButtonAttemptProps, "href" | "glyph" | "fit"> &
87
+ Handed & {
88
+ fit?: ButtonFit;
89
+ painted?: boolean;
90
+ pending?: boolean;
91
+ line?: boolean;
92
+ /** `-1` where the act's host holds the tab stop (a tree's row); absent, the act keeps Base UI's own. */
93
+ tabIndex?: -1;
94
+ }) {
95
+ const kind = act ?? "primary";
96
+ const muted = !painted && blocked !== undefined;
97
+ const { touched } = useTouched();
98
+ const host = use(ReasonHostContext);
99
+ const submits = use(SubmitContext);
100
+ // A host with a line of its own draws a rejection there; the public Button
101
+ // alone draws it under itself.
102
+ const acting = useAct(line && !host ? "line" : "toast");
103
+ const pending = given === true || acting.pending !== undefined;
104
+ // Inert beside a pending act: the blocked look and no press, no reason.
105
+ const waiting = wait !== undefined && wait > 0;
106
+ const inert = (use(ActInert) || waiting) && !pending;
107
+ const [pressed, keep] = usePressed(blocked);
108
+ const said = muted && (pressed || touched);
109
+ const look = painted ? PAINT_CONTROL : lookOf(kind, pending, muted || inert);
110
+ const labelLook = pending
111
+ ? FADE_OUT
112
+ : (muted || inert) && LABEL_BLOCKED[kind];
113
+ const press = () => {
114
+ if (inert || pending) return;
115
+ if (muted) {
116
+ if (host) host();
117
+ else keep();
118
+ } else if (given === undefined)
119
+ acting.attempt(true, {
120
+ onAct: () => onAct?.(),
121
+ label,
122
+ destructive: kind === "destructive" || kind === "danger",
123
+ confirm,
124
+ done,
125
+ to,
126
+ sheet,
127
+ });
128
+ else onAct?.();
129
+ };
130
+ // Blocked is not Base UI's `disabled`, which swallows the press that shows
131
+ // the reason: aria-disabled is set by hand, and the caller's props win the merge.
132
+ const face = (
133
+ <BaseButton
134
+ {...handed}
135
+ disabled={pending}
136
+ focusableWhenDisabled
137
+ type={submits ? "submit" : "button"}
138
+ aria-disabled={pending || muted || inert || undefined}
139
+ aria-busy={pending || undefined}
140
+ inert={painted || undefined}
141
+ {...(tabIndex === undefined ? {} : { tabIndex })}
142
+ onClick={(event) => {
143
+ onClick?.(event);
144
+ endSubmit(submits, event);
145
+ press();
146
+ }}
147
+ className={cn(button({ act: kind, fit }), BOX, look)}
148
+ >
149
+ {icon ? (
150
+ <span className={cn(GLYPH, pending && FADE_OUT, painted && HIDDEN)}>
151
+ <Icon name={icon} fit="control" />
152
+ </span>
153
+ ) : null}
154
+ <span
155
+ className={cn(
156
+ buttonLabel({ act: kind }),
157
+ LABEL,
158
+ labelLook,
159
+ painted && HIDDEN,
160
+ )}
161
+ >
162
+ {label}
163
+ </span>
164
+ {wait !== undefined ? (
165
+ <span
166
+ className={cn(
167
+ GLYPH,
168
+ !waiting && PENDING,
169
+ pending && FADE_OUT,
170
+ painted && HIDDEN,
171
+ )}
172
+ >
173
+ <CountBase value={wait} inAct />
174
+ </span>
175
+ ) : count !== undefined ? (
176
+ <span className={cn(GLYPH, pending && FADE_OUT, painted && HIDDEN)}>
177
+ <CountBase value={count} inAct />
178
+ </span>
179
+ ) : null}
180
+ {pending ? (
181
+ <span className={cn(SPINNER_LAYER, FILL_PENDING[kind], FADE_IN)}>
182
+ <Spinner />
183
+ </span>
184
+ ) : null}
185
+ </BaseButton>
186
+ );
187
+ // A host draws the reason, and a failure, on its own line. A blocked act's
188
+ // reason stands before a failure; paused is the wait for a connection, not
189
+ // a failure.
190
+ if (host) return face;
191
+ if (muted) {
192
+ return (
193
+ <div className={STACK}>
194
+ {face}
195
+ <Reason shown={said}>{blocked}</Reason>
196
+ </div>
197
+ );
198
+ }
199
+ if (!line) return face;
200
+ // The stack stands from the first render, so the failure's line arriving
201
+ // never remounts the act it was pressed on (and its focus with it).
202
+ const under = acting.line;
203
+ return (
204
+ <div className={STACK}>
205
+ {face}
206
+ <Reason
207
+ shown={under !== undefined}
208
+ failed={acting.holds || acting.pending === undefined}
209
+ >
210
+ {under ?? ""}
211
+ </Reason>
212
+ </div>
213
+ );
214
+ }
@@ -0,0 +1,84 @@
1
+ import type {
2
+ IconLinkAct,
3
+ IconName,
4
+ LinkAct,
5
+ } from "@slotform/ui-core/descriptors";
6
+ import type { ButtonAct, ButtonFit } from "@slotform/ui-core/variants";
7
+ import { IconButtonLink } from "../../atoms/button/glyph.tsx";
8
+ import { ButtonLink } from "../../atoms/button/link.tsx";
9
+ import { type Act, type IconAct, wiringOf } from "../../lib/act.ts";
10
+ import { ButtonBase } from "./base.tsx";
11
+ import { AttemptGlyph } from "./index.tsx";
12
+
13
+ /** A labelled act as its host draws it: a Button that runs an `Act`, or the anchor that goes to a `LinkAct`'s route, in the same look. `kind` is the look a host gives the act (a `destructive` act draws as `destructive` where the host asks `secondary`). `blocked` is the host's reason where it holds one apart from the act's own (a read that ended); a link draws inert with its own reason, as a blocked act does, and the host's does not stop it. Outside the package's exports. */
14
+ export function ActFace(props: {
15
+ act: Act | LinkAct;
16
+ kind: ButtonAct;
17
+ fit?: ButtonFit;
18
+ icon?: IconName;
19
+ blocked?: string;
20
+ tabIndex?: -1;
21
+ }) {
22
+ const { act, kind, fit, icon, blocked, tabIndex } = props;
23
+ // An act runs its `onAct` or opens its `sheet`, so whatever is no link
24
+ // hands its wiring on, a sheet with it.
25
+ const own = "href" in act ? undefined : act;
26
+ if ("href" in act && act.blocked === undefined)
27
+ return (
28
+ <ButtonLink
29
+ act={kind}
30
+ fit={fit}
31
+ icon={icon}
32
+ label={act.label}
33
+ href={act.href}
34
+ tabIndex={tabIndex}
35
+ />
36
+ );
37
+ return (
38
+ <ButtonBase
39
+ act={
40
+ kind === "secondary" && "destructive" in act && act.destructive
41
+ ? "destructive"
42
+ : kind
43
+ }
44
+ fit={fit}
45
+ icon={icon}
46
+ label={act.label}
47
+ onAct={own?.onAct}
48
+ {...(own ? wiringOf(own) : {})}
49
+ blocked={own ? (blocked ?? own.blocked) : act.blocked}
50
+ tabIndex={tabIndex}
51
+ />
52
+ );
53
+ }
54
+
55
+ /** An icon act as its host draws it: the glyph that runs an `IconAct`, or the one that goes to an `IconLinkAct`'s route; a blocked link is inert, as a blocked act is, and gives its reason. Outside the package's exports. */
56
+ export function IconActFace(props: {
57
+ act: IconAct | IconLinkAct;
58
+ tabIndex?: -1;
59
+ }) {
60
+ const { act, tabIndex } = props;
61
+ if ("href" in act && act.blocked === undefined) {
62
+ return (
63
+ <IconButtonLink
64
+ icon={act.icon}
65
+ label={act.label}
66
+ href={act.href}
67
+ tabIndex={tabIndex}
68
+ />
69
+ );
70
+ }
71
+ // An act that opens a sheet has no `onAct`: its sheet is its wiring.
72
+ const own = "href" in act ? undefined : act;
73
+ return (
74
+ <AttemptGlyph
75
+ tabIndex={tabIndex}
76
+ icon={act.icon}
77
+ label={act.label}
78
+ act={own?.destructive ? "destructive" : undefined}
79
+ blocked={act.blocked}
80
+ onAct={own?.onAct}
81
+ {...(own ? wiringOf(own) : {})}
82
+ />
83
+ );
84
+ }
@@ -0,0 +1,206 @@
1
+ import { cn } from "@slotform/ui-core/cn";
2
+ import type { Decision, IconName } from "@slotform/ui-core/descriptors";
3
+ import { ReasonHostContext } from "@slotform/ui-core/react/reason";
4
+ import {
5
+ type ButtonAct,
6
+ type ButtonFit,
7
+ link,
8
+ } from "@slotform/ui-core/variants";
9
+ import { use } from "react";
10
+ import { IconButtonBase, IconButtonLink } from "../../atoms/button/glyph.tsx";
11
+ import { ButtonLink, TEXT_PRESS } from "../../atoms/button/link.tsx";
12
+ import { type ActSheetProps, useAct } from "../../lib/act.ts";
13
+ import type { Closed } from "../../lib/closed.ts";
14
+ import { ButtonBase } from "./base.tsx";
15
+
16
+ interface Named extends Closed {
17
+ /** The act's accessible name and, in the labelled forms, its visible text (a short phrase; truncates). In the icon form it is read aloud and shown in a tooltip, never drawn. */
18
+ label: string;
19
+ }
20
+
21
+ /** A labelled act that runs. */
22
+ export interface ButtonAttemptProps extends Named {
23
+ /** The act's kind: the accent fill (`primary`, the default), the danger fill, a hairline, the hairline in danger ink, or quiet words in the meta ink. */
24
+ act?: ButtonAct;
25
+ /** What it sits in: a body (the default), full width under a field, or `inline`, inside a sentence after its caption ("Didn't get the code? Resend"): its words in the accent ink, underlined, in the sentence's type; a rejection raises a failed toast, and blocked it stands inert in the meta ink, the sentence saying why. */
26
+ fit?: ButtonFit | "inline";
27
+ /** A glyph before the label, in the label's ink. */
28
+ icon?: IconName;
29
+ /** A number after the label, in the label's ink. */
30
+ count?: number;
31
+ /** A wait, in seconds left: the act is inert while it is above zero, its count drawn, and it draws no reason, so its row never grows. At zero the count's region stays, hidden, so the act keeps its width. */
32
+ wait?: number;
33
+ /** Runs the act. A promise it returns holds the act pending until it settles: inert at the press, then (after `tuned.actDelay`) its glyph and label hidden under a spinner, its name kept. A rejection reads under the act. */
34
+ onAct?: () => unknown;
35
+ /** Asked before `onAct` runs, as a decision over the page: declined, nothing runs. Its act carries this act's label. */
36
+ confirm?: Decision;
37
+ /** Toasted once `onAct` resolves (a sentence). */
38
+ done?: string;
39
+ /** The route gone to once `onAct` resolves, after `done`. */
40
+ to?: string;
41
+ /** The sheet a press opens, in place of running `onAct` (exclusive with it): open from the press until it is dismissed or its `submit` has resolved. */
42
+ sheet?: ActSheetProps;
43
+ /** Why the act cannot run (a sentence; wraps): it is inert, and shows this under itself once pressed or once its form or sheet is touched. */
44
+ blocked?: string;
45
+ href?: undefined;
46
+ glyph?: undefined;
47
+ }
48
+
49
+ /** The icon form that runs: a square act with no boundary at rest. */
50
+ export interface ButtonGlyphProps extends Named {
51
+ /** `quiet` (the default) draws the glyph in the meta ink, `destructive` in the danger ink (an act that removes or ends something), `primary` on the accent fill (the act its bar is for). */
52
+ act?: "quiet" | "destructive" | "primary";
53
+ /** What it sits in: a body (the default), or a field's end. */
54
+ fit?: ButtonFit;
55
+ /** The glyph. */
56
+ icon: IconName;
57
+ /** Draws the glyph alone, the label its tooltip and accessible name. */
58
+ glyph: true;
59
+ /** Runs the act. A promise it returns holds the act pending until it settles: inert at the press, then (after `tuned.actDelay`) its glyph swapped for a spinner, its size and name kept. A rejection raises a failed toast with Retry. */
60
+ onAct?: () => unknown;
61
+ /** Asked before `onAct` runs, as a decision over the page: declined, nothing runs. */
62
+ confirm?: Decision;
63
+ /** Toasted once `onAct` resolves (a sentence). */
64
+ done?: string;
65
+ /** The route gone to once `onAct` resolves, after `done`. */
66
+ to?: string;
67
+ /** The sheet a press opens, in place of running `onAct`. */
68
+ sheet?: ActSheetProps;
69
+ /** Why the act cannot run: it stands inert (its holder draws the reason). */
70
+ blocked?: string;
71
+ href?: undefined;
72
+ }
73
+
74
+ /** The link form: an anchor to a route or an external URL, which runs nothing, so it never pends and is never blocked. */
75
+ export interface ButtonRouteProps extends Named {
76
+ /** Without an `act` the anchor is accent ink in the type of the line it sits in; with one, it takes that act's look. */
77
+ act?: ButtonAct;
78
+ /** On its own at the target height (the default), or `inline`, inside a line of text and underlined at rest (the accent ink alone). */
79
+ fit?: ButtonFit | "inline";
80
+ /** A glyph before the label, in an act's look. */
81
+ icon?: IconName;
82
+ /** Where it goes: a route of the app or an external URL. */
83
+ href: string;
84
+ glyph?: undefined;
85
+ }
86
+
87
+ /** The link form drawn as an icon. */
88
+ export interface ButtonRouteGlyphProps extends Named {
89
+ fit?: ButtonFit;
90
+ icon: IconName;
91
+ glyph: true;
92
+ href: string;
93
+ }
94
+
95
+ export type ButtonProps =
96
+ | ButtonAttemptProps
97
+ | ButtonGlyphProps
98
+ | ButtonRouteProps
99
+ | ButtonRouteGlyphProps;
100
+
101
+ /** An act: a labelled one that runs (it holds its own attempt, and draws a rejection in a line under itself), the same with an `href` as a link, or with `glyph` as an icon alone. Pending and blocked acts keep focus and ignore the press. */
102
+ export function Button(props: ButtonProps) {
103
+ if (props.href !== undefined)
104
+ return props.glyph ? (
105
+ <IconButtonLink
106
+ icon={props.icon}
107
+ fit={props.fit}
108
+ label={props.label}
109
+ href={props.href}
110
+ />
111
+ ) : (
112
+ <ButtonLink
113
+ act={props.act}
114
+ fit={props.fit}
115
+ icon={props.icon}
116
+ label={props.label}
117
+ href={props.href}
118
+ />
119
+ );
120
+ if (props.glyph) return <AttemptGlyph {...props} />;
121
+ if (props.fit === "inline") return <AttemptInline {...props} />;
122
+ return (
123
+ <ButtonBase
124
+ act={props.act}
125
+ fit={props.fit}
126
+ icon={props.icon}
127
+ label={props.label}
128
+ count={props.count}
129
+ wait={props.wait}
130
+ onAct={props.onAct}
131
+ confirm={props.confirm}
132
+ done={props.done}
133
+ to={props.to}
134
+ sheet={props.sheet}
135
+ blocked={props.blocked}
136
+ line
137
+ />
138
+ );
139
+ }
140
+
141
+ // The inline form's words take the meta ink while they cannot run.
142
+ const INLINE_INERT =
143
+ "aria-disabled:text-ink-meta aria-disabled:decoration-transparent";
144
+
145
+ // The inline form that runs, holding its own attempt: inert and `aria-busy` while
146
+ // it pends, a rejection raised as a failed toast.
147
+ function AttemptInline(props: ButtonAttemptProps) {
148
+ const { label, blocked, onAct, confirm, done, to, sheet } = props;
149
+ const acting = useAct("toast");
150
+ const pending = acting.pending !== undefined;
151
+ const inert = blocked !== undefined || pending;
152
+ const run = () =>
153
+ acting.attempt(true, { onAct, label, confirm, done, to, sheet });
154
+ return (
155
+ <button
156
+ type="button"
157
+ aria-busy={pending || undefined}
158
+ aria-disabled={inert || undefined}
159
+ onClick={inert ? undefined : run}
160
+ className={cn(link({ fit: "inline" }), TEXT_PRESS.inline, INLINE_INERT)}
161
+ >
162
+ {label}
163
+ </button>
164
+ );
165
+ }
166
+
167
+ /** The icon form that runs, holding its own attempt: a rejection raises a failed toast. A host whose rows stand in one Tab stop (a grid) hands it `tabIndex={-1}`. Outside the package's exports. */
168
+ export function AttemptGlyph({
169
+ act,
170
+ fit,
171
+ icon,
172
+ label,
173
+ blocked,
174
+ onAct,
175
+ tabIndex,
176
+ ...wiring
177
+ }: Omit<ButtonGlyphProps, "glyph"> & { tabIndex?: -1 }) {
178
+ const acting = useAct("toast");
179
+ // Under a host that draws a blocked act's reason (a Section's head, a
180
+ // row's acts), a blocked press is handed to it; with none the act is inert.
181
+ const host = use(ReasonHostContext);
182
+ const held = blocked !== undefined && host !== undefined;
183
+ return (
184
+ <IconButtonBase
185
+ icon={icon}
186
+ fit={fit}
187
+ label={label}
188
+ destructive={act === "destructive"}
189
+ primary={act === "primary"}
190
+ disabled={blocked !== undefined && !held}
191
+ blocked={held || undefined}
192
+ pending={acting.pending !== undefined}
193
+ tabIndex={tabIndex}
194
+ onClick={() =>
195
+ held
196
+ ? host()
197
+ : acting.attempt(true, {
198
+ onAct,
199
+ label,
200
+ destructive: act === "destructive",
201
+ ...wiring,
202
+ })
203
+ }
204
+ />
205
+ );
206
+ }
@@ -0,0 +1,26 @@
1
+ import type { CanvasPoint } from "@slotform/ui-core/descriptors";
2
+ import { Stroke, SVG } from "./edges.tsx";
3
+ import { type Box, bendRoute, cleanPoints, roundedPath } from "./geometry.ts";
4
+
5
+ // The link being drawn from a node's out port to the pointer, in the layer's
6
+ // flow coordinates: an edge's own stroke, in the rest ink. Dashed would say
7
+ // handoff, and no tone says whether the port beneath the pointer takes it.
8
+ export function ConnectionLine({
9
+ from,
10
+ to,
11
+ pair,
12
+ }: {
13
+ from: Box;
14
+ to: CanvasPoint;
15
+ pair: number;
16
+ }) {
17
+ const source = { x: from.x + from.width / 2, y: from.y + from.height };
18
+ return (
19
+ <svg aria-hidden="true" data-link className={SVG}>
20
+ <Stroke
21
+ path={roundedPath(cleanPoints(bendRoute(source, to, pair)), pair)}
22
+ dashed={false}
23
+ />
24
+ </svg>
25
+ );
26
+ }
@@ -0,0 +1,116 @@
1
+ import { cn } from "@slotform/ui-core/cn";
2
+ import type { CanvasEdge } from "@slotform/ui-core/descriptors";
3
+ import { PATH_TONE } from "@slotform/ui-core/variants";
4
+ import { useId } from "react";
5
+ import {
6
+ ARROW,
7
+ ARROW_REF,
8
+ crisp,
9
+ type Route,
10
+ roundedPath,
11
+ } from "./geometry.ts";
12
+ import { EdgeLabel } from "./label.tsx";
13
+ import type { EdgeTone } from "./look.ts";
14
+
15
+ export const SVG = "absolute left-0 top-0 overflow-visible pointer-events-none";
16
+ const INK = "text-edge-strong";
17
+ // The dot grid's ink: `edge` is fainter than the grid and `ink-disabled` stands
18
+ // within 0.05 of lightness of `edge-strong`, so neither tells a dimmed edge.
19
+ const DIM = "text-grid";
20
+ // Dashed means a handoff, and only that.
21
+ const HANDOFF_DASH = "4 4";
22
+
23
+ // A line and its arrowhead. A marker takes its colour from where it is
24
+ // defined, so each stroke has its own inside its `g`, and a tone on the group
25
+ // reaches the line and the head together. An edge names itself with `edge`;
26
+ // the line being drawn has none.
27
+ export function Stroke({
28
+ path,
29
+ dashed,
30
+ tone = "rest",
31
+ edge,
32
+ }: {
33
+ path: string;
34
+ dashed: boolean;
35
+ tone?: EdgeTone;
36
+ edge?: string;
37
+ }) {
38
+ const marker = useId();
39
+ return (
40
+ <g
41
+ data-edge={edge}
42
+ className={cn(tone === "dimmed" ? DIM : INK, PATH_TONE)}
43
+ >
44
+ <marker
45
+ id={marker}
46
+ markerWidth={ARROW}
47
+ markerHeight={ARROW}
48
+ refX={ARROW_REF}
49
+ refY={ARROW / 2}
50
+ orient="auto"
51
+ >
52
+ <path
53
+ d={`M0 0 L${ARROW} ${ARROW / 2} L0 ${ARROW} Z`}
54
+ fill="currentColor"
55
+ />
56
+ </marker>
57
+ <path
58
+ d={path}
59
+ fill="none"
60
+ stroke="currentColor"
61
+ strokeDasharray={dashed ? HANDOFF_DASH : undefined}
62
+ markerEnd={`url(#${marker})`}
63
+ />
64
+ </g>
65
+ );
66
+ }
67
+
68
+ // Every edge as one SVG in flow coordinates, then the chips over it. Nothing
69
+ // here decides a coordinate: the router did.
70
+ export function EdgeLayer({
71
+ edges,
72
+ routes,
73
+ tones,
74
+ radius,
75
+ below,
76
+ }: {
77
+ edges: readonly CanvasEdge[];
78
+ routes: ReadonlyMap<string, Route>;
79
+ // Each edge's tone, by id.
80
+ tones: ReadonlyMap<string, EdgeTone>;
81
+ radius: number;
82
+ // Under the text floor the chips draw nothing.
83
+ below: boolean;
84
+ }) {
85
+ return (
86
+ <>
87
+ <svg aria-hidden="true" className={SVG}>
88
+ {edges.map((edge) => {
89
+ const route = routes.get(edge.id);
90
+ return route ? (
91
+ <Stroke
92
+ key={edge.id}
93
+ edge={edge.id}
94
+ path={roundedPath(crisp(route.points), radius)}
95
+ dashed={edge.handoff ?? false}
96
+ tone={tones.get(edge.id) ?? "rest"}
97
+ />
98
+ ) : null;
99
+ })}
100
+ </svg>
101
+ {edges.map((edge) => {
102
+ const at = routes.get(edge.id)?.label;
103
+ return at ? (
104
+ <EdgeLabel
105
+ key={edge.id}
106
+ label={edge.label}
107
+ handoff={edge.handoff ?? false}
108
+ tone={tones.get(edge.id) ?? "rest"}
109
+ at={at}
110
+ below={below}
111
+ />
112
+ ) : null;
113
+ })}
114
+ </>
115
+ );
116
+ }