@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.
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,79 @@
1
+ import { afterRun } from "@slotform/ui-core/acts";
2
+ import {
3
+ type ConfirmEntry,
4
+ dismissConfirmation,
5
+ useConfirmations,
6
+ } from "@slotform/ui-core/react/confirm";
7
+ import { useWords } from "@slotform/ui-core/react/words";
8
+ import { useState } from "react";
9
+ import { FormField } from "../form-field/index.tsx";
10
+ import { Input } from "../input/index.tsx";
11
+ import { SheetBase } from "./base.tsx";
12
+
13
+ /** One decision: centred on the desktop, a bottom sheet on touch, the sentence under the title and the act after the way out, Cancel unless the decision names it (a destructive act the danger fill). The act runs the work: pending while its promise pends, the sheet's other acts and its dismissal inert; the sheet closes when it resolves (at once for an act that returns nothing) and stays open, the act ready again and its sentence in the bar's line, when it rejects. A decision that asks for a name draws its field over the acts, the act blocked on its reason until the name typed matches. Outside the package's exports: the Shell draws the queue's first. */
14
+ export function ConfirmSheet(props: {
15
+ entry: ConfirmEntry;
16
+ open: boolean;
17
+ onDone: () => void;
18
+ }) {
19
+ const { entry, open, onDone } = props;
20
+ const [typed, setTyped] = useState("");
21
+ // A new decision starts from an empty field and a ready act, reset during
22
+ // render; a sheet that is leaving keeps its decision's state until it is gone.
23
+ const [decision, setDecision] = useState(entry.id);
24
+ if (decision !== entry.id) {
25
+ setDecision(entry.id);
26
+ setTyped("");
27
+ }
28
+ // The sheet's bar holds the act's attempt: a rejection stays in the bar's line,
29
+ // the sheet open and the act ready; an act that returns no promise is done
30
+ // at once.
31
+ const run = () =>
32
+ afterRun(entry.act.onAct, (failed) => {
33
+ if (!failed) onDone();
34
+ });
35
+ const words = useWords();
36
+ const name = entry.confirmName;
37
+ const blocked = name && typed !== name.value ? name.blocked : undefined;
38
+ return (
39
+ <SheetBase
40
+ centred
41
+ open={open}
42
+ onClose={onDone}
43
+ focus={name ? "field" : undefined}
44
+ title={entry.title}
45
+ description={entry.sentence}
46
+ acts={[
47
+ { label: entry.cancel ?? words.cancel, onAct: onDone },
48
+ {
49
+ label: entry.act.label,
50
+ destructive: entry.act.destructive,
51
+ blocked,
52
+ onAct: run,
53
+ },
54
+ ]}
55
+ >
56
+ {name ? (
57
+ <FormField label={name.label}>
58
+ <Input label={name.label} value={typed} onChange={setTyped} />
59
+ </FormField>
60
+ ) : null}
61
+ </SheetBase>
62
+ );
63
+ }
64
+
65
+ /** The first queued decision (queued by `confirm` and `ask`, `@slotform/ui-core/react/confirm`); the last one stays drawn while its sheet closes. */
66
+ export function Confirmations() {
67
+ const current = useConfirmations()[0];
68
+ const [last, setLast] = useState(current);
69
+ if (current && current !== last) setLast(current);
70
+ const shown = current ?? last;
71
+ if (!shown) return null;
72
+ return (
73
+ <ConfirmSheet
74
+ entry={shown}
75
+ open={current !== undefined}
76
+ onDone={() => dismissConfirmation(shown.id)}
77
+ />
78
+ );
79
+ }
@@ -0,0 +1,218 @@
1
+ import { cn } from "@slotform/ui-core/cn";
2
+ import type { ProcedureCall } from "@slotform/ui-core/form";
3
+ import { BACK_GLYPH } from "@slotform/ui-core/list-state";
4
+ import {
5
+ TouchedContext,
6
+ usePageTurn,
7
+ useTouchState,
8
+ } from "@slotform/ui-core/react/touched";
9
+ import { useWords } from "@slotform/ui-core/react/words";
10
+ import { dockedBodyMax } from "@slotform/ui-core/tokens";
11
+ import {
12
+ BLOCK_IN,
13
+ DOCKED_FLOOR_ROWS,
14
+ lineBox,
15
+ SHEET_DOCKED_BODY,
16
+ SHEET_DOCKED_FLOOR,
17
+ SHEET_DOCKED_FOOT,
18
+ SHEET_DOCKED_HEAD,
19
+ SHEET_HEAD_ROW,
20
+ text,
21
+ } from "@slotform/ui-core/variants";
22
+ import {
23
+ type ReactNode,
24
+ useEffect,
25
+ useId,
26
+ useLayoutEffect,
27
+ useRef,
28
+ useState,
29
+ } from "react";
30
+ import { DIVIDER } from "../../atoms/section/card.tsx";
31
+ import type { FootRegionValue } from "../../lib/container.ts";
32
+ import { FIELDS, focusFirst } from "../../lib/focus.ts";
33
+ import { useScrolls } from "../../lib/scrolls.ts";
34
+ import { Scroller, useScroller } from "../../lib/window.tsx";
35
+ import { ActionBarBase } from "../action-bar/base.tsx";
36
+ import { Button } from "../button/index.tsx";
37
+ import type { FormProps } from "../form/index.tsx";
38
+ import { type SheetSubmit, submitAct } from "./base.tsx";
39
+ import { useSheetForm } from "./form.tsx";
40
+
41
+ // The sheet fills its foot: the head and the foot keep their height and the
42
+ // body, bounded below, scrolls in what is left. The foot centres what it holds,
43
+ // so the sheet spans it.
44
+ const ROOT = "flex flex-col w-full min-h-0";
45
+ const HEAD = "flex items-start shrink-0";
46
+ const HEAD_MAIN = "flex flex-col grow min-w-0";
47
+ // The back and close acts stand at the title's first line: each in a box one
48
+ // heading line tall, centred on the line; a taller act overflows it centred.
49
+ const FIRST_LINE = "flex shrink-0 items-center h-lh";
50
+ const TITLE = "min-w-0";
51
+ // The body takes a tab stop only while it scrolls with nothing tabbable inside.
52
+ // Its three-row floor is on the content it scrolls, so the body itself yields
53
+ // below it where the region is short.
54
+ const BODY =
55
+ "min-h-0 overflow-y-auto overscroll-contain focus-visible:-outline-offset-2";
56
+ const CONTENT = "flex flex-col";
57
+ const FOOT = "shrink-0";
58
+ const FOOT_ROW =
59
+ "flex items-center justify-end touch:flex-col touch:items-stretch";
60
+ // On the desktop the sheet stands within the thread's column, as the field does.
61
+ const COLUMN = "max-w-measure touch:max-w-none";
62
+
63
+ /** What a docked `Sheet` draws: the public `Sheet`'s props, standing in a foot, and the foot's measured `region`. Outside the package's exports: a `Pane` and a `Thread` draw it for their `sheet`. */
64
+ interface SheetDockedProps<P extends ProcedureCall = ProcedureCall> {
65
+ open: boolean;
66
+ onClose: () => void;
67
+ title: string;
68
+ description?: string;
69
+ back?: () => void;
70
+ submit?: SheetSubmit;
71
+ form?: FormProps<P>;
72
+ /** The foot's region, which bounds the body. */
73
+ region: FootRegionValue;
74
+ /** The body's parts, ahead of the `form`. */
75
+ children?: ReactNode;
76
+ }
77
+
78
+ /** A `Sheet` a Thread or a Pane draws in its foot: no scrim, portal or dialog, the foot's raised cell its surface. The head holds the back act before one column, the title over the description, with the acts at the title's first line; the body scrolls between the head and the foot, which hold their height; the foot holds the submit, and under it one kept line for a blocked reason or a failed run's sentence. Escape closes it, and each page opens at its top with focus in its first field. Closed it draws nothing. */
79
+ export function SheetDocked<P extends ProcedureCall>({
80
+ open,
81
+ onClose,
82
+ title,
83
+ description,
84
+ back,
85
+ submit,
86
+ form,
87
+ region,
88
+ children,
89
+ }: SheetDockedProps<P>) {
90
+ // The sheet docks as a block: it fades in on `base` and the body above takes
91
+ // its new height; closing it runs in the page's block move, so it fades out on
92
+ // `fast` as the body takes the room back.
93
+ const { acting, fields } = useSheetForm(form, open, []);
94
+ const words = useWords();
95
+ const titleId = useId();
96
+ const root = useRef<HTMLElement>(null);
97
+ const scroll = useScroller();
98
+ const body = scroll.node;
99
+ // What the sheet pins besides its body (its head and foot) and the body's
100
+ // floor, measured off the sheet.
101
+ const [pinned, setPinned] = useState({ parts: 0, floor: 0 });
102
+ useScrolls(body);
103
+ const [touchedValue, setTouched] = useTouchState();
104
+ const page = usePageTurn(open, title, description, () => setTouched(false));
105
+ useLayoutEffect(() => {
106
+ const sheet = root.current;
107
+ if (!sheet || !body) return;
108
+ const measure = () => {
109
+ const parts = Math.round(
110
+ sheet.getBoundingClientRect().height -
111
+ body.getBoundingClientRect().height,
112
+ );
113
+ const floor =
114
+ DOCKED_FLOOR_ROWS *
115
+ Number.parseFloat(
116
+ getComputedStyle(sheet).getPropertyValue("--spacing-row"),
117
+ );
118
+ setPinned((last) =>
119
+ last.parts === parts && last.floor === floor ? last : { parts, floor },
120
+ );
121
+ };
122
+ measure();
123
+ const resize = new ResizeObserver(measure);
124
+ resize.observe(sheet);
125
+ resize.observe(body);
126
+ return () => resize.disconnect();
127
+ }, [body]);
128
+ // Each page takes focus in its first field, else its first tabbable, once
129
+ // it has settled (a radio group sets its tab stop after the commit, and no
130
+ // event says it has), whatever held it: an act that relabels or leaves
131
+ // drops focus to the document, which a page with nothing tabbable gives to
132
+ // the sheet's first one.
133
+ useEffect(() => {
134
+ if (!open || !body) return;
135
+ const frame = requestAnimationFrame(() => {
136
+ if (!focusFirst(body, FIELDS)) focusFirst(body);
137
+ if (document.activeElement === document.body) focusFirst(root.current);
138
+ });
139
+ return () => cancelAnimationFrame(frame);
140
+ }, [open, page, body]);
141
+ if (!open) return null;
142
+ const maxHeight =
143
+ region.height > 0
144
+ ? dockedBodyMax({
145
+ region: region.height,
146
+ pinned: region.chrome + pinned.parts,
147
+ floor: pinned.floor,
148
+ logFloor: region.logFloor,
149
+ })
150
+ : undefined;
151
+ // A submit that acknowledges closes the sheet.
152
+ const bar = submit ? (
153
+ <ActionBarBase acts={[submitAct(submit, onClose)]} acting={acting} kept />
154
+ ) : null;
155
+ const close = () => {
156
+ if (!acting.holds) onClose();
157
+ };
158
+ return (
159
+ <TouchedContext value={touchedValue}>
160
+ <section
161
+ ref={root}
162
+ aria-labelledby={titleId}
163
+ onKeyDown={(event) => {
164
+ if (event.key !== "Escape") return;
165
+ event.stopPropagation();
166
+ close();
167
+ }}
168
+ // A field inside takes input: a blocked act says its reason.
169
+ onChange={touchedValue.touch}
170
+ className={cn(COLUMN, ROOT, BLOCK_IN)}
171
+ >
172
+ <div className={cn(SHEET_HEAD_ROW, HEAD)}>
173
+ {back ? (
174
+ <div className={cn(lineBox({ role: "heading" }), FIRST_LINE)}>
175
+ <Button glyph icon={BACK_GLYPH} label={words.back} onAct={back} />
176
+ </div>
177
+ ) : null}
178
+ <div className={cn(SHEET_DOCKED_HEAD, HEAD_MAIN)}>
179
+ <h2 id={titleId} className={cn(text({ role: "heading" }), TITLE)}>
180
+ {title}
181
+ </h2>
182
+ {description ? (
183
+ <p className={text({ role: "meta" })}>{description}</p>
184
+ ) : null}
185
+ </div>
186
+ <div className={cn(lineBox({ role: "heading" }), FIRST_LINE)}>
187
+ <Button glyph icon="X" label={words.close} onAct={close} />
188
+ </div>
189
+ </div>
190
+ {/* A new page is a new scroller, open at its top, not where the last one was scrolled to. */}
191
+ <div
192
+ key={page}
193
+ ref={scroll.ref}
194
+ style={maxHeight === undefined ? undefined : { maxHeight }}
195
+ className={BODY}
196
+ >
197
+ <div
198
+ className={cn(
199
+ CONTENT,
200
+ DIVIDER,
201
+ region.height > 0 && SHEET_DOCKED_FLOOR,
202
+ )}
203
+ >
204
+ <Scroller value={scroll}>
205
+ {children ? (
206
+ <div className={cn(SHEET_DOCKED_BODY, CONTENT)}>{children}</div>
207
+ ) : null}
208
+ {fields}
209
+ </Scroller>
210
+ </div>
211
+ </div>
212
+ {bar ? (
213
+ <div className={cn(SHEET_DOCKED_FOOT, FOOT, FOOT_ROW)}>{bar}</div>
214
+ ) : null}
215
+ </section>
216
+ </TouchedContext>
217
+ );
218
+ }
@@ -0,0 +1,76 @@
1
+ import { cn } from "@slotform/ui-core/cn";
2
+ import type { ProcedureCall } from "@slotform/ui-core/form";
3
+ import type { Acting } from "@slotform/ui-core/react/acts";
4
+ import { useFrame } from "@slotform/ui-core/react/read";
5
+ import { useTouched } from "@slotform/ui-core/react/touched";
6
+ import { FORM_FOOT, FORM_FOOT_STUCK, ROWS } from "@slotform/ui-core/variants";
7
+ import { type ReactNode, useState } from "react";
8
+ import { useAct } from "../../lib/act.ts";
9
+ import {
10
+ type FormFrameProps,
11
+ FormRows,
12
+ FormShell,
13
+ useFormBar,
14
+ } from "../form/base.tsx";
15
+ import { useDerivedForm } from "../form/derive.tsx";
16
+ import type { FormProps } from "../form/index.tsx";
17
+
18
+ /** A sheet's form, the modal and the docked one's: its rows flush on the sheet, its foot stuck to the body's. Outside the package's exports. */
19
+ function SheetForm(props: {
20
+ form: FormFrameProps;
21
+ /** The reads the bar paints under besides the form's own (the sheet's read, the ability the form is gated on). */
22
+ outer: readonly unknown[];
23
+ /** The sheet's run: one holder keeps the dismissal held while either the form's act or the sheet's runs. */
24
+ acting: Acting<number>;
25
+ }) {
26
+ const { form } = props;
27
+ // A sheet's form is the sheet's: its edit by value is the sheet's leave,
28
+ // which the sheet asks when it is closed, so the form asks nothing of its own.
29
+ const touch = useTouched();
30
+ const frame = useFrame(form.read);
31
+ const bar = useFormBar(form.bar, frame, props.outer, props.acting);
32
+ return (
33
+ <FormShell
34
+ frame={frame}
35
+ touch={touch}
36
+ guards={false}
37
+ edited={form.edited}
38
+ className={cn(ROWS)}
39
+ >
40
+ <FormRows
41
+ frame={frame}
42
+ groups={form.groups}
43
+ empty={form.empty}
44
+ after={form.after}
45
+ >
46
+ {form.children}
47
+ </FormRows>
48
+ {bar ? <div className={cn(FORM_FOOT, FORM_FOOT_STUCK)}>{bar}</div> : null}
49
+ </FormShell>
50
+ );
51
+ }
52
+
53
+ /** A sheet's form, the modal and the docked one's: the sheet's run, which its foot's act and its form's bar share (one act pends at a time, and the dismissal is held while it runs), and the form's rows, its edits dropped as the sheet opens again, on the render that sees it open. `outer`: the reads the bar paints under besides the form's own (the sheet's read). Outside the package's exports. */
54
+ export function useSheetForm<P extends ProcedureCall>(
55
+ form: FormProps<P> | undefined,
56
+ open: boolean,
57
+ outer: readonly unknown[],
58
+ ): { acting: Acting<number>; fields: ReactNode } {
59
+ const acting = useAct<number>("line");
60
+ const derived = useDerivedForm(form, false);
61
+ const [wasOpen, setWasOpen] = useState(open);
62
+ if (open !== wasOpen) {
63
+ setWasOpen(open);
64
+ if (open) derived.clear();
65
+ }
66
+ return {
67
+ acting,
68
+ fields: derived.frame ? (
69
+ <SheetForm
70
+ form={derived.frame}
71
+ acting={acting}
72
+ outer={[...outer, ...derived.outer]}
73
+ />
74
+ ) : undefined,
75
+ };
76
+ }
@@ -0,0 +1,120 @@
1
+ import { Dialog } from "@base-ui/react/dialog";
2
+ import { cn } from "@slotform/ui-core/cn";
3
+ import { BACK_GLYPH } from "@slotform/ui-core/list-state";
4
+ import type { Frame } from "@slotform/ui-core/react/read";
5
+ import { useWords } from "@slotform/ui-core/react/words";
6
+ import { SHEET_HEAD, SHEET_HEAD_ROW, text } from "@slotform/ui-core/variants";
7
+ import { use } from "react";
8
+ import { IconButtonBase } from "../../atoms/button/glyph.tsx";
9
+ import { useFollow } from "../../lib/follow.ts";
10
+ import { useTouch } from "../../lib/media.ts";
11
+ import { BusyMark, FrameLine } from "../../lib/read.tsx";
12
+ import { Button } from "../button/index.tsx";
13
+ import { SheetLayerContext } from "./layer.tsx";
14
+
15
+ // The head is where a bottom sheet is pulled down by a finger, so the browser
16
+ // leaves it the vertical axis.
17
+ const HEAD = "flex flex-col touch-none";
18
+ const HEAD_ROW = "flex items-center";
19
+ // The head is one line: the title truncates at its floor and the close act
20
+ // stands beside it, before it on touch.
21
+ const TITLE_BLOCK = "flex flex-col grow basis-0 min-w-0";
22
+ const TITLE_REGION = "flex items-center gap-gap min-w-0";
23
+ const TITLE = "min-w-0 truncate";
24
+ // The desktop head is a two-line row tall (the title over its description)
25
+ // whether or not the description stands; on touch the row is the acts'.
26
+ const HEAD_ROW_TALL = "py-gap touch:min-h-0";
27
+
28
+ /** A `SheetLayer`'s head: the title that names the layer over its description, the back act and the close act; on touch the close act leads unless back holds its place, the description stands under the row and a finger on the head pulls the sheet down. Outside the package's exports. */
29
+ export function SheetHead({
30
+ title,
31
+ description,
32
+ back,
33
+ frame,
34
+ centred,
35
+ close = true,
36
+ holds = false,
37
+ asks = false,
38
+ onClose,
39
+ }: {
40
+ title: string;
41
+ description?: string;
42
+ back?: () => void;
43
+ /** The sheet's frame, whose busy mark stands after the title and whose line under the head. */
44
+ frame?: Frame;
45
+ /** A decision's head on the desktop: the row is one line tall, and nothing pulls it. */
46
+ centred?: boolean;
47
+ /** The head draws its close act; a decision's acts dismiss it instead. */
48
+ close?: boolean;
49
+ /** An act runs: the close act is inert and the head does not follow a finger. */
50
+ holds?: boolean;
51
+ /** The sheet asks before it closes, so the head does not follow a finger. */
52
+ asks?: boolean;
53
+ /** Hears the sheet pulled away. */
54
+ onClose: () => void;
55
+ }) {
56
+ const touch = useTouch();
57
+ const words = useWords();
58
+ const { popup, titleId } = use(SheetLayerContext);
59
+ // A bottom sheet follows a finger on its head, 1:1, and leaves past the reach
60
+ // or flung; a held dismissal (an act running) and an edit keep it.
61
+ const pull = useFollow({
62
+ target: popup,
63
+ axis: "y",
64
+ away: 1,
65
+ enabled: touch && !centred && !holds && !asks,
66
+ onAway: onClose,
67
+ });
68
+ const closer = close ? (
69
+ <Dialog.Close
70
+ disabled={holds}
71
+ render={<IconButtonBase icon="X" label={words.close} />}
72
+ />
73
+ ) : null;
74
+ const lead = back ? (
75
+ <Button glyph icon={BACK_GLYPH} label={words.back} onAct={back} />
76
+ ) : null;
77
+ // On touch the close act leads the head unless back holds its place.
78
+ const start = touch ? (lead ?? closer) : lead;
79
+ const end = touch ? null : closer;
80
+ const titled = (
81
+ <h2 id={titleId} className={TITLE_REGION}>
82
+ <span className={cn(text({ role: "heading" }), TITLE)}>{title}</span>
83
+ {frame ? <BusyMark frame={frame} /> : null}
84
+ </h2>
85
+ );
86
+ const said = description ? (
87
+ <p className={text({ role: "meta" })}>{description}</p>
88
+ ) : null;
89
+ const line = frame ? <FrameLine frame={frame} /> : null;
90
+ const headRow = (
91
+ <div className={cn(SHEET_HEAD_ROW, HEAD_ROW, !centred && HEAD_ROW_TALL)}>
92
+ {start}
93
+ <div className={TITLE_BLOCK}>
94
+ {titled}
95
+ {touch ? null : said}
96
+ </div>
97
+ {end}
98
+ </div>
99
+ );
100
+ if (centred)
101
+ return (
102
+ <>
103
+ {headRow}
104
+ {line}
105
+ </>
106
+ );
107
+ return (
108
+ <div
109
+ onPointerDown={pull.onPointerDown}
110
+ onPointerMove={pull.onPointerMove}
111
+ onPointerUp={pull.onPointerUp}
112
+ onPointerCancel={pull.onPointerCancel}
113
+ className={cn(SHEET_HEAD, HEAD)}
114
+ >
115
+ {headRow}
116
+ {touch ? said : null}
117
+ {line}
118
+ </div>
119
+ );
120
+ }
@@ -0,0 +1,45 @@
1
+ import type { ProcedureCall } from "@slotform/ui-core/form";
2
+ import type { Selection } from "@slotform/ui-core/read";
3
+ import type { ReactNode } from "react";
4
+ import type { Closed } from "../../lib/closed.ts";
5
+ import type { Empty } from "../../lib/empty.tsx";
6
+ import type { FormProps } from "../form/index.tsx";
7
+ import type { SheetSubmit } from "./base.tsx";
8
+ import { TaskSheet } from "./task.tsx";
9
+
10
+ export type { Acknowledge, SheetSubmit } from "./base.tsx";
11
+
12
+ /** The sheet an act opens, or a `Pane`'s or a `Thread`'s docked one, over the procedure its form submits (`P`, read off the form's `act`, so `onDone` hears that procedure's output): a `Sheet`'s props but the two its holder owns, `open` and `onClose` (the sheet outlet, for an act's). */
13
+ export interface ActSheetProps<P extends ProcedureCall = ProcedureCall>
14
+ extends Closed {
15
+ /** The sheet's heading, which names it (a short phrase; wraps). */
16
+ title: string;
17
+ /** Under the title (a sentence; wraps). */
18
+ description?: string;
19
+ /** A second page's way back: the back act stands first in the head, on touch in the close act's place. */
20
+ back?: () => void;
21
+ /** The act that completes the task, in the foot after the body: after Cancel on the desktop, alone on touch. A promise its `onAct` returns keeps it pending until it settles. Given with no `onAct` (`{ label: "I saved them" }`) it acknowledges what the sheet shows: the press closes the sheet, and it stands alone, with no Cancel. */
22
+ submit?: SheetSubmit;
23
+ /** What the body holds, read once for the frame: while it waits the body's leaves paint and the submit with them, inert; its failure and a missing record stand in the body's place, the submit blocked with the failed sentence. A sheet starts with no holds, so its read draws its state here whatever the page under it holds. */
24
+ read?: Selection<unknown>;
25
+ /** The body's sentence when the `read`'s selection is empty. */
26
+ empty?: Empty;
27
+ /** A form the body ends with, a `Form`'s props (its procedure, its fields): its rows flush on the sheet after the body's parts, its bar stuck to the body's foot; the sheet asks "Discard your edit?" when it closes while the form stands edited (Escape, a press outside, the close act, Cancel), and the viewer's edits are dropped as it opens again. A bare control in the body (a `Picker`, an `Input` on the app's own value) asks nothing on close: its value is the app's, kept or dropped as the app decides. Give the form's submit or the sheet's `submit` as the act that completes the task, not both. */
28
+ form?: FormProps<P>;
29
+ /** The body's parts, ahead of the `form`, at the card inset. */
30
+ children?: ReactNode;
31
+ }
32
+
33
+ /** A task over the page. */
34
+ export interface SheetProps<P extends ProcedureCall = ProcedureCall>
35
+ extends ActSheetProps<P> {
36
+ /** The sheet is open. */
37
+ open: boolean;
38
+ /** Hears Escape, a press outside, the close act and Cancel, once an edited form has been discarded. */
39
+ onClose: () => void;
40
+ }
41
+
42
+ /** On the desktop a card centred across the scrim, its top a static inset under the viewport's top at every size, capped at the viewport less the page inset below it with its body scrolling, its head (the title over the description beside the close act) over the body and the foot; on touch a bottom sheet with the close act first and the submit in the foot after the body, a blocked submit's reason under the submit. A closing sheet draws what it last drew open, so its leave plays over that content whatever its holder clears as it closes. Always the modal one: a docked sheet is a `Pane`'s or a `Thread`'s `sheet`. */
43
+ export const Sheet: <P extends ProcedureCall>(
44
+ props: SheetProps<P>,
45
+ ) => ReactNode = TaskSheet;