@opsinjs/react 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 (266) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +114 -2
  4. package/dist/components/accordion.d.ts +82 -0
  5. package/dist/components/accordion.d.ts.map +1 -0
  6. package/dist/components/accordion.js +154 -0
  7. package/dist/components/accordion.js.map +1 -0
  8. package/dist/components/alert-banner.d.ts +291 -0
  9. package/dist/components/alert-banner.d.ts.map +1 -0
  10. package/dist/components/alert-banner.js +529 -0
  11. package/dist/components/alert-banner.js.map +1 -0
  12. package/dist/components/avatar.d.ts +45 -0
  13. package/dist/components/avatar.d.ts.map +1 -0
  14. package/dist/components/avatar.js +159 -0
  15. package/dist/components/avatar.js.map +1 -0
  16. package/dist/components/badge.d.ts +78 -0
  17. package/dist/components/badge.d.ts.map +1 -0
  18. package/dist/components/badge.js +32 -0
  19. package/dist/components/badge.js.map +1 -0
  20. package/dist/components/body-map.d.ts +51 -0
  21. package/dist/components/body-map.d.ts.map +1 -0
  22. package/dist/components/body-map.js +190 -0
  23. package/dist/components/body-map.js.map +1 -0
  24. package/dist/components/button.d.ts +260 -0
  25. package/dist/components/button.d.ts.map +1 -0
  26. package/dist/components/button.js +609 -0
  27. package/dist/components/button.js.map +1 -0
  28. package/dist/components/callout.d.ts +99 -0
  29. package/dist/components/callout.d.ts.map +1 -0
  30. package/dist/components/callout.js +285 -0
  31. package/dist/components/callout.js.map +1 -0
  32. package/dist/components/card.d.ts +156 -0
  33. package/dist/components/card.d.ts.map +1 -0
  34. package/dist/components/card.js +396 -0
  35. package/dist/components/card.js.map +1 -0
  36. package/dist/components/care-card.d.ts +182 -0
  37. package/dist/components/care-card.d.ts.map +1 -0
  38. package/dist/components/care-card.js +544 -0
  39. package/dist/components/care-card.js.map +1 -0
  40. package/dist/components/checkbox.d.ts +58 -0
  41. package/dist/components/checkbox.d.ts.map +1 -0
  42. package/dist/components/checkbox.js +167 -0
  43. package/dist/components/checkbox.js.map +1 -0
  44. package/dist/components/combobox.d.ts +71 -0
  45. package/dist/components/combobox.d.ts.map +1 -0
  46. package/dist/components/combobox.js +204 -0
  47. package/dist/components/combobox.js.map +1 -0
  48. package/dist/components/consent-sheet.d.ts +186 -0
  49. package/dist/components/consent-sheet.d.ts.map +1 -0
  50. package/dist/components/consent-sheet.js +452 -0
  51. package/dist/components/consent-sheet.js.map +1 -0
  52. package/dist/components/dialog.d.ts +108 -0
  53. package/dist/components/dialog.d.ts.map +1 -0
  54. package/dist/components/dialog.js +573 -0
  55. package/dist/components/dialog.js.map +1 -0
  56. package/dist/components/disclaimer-note.d.ts +144 -0
  57. package/dist/components/disclaimer-note.d.ts.map +1 -0
  58. package/dist/components/disclaimer-note.js +486 -0
  59. package/dist/components/disclaimer-note.js.map +1 -0
  60. package/dist/components/divider.d.ts +76 -0
  61. package/dist/components/divider.d.ts.map +1 -0
  62. package/dist/components/divider.js +101 -0
  63. package/dist/components/divider.js.map +1 -0
  64. package/dist/components/dose-tracker.d.ts +137 -0
  65. package/dist/components/dose-tracker.d.ts.map +1 -0
  66. package/dist/components/dose-tracker.js +154 -0
  67. package/dist/components/dose-tracker.js.map +1 -0
  68. package/dist/components/empty-state.d.ts +171 -0
  69. package/dist/components/empty-state.d.ts.map +1 -0
  70. package/dist/components/empty-state.js +387 -0
  71. package/dist/components/empty-state.js.map +1 -0
  72. package/dist/components/field.d.ts +195 -0
  73. package/dist/components/field.d.ts.map +1 -0
  74. package/dist/components/field.js +282 -0
  75. package/dist/components/field.js.map +1 -0
  76. package/dist/components/goal-ring.d.ts +114 -0
  77. package/dist/components/goal-ring.d.ts.map +1 -0
  78. package/dist/components/goal-ring.js +254 -0
  79. package/dist/components/goal-ring.js.map +1 -0
  80. package/dist/components/icon-button.d.ts +124 -0
  81. package/dist/components/icon-button.d.ts.map +1 -0
  82. package/dist/components/icon-button.js +113 -0
  83. package/dist/components/icon-button.js.map +1 -0
  84. package/dist/components/link.d.ts +122 -0
  85. package/dist/components/link.d.ts.map +1 -0
  86. package/dist/components/link.js +164 -0
  87. package/dist/components/link.js.map +1 -0
  88. package/dist/components/log-sheet.d.ts +259 -0
  89. package/dist/components/log-sheet.d.ts.map +1 -0
  90. package/dist/components/log-sheet.js +437 -0
  91. package/dist/components/log-sheet.js.map +1 -0
  92. package/dist/components/menu.d.ts +69 -0
  93. package/dist/components/menu.d.ts.map +1 -0
  94. package/dist/components/menu.js +190 -0
  95. package/dist/components/menu.js.map +1 -0
  96. package/dist/components/metric-tile.d.ts +301 -0
  97. package/dist/components/metric-tile.d.ts.map +1 -0
  98. package/dist/components/metric-tile.js +533 -0
  99. package/dist/components/metric-tile.js.map +1 -0
  100. package/dist/components/number-field.d.ts +62 -0
  101. package/dist/components/number-field.d.ts.map +1 -0
  102. package/dist/components/number-field.js +134 -0
  103. package/dist/components/number-field.js.map +1 -0
  104. package/dist/components/popover.d.ts +70 -0
  105. package/dist/components/popover.d.ts.map +1 -0
  106. package/dist/components/popover.js +174 -0
  107. package/dist/components/popover.js.map +1 -0
  108. package/dist/components/progress.d.ts +83 -0
  109. package/dist/components/progress.d.ts.map +1 -0
  110. package/dist/components/progress.js +140 -0
  111. package/dist/components/progress.js.map +1 -0
  112. package/dist/components/questionnaire.d.ts +123 -0
  113. package/dist/components/questionnaire.d.ts.map +1 -0
  114. package/dist/components/questionnaire.js +148 -0
  115. package/dist/components/questionnaire.js.map +1 -0
  116. package/dist/components/radio-group.d.ts +66 -0
  117. package/dist/components/radio-group.d.ts.map +1 -0
  118. package/dist/components/radio-group.js +186 -0
  119. package/dist/components/radio-group.js.map +1 -0
  120. package/dist/components/range-bar.d.ts +172 -0
  121. package/dist/components/range-bar.d.ts.map +1 -0
  122. package/dist/components/range-bar.js +578 -0
  123. package/dist/components/range-bar.js.map +1 -0
  124. package/dist/components/range-legend.d.ts +97 -0
  125. package/dist/components/range-legend.d.ts.map +1 -0
  126. package/dist/components/range-legend.js +166 -0
  127. package/dist/components/range-legend.js.map +1 -0
  128. package/dist/components/reading-input.d.ts +225 -0
  129. package/dist/components/reading-input.d.ts.map +1 -0
  130. package/dist/components/reading-input.js +651 -0
  131. package/dist/components/reading-input.js.map +1 -0
  132. package/dist/components/relative-time.d.ts +177 -0
  133. package/dist/components/relative-time.d.ts.map +1 -0
  134. package/dist/components/relative-time.js +603 -0
  135. package/dist/components/relative-time.js.map +1 -0
  136. package/dist/components/result-card.d.ts +319 -0
  137. package/dist/components/result-card.d.ts.map +1 -0
  138. package/dist/components/result-card.js +614 -0
  139. package/dist/components/result-card.js.map +1 -0
  140. package/dist/components/scale-input.d.ts +58 -0
  141. package/dist/components/scale-input.d.ts.map +1 -0
  142. package/dist/components/scale-input.js +170 -0
  143. package/dist/components/scale-input.js.map +1 -0
  144. package/dist/components/score-dial.d.ts +205 -0
  145. package/dist/components/score-dial.d.ts.map +1 -0
  146. package/dist/components/score-dial.js +728 -0
  147. package/dist/components/score-dial.js.map +1 -0
  148. package/dist/components/scroll-area.d.ts +38 -0
  149. package/dist/components/scroll-area.d.ts.map +1 -0
  150. package/dist/components/scroll-area.js +138 -0
  151. package/dist/components/scroll-area.js.map +1 -0
  152. package/dist/components/segmented-control.d.ts +69 -0
  153. package/dist/components/segmented-control.d.ts.map +1 -0
  154. package/dist/components/segmented-control.js +259 -0
  155. package/dist/components/segmented-control.js.map +1 -0
  156. package/dist/components/select.d.ts +72 -0
  157. package/dist/components/select.d.ts.map +1 -0
  158. package/dist/components/select.js +205 -0
  159. package/dist/components/select.js.map +1 -0
  160. package/dist/components/sheet.d.ts +192 -0
  161. package/dist/components/sheet.d.ts.map +1 -0
  162. package/dist/components/sheet.js +952 -0
  163. package/dist/components/sheet.js.map +1 -0
  164. package/dist/components/skeleton.d.ts +104 -0
  165. package/dist/components/skeleton.d.ts.map +1 -0
  166. package/dist/components/skeleton.js +266 -0
  167. package/dist/components/skeleton.js.map +1 -0
  168. package/dist/components/slider.d.ts +55 -0
  169. package/dist/components/slider.d.ts.map +1 -0
  170. package/dist/components/slider.js +170 -0
  171. package/dist/components/slider.js.map +1 -0
  172. package/dist/components/source-citation.d.ts +127 -0
  173. package/dist/components/source-citation.d.ts.map +1 -0
  174. package/dist/components/source-citation.js +391 -0
  175. package/dist/components/source-citation.js.map +1 -0
  176. package/dist/components/spinner.d.ts +86 -0
  177. package/dist/components/spinner.d.ts.map +1 -0
  178. package/dist/components/spinner.js +97 -0
  179. package/dist/components/spinner.js.map +1 -0
  180. package/dist/components/status-pill.d.ts +90 -0
  181. package/dist/components/status-pill.d.ts.map +1 -0
  182. package/dist/components/status-pill.js +259 -0
  183. package/dist/components/status-pill.js.map +1 -0
  184. package/dist/components/stepper.d.ts +99 -0
  185. package/dist/components/stepper.d.ts.map +1 -0
  186. package/dist/components/stepper.js +152 -0
  187. package/dist/components/stepper.js.map +1 -0
  188. package/dist/components/surface.d.ts +92 -0
  189. package/dist/components/surface.d.ts.map +1 -0
  190. package/dist/components/surface.js +261 -0
  191. package/dist/components/surface.js.map +1 -0
  192. package/dist/components/switch.d.ts +48 -0
  193. package/dist/components/switch.d.ts.map +1 -0
  194. package/dist/components/switch.js +152 -0
  195. package/dist/components/switch.js.map +1 -0
  196. package/dist/components/symptom-picker.d.ts +69 -0
  197. package/dist/components/symptom-picker.d.ts.map +1 -0
  198. package/dist/components/symptom-picker.js +170 -0
  199. package/dist/components/symptom-picker.js.map +1 -0
  200. package/dist/components/tab-bar.d.ts +110 -0
  201. package/dist/components/tab-bar.d.ts.map +1 -0
  202. package/dist/components/tab-bar.js +118 -0
  203. package/dist/components/tab-bar.js.map +1 -0
  204. package/dist/components/table.d.ts +117 -0
  205. package/dist/components/table.d.ts.map +1 -0
  206. package/dist/components/table.js +65 -0
  207. package/dist/components/table.js.map +1 -0
  208. package/dist/components/tabs.d.ts +106 -0
  209. package/dist/components/tabs.d.ts.map +1 -0
  210. package/dist/components/tabs.js +136 -0
  211. package/dist/components/tabs.js.map +1 -0
  212. package/dist/components/term.d.ts +243 -0
  213. package/dist/components/term.d.ts.map +1 -0
  214. package/dist/components/term.js +562 -0
  215. package/dist/components/term.js.map +1 -0
  216. package/dist/components/textarea.d.ts +157 -0
  217. package/dist/components/textarea.d.ts.map +1 -0
  218. package/dist/components/textarea.js +66 -0
  219. package/dist/components/textarea.js.map +1 -0
  220. package/dist/components/timeline-entry.d.ts +99 -0
  221. package/dist/components/timeline-entry.d.ts.map +1 -0
  222. package/dist/components/timeline-entry.js +47 -0
  223. package/dist/components/timeline-entry.js.map +1 -0
  224. package/dist/components/toast.d.ts +80 -0
  225. package/dist/components/toast.d.ts.map +1 -0
  226. package/dist/components/toast.js +266 -0
  227. package/dist/components/toast.js.map +1 -0
  228. package/dist/components/tooltip.d.ts +48 -0
  229. package/dist/components/tooltip.d.ts.map +1 -0
  230. package/dist/components/tooltip.js +159 -0
  231. package/dist/components/tooltip.js.map +1 -0
  232. package/dist/components/trend-sparkline.d.ts +188 -0
  233. package/dist/components/trend-sparkline.d.ts.map +1 -0
  234. package/dist/components/trend-sparkline.js +796 -0
  235. package/dist/components/trend-sparkline.js.map +1 -0
  236. package/dist/components/value.d.ts +150 -0
  237. package/dist/components/value.d.ts.map +1 -0
  238. package/dist/components/value.js +402 -0
  239. package/dist/components/value.js.map +1 -0
  240. package/dist/components/visually-hidden.d.ts +61 -0
  241. package/dist/components/visually-hidden.d.ts.map +1 -0
  242. package/dist/components/visually-hidden.js +172 -0
  243. package/dist/components/visually-hidden.js.map +1 -0
  244. package/dist/index.d.ts +63 -0
  245. package/dist/index.d.ts.map +1 -0
  246. package/dist/index.js +72 -0
  247. package/dist/index.js.map +1 -0
  248. package/dist/opsinjs.d.ts +443 -0
  249. package/dist/opsinjs.d.ts.map +1 -0
  250. package/dist/opsinjs.js +906 -0
  251. package/dist/opsinjs.js.map +1 -0
  252. package/dist/status.d.ts +111 -0
  253. package/dist/status.d.ts.map +1 -0
  254. package/dist/status.js +125 -0
  255. package/dist/status.js.map +1 -0
  256. package/dist/styles.css +2 -0
  257. package/dist/utils.d.ts +20 -0
  258. package/dist/utils.d.ts.map +1 -0
  259. package/dist/utils.js +82 -0
  260. package/dist/utils.js.map +1 -0
  261. package/package.json +86 -3
  262. package/styles/base.css +132 -0
  263. package/styles/roles.css +412 -0
  264. package/styles/standalone.css +20 -0
  265. package/styles/tailwind.css +18 -0
  266. package/styles/theme.css +309 -0
@@ -0,0 +1,437 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * LogSheet is a Sheet with a capture contract: one entry, a time, an optional
5
+ * note, one explicit save, and no way to leave typed input behind by accident.
6
+ *
7
+ * IT EXTENDS SHEET, AND THAT NOW MEANS SOMETHING (ADR 0021). `LogSheetProps`
8
+ * extends `SheetProps`, so `open`, `onOpenChange`, `title`, `detents` and
9
+ * `className` arrive from the base unchanged and are documented on the base's
10
+ * page. They are not redeclared here and not renamed. Three of Sheet's props
11
+ * are omitted rather than inherited. They are `footer`, because this component
12
+ * owns the action area; `modal` and `dismissible`, because both of this
13
+ * component's promises depend on their defaults and neither is a knob a capture
14
+ * surface should offer. See the omission note above the interface.
15
+ *
16
+ * THE HOLE THIS FILE HAD TO FILL, and the decision it records.
17
+ *
18
+ * The specification hands the component `children: React.ReactNode` and asks
19
+ * `onSave` to return `values: Record<string, number | string | null>`. Those two
20
+ * sentences cannot both be true without a mechanism, and the page named none.
21
+ * Three mechanisms were available and one had to be chosen:
22
+ *
23
+ * 1. A registration context. Each control inside registers its key and its
24
+ * current value on a context this component provides. REJECTED: it needs
25
+ * every control to opt in, which means editing `Field`, and this file
26
+ * does not own `Field`. It also silently collects nothing from any
27
+ * control a product wrote itself, which is most of them. A collector that
28
+ * returns an incomplete record and cannot tell it is incomplete is worse
29
+ * than none.
30
+ *
31
+ * 2. A `<form>` and `FormData`, keyed off each control's `name`. REJECTED,
32
+ * and the reason is the one rule in this batch that is not negotiable:
33
+ * `FormData` returns `""` for a control the reader emptied and `""` for one
34
+ * they never touched, and it returns strings for everything. `null` is a
35
+ * first-class absence here, distinct from `0` and distinct from "not typed
36
+ * yet", and a channel that cannot carry the distinction is a channel that
37
+ * quietly turns "no answer" into "zero" somewhere downstream in somebody's
38
+ * record.
39
+ *
40
+ * 3. A controlled `values` prop. CHOSEN. The product already holds this state
41
+ * because every controlled input in `children` is reading and writing it.
42
+ * So asking for it is asking for something that already exists rather than
43
+ * duplicating it. `children` stays genuinely opaque: this file never walks
44
+ * it, never inspects it, and never needs to. What it costs is honest and
45
+ * visible at the call site: the product writes the key beside each control.
46
+ *
47
+ * SO THE DIVISION IS: the product owns every field it rendered, and this
48
+ * component owns exactly the two it renders itself. Those two are the time and
49
+ * the note. It also owns the four facts about the record that only it is in a
50
+ * position to state. It adds nothing to `values`, removes nothing from it, and
51
+ * coerces nothing in it.
52
+ *
53
+ * WHAT IT REFUSES TO DO. It does not evaluate what is entered: no status
54
+ * colour, no verdict, no comparison against anything. It does not block a save
55
+ * for any reason. It does not close itself, on save or ever. `open` belongs to
56
+ * the product, and a sheet that closed itself on save would be deciding the
57
+ * reader is finished. It mounts no live region. And it does not count the
58
+ * fields: see the note on `children`.
59
+ */
60
+ import { useId, useRef, useState } from "react";
61
+ import { HEALTH_CATEGORIES, isDevelopment, isHealthCategory, warnOnce, } from "../opsinjs.js";
62
+ import { cn } from "../utils.js";
63
+ import { Button } from "./button.js";
64
+ import { Field } from "./field.js";
65
+ import { Sheet } from "./sheet.js";
66
+ /**
67
+ * Once per cause, not once per render.
68
+ *
69
+ * The same channel `Sheet` and `Field` use, and for the same reason:
70
+ * `tokens/errors.json` has no code for either mistake below and a component may
71
+ * not mint one, but the once-per-cause half of that file's policy is not
72
+ * attached to the code. LogSheet wraps a product's own controlled form, so
73
+ * every keystroke re-renders it; an un-deduplicated warning prints once per
74
+ * character and buries whatever is reported next.
75
+ */
76
+ const warnedCauses = new Set();
77
+ function warnDevelopmentOnce(cause, message) {
78
+ if (!isDevelopment() || warnedCauses.has(cause))
79
+ return;
80
+ warnedCauses.add(cause);
81
+ console.warn(message);
82
+ }
83
+ /**
84
+ * The category tint, written out because Tailwind reads class names as literal
85
+ * strings. `bg-category-${category}` generates no CSS and the band renders
86
+ * invisible, which is the failure that looks like nothing happening.
87
+ *
88
+ * The BARE category name is the ACCENT role, and the asymmetry between the axes
89
+ * is worth restating because it catches people: the bare status name is the
90
+ * LINE role. Accent is the identity fill, chosen for recognition rather than
91
+ * for contrast, so it is never text and never the only boundary. A band
92
+ * that holds neither is exactly what it is for.
93
+ *
94
+ * No word accompanies it, deliberately. Category colour says what a reading is
95
+ * about, never how urgent it is, and the sheet's own title already names what
96
+ * is being logged in full. In greyscale the band says nothing, and nothing is
97
+ * what it is entitled to say.
98
+ */
99
+ const CATEGORY_ACCENT = {
100
+ sleep: "bg-category-sleep",
101
+ heart: "bg-category-heart",
102
+ activity: "bg-category-activity",
103
+ nutrition: "bg-category-nutrition",
104
+ mind: "bg-category-mind",
105
+ labs: "bg-category-labs",
106
+ };
107
+ /**
108
+ * A `Date` as the value a `datetime-local` control wants: local wall-clock, to
109
+ * the minute, with no zone and no seconds.
110
+ *
111
+ * Hand-written rather than `toISOString().slice(...)`, which is the tempting
112
+ * one-liner and is wrong: `toISOString` converts to UTC first, so a reader east
113
+ * of Greenwich would open the sheet and find it pre-filled with an hour they
114
+ * were not at.
115
+ */
116
+ function toDateTimeLocal(date) {
117
+ const pad = (part) => String(part).padStart(2, "0");
118
+ return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}` +
119
+ `T${pad(date.getHours())}:${pad(date.getMinutes())}`);
120
+ }
121
+ /**
122
+ * Whether two value records hold the same answers.
123
+ *
124
+ * `Object.is` per key rather than `===`, so `null` and `0` stay different
125
+ * things and a stray `NaN` compares equal to itself. Shallow, because the shape
126
+ * the interface declares is flat. A nested object under a key would compare by
127
+ * identity, and this returns false where it cannot be sure, which is the safe
128
+ * direction: the cost of a wrong `false` is one confirmation the reader did not
129
+ * need, and the cost of a wrong `true` is their typing thrown away.
130
+ */
131
+ function sameEntries(a, b) {
132
+ const keys = Object.keys(a);
133
+ if (keys.length !== Object.keys(b).length)
134
+ return false;
135
+ return keys.every((key) => Object.is(a[key], b[key]));
136
+ }
137
+ export function LogSheet({ open, onOpenChange, title, values, children, category, saveLabel, timeLabel, noteLabel, maxBackdateDays, onSave, onDiscard, ...sheet }) {
138
+ /* WHEN "NOW" IS READ, AND WHY THERE IS NO EFFECT DOING IT.
139
+ The clock is read in two places, and both of them are places the server
140
+ never reaches. The lazy initialiser below runs on the server too, but
141
+ everything derived from it is inside `Drawer.Portal`. Floating-ui's portal
142
+ holds its container in state and sets it in an effect, so its children
143
+ render as nothing in the server's HTML and as nothing on the first client
144
+ render. And the capture in the transition branch below runs only when
145
+ `open` changes, which during a server render it never does.
146
+
147
+ That matters because a `datetime-local` value is local wall-clock: a server
148
+ in UTC and a reader in Lisbon disagree by an hour, and a value read during
149
+ a render that reaches HTML is a hydration mismatch on every reader outside
150
+ the server's zone. It is also why this is not an effect. An effect that
151
+ sets state is a cascading render the lint rule refuses, and the render-time
152
+ adjustment is React's own answer for state derived from a prop. */
153
+ const [openedAt, setOpenedAt] = useState(() => open ? new Date() : null);
154
+ /* `null` means the reader has not touched the time control. That is a
155
+ different fact from "the control holds the opening time", and it is the
156
+ difference `backdated` is made of. */
157
+ const [typedAt, setTypedAt] = useState(null);
158
+ const [note, setNote] = useState("");
159
+ const [confirming, setConfirming] = useState(false);
160
+ const [route, setRoute] = useState("other");
161
+ /* Where focus was when the question went up, so it can go back. Null when
162
+ focus was outside the sheet, which is what a scrim tap usually leaves. */
163
+ const focusBeforeConfirm = useRef(null);
164
+ /* The keep answer's wrapper, so its Button can be focused without a ref on
165
+ Button, whose props type does not carry one. */
166
+ const keepRef = useRef(null);
167
+ /* One id for the discard question, so both answers can point at it with
168
+ aria-describedby. Without it focus lands on a button announced as its label
169
+ alone and the sentence that says what is at stake is voiced by nothing. */
170
+ const questionId = useId();
171
+ /* WHAT "UNSAVED" IS MEASURED AGAINST. Set when the sheet opens, and set again
172
+ the moment `onSave` fires. That matters because a sheet the product keeps
173
+ open after a save is one where the question "you have not saved this entry"
174
+ would be a false statement, and this component's copy is a claim like any
175
+ other. */
176
+ const [baseline, setBaseline] = useState(() => ({ values, typedAt: null, note: "" }));
177
+ const [openLastRender, setOpenLastRender] = useState(open);
178
+ /* Reset on the render that notices the sheet has opened, rather than in an
179
+ effect. An effect would commit the sheet holding the previous entry's note
180
+ and time, paint it, and then correct it. That is one frame of somebody
181
+ else's record on the way in.
182
+
183
+ Every reopen is a fresh entry. A log sheet that remembered what was typed
184
+ last time is how a log fills with numbers nobody measured. */
185
+ if (openLastRender !== open) {
186
+ setOpenLastRender(open);
187
+ if (open) {
188
+ setOpenedAt(new Date());
189
+ setTypedAt(null);
190
+ setNote("");
191
+ setConfirming(false);
192
+ /* No question is up on a fresh open, so nothing is owed a focus return. */
193
+ focusBeforeConfirm.current = null;
194
+ setRoute("other");
195
+ setBaseline({ values, typedAt: null, note: "" });
196
+ }
197
+ }
198
+ const openedValue = openedAt === null ? "" : toDateTimeLocal(openedAt);
199
+ const occurredAt = typedAt ?? openedValue;
200
+ /* `backdated`, as the reader's action rather than as arithmetic. Deriving it
201
+ from `occurredAt !== recordedAt` was the obvious implementation and is
202
+ wrong: those two always differ by however long the entry took to type, so
203
+ every record would come back marked and the flag would mean nothing. There
204
+ is no tolerance window here because none is needed. The reader either
205
+ moved the control away from the time it opened at, or they did not.
206
+
207
+ An emptied control is not a re-dating. A reader who clears the field has
208
+ said "I do not know when", which is the same class of fact as a null in
209
+ `values`, and flagging it as a deliberate re-dating puts a claim in
210
+ somebody's record that they never made. So `""` is excluded here, the same
211
+ refusal this file makes for `FormData` above and that the demo makes for
212
+ its own control below. */
213
+ const timeEdited = typedAt !== null && typedAt !== "" && typedAt !== openedValue;
214
+ if (typeof saveLabel !== "string" || saveLabel.trim() === "") {
215
+ warnDevelopmentOnce("save-label", "[opsinjs] <LogSheet> was given no `saveLabel`. The primary action has to " +
216
+ "say what it saves, and there is no default here on purpose: a button " +
217
+ 'reading "Save" tells a reader nothing they did not already know, and a ' +
218
+ "component that shipped one would let every product skip the rule.");
219
+ }
220
+ /* The category, checked rather than trusted. This file ships as source into
221
+ JavaScript projects where a type is advice, and a seventh category is a
222
+ seventh colour ramp that does not exist. So an unrecognised one is
223
+ reported and the band is left out rather than tinted from a ramp picked at
224
+ random. */
225
+ let tint;
226
+ if (category !== undefined) {
227
+ if (isHealthCategory(category)) {
228
+ tint = category;
229
+ }
230
+ else {
231
+ warnOnce("OPSIN-0010", {
232
+ category: String(category),
233
+ known: HEALTH_CATEGORIES.join(", "),
234
+ });
235
+ }
236
+ }
237
+ const earliest = (() => {
238
+ if (openedAt === null || maxBackdateDays === undefined)
239
+ return undefined;
240
+ const date = new Date(openedAt);
241
+ /* Day arithmetic through the Date object rather than a subtraction in
242
+ milliseconds, so a window that spans a daylight-saving change lands on
243
+ the date a reader would name rather than an hour either side of it.
244
+
245
+ Then floored to the start of that day, because the hint beside the
246
+ control names a DATE and `min` carries a TIME. Without the floor a
247
+ sheet opened at 12:29 emits min="2026-08-29T12:29" under a sentence
248
+ that says entries can be dated back to 29 August, and a reader
249
+ backdating a morning reading to the day the copy just offered them is
250
+ refused by the control. The window is a number of days, so its edge is
251
+ the start of a day. */
252
+ date.setDate(date.getDate() - maxBackdateDays);
253
+ date.setHours(0, 0, 0, 0);
254
+ return date;
255
+ })();
256
+ /* Deliberately more eager than `timeEdited`: a reader who moved the time
257
+ control and then moved it back has still touched something, and the cost of
258
+ asking once too often is a question, while the cost of asking once too
259
+ rarely is their typing. */
260
+ const dirty = !sameEntries(values, baseline.values) ||
261
+ typedAt !== baseline.typedAt ||
262
+ note !== baseline.note;
263
+ /* The time field's guidance, computed as a list of sentences so a second one
264
+ can appear only when it is about something. The second sentence is shown
265
+ just while the control is empty, which is the only moment it is about
266
+ anything, because `buildEntry` then substitutes the save time and a reader
267
+ who cleared the field on purpose should see that coming rather than find it
268
+ afterwards.
269
+
270
+ The punctuation is computed rather than written because
271
+ content/docs/content/grammar-and-mechanics.mdx takes no full stop on a
272
+ single-sentence hint and full stops on full sentences, so one sentence
273
+ ends bare and two are both stopped. The sentences in the array carry no
274
+ stops for exactly that reason. */
275
+ const timeHints = [
276
+ earliest
277
+ ? `Entries can be dated back to ${new Intl.DateTimeFormat(undefined, {
278
+ dateStyle: "long",
279
+ }).format(earliest)}`
280
+ : null,
281
+ occurredAt === ""
282
+ ? "If you leave this empty, the time you save is used"
283
+ : null,
284
+ ].filter((line) => line !== null);
285
+ const timeHint = timeHints.length === 0
286
+ ? undefined
287
+ : timeHints.length === 1
288
+ ? timeHints[0]
289
+ : timeHints.map((line) => `${line}.`).join(" ");
290
+ function buildEntry() {
291
+ const recordedAt = new Date();
292
+ const chosen = occurredAt === "" ? null : new Date(occurredAt);
293
+ const trimmed = note.trim();
294
+ return {
295
+ /* Copied rather than passed by reference: the product's state object is
296
+ about to change under it, and a record that mutates after it was handed
297
+ over is a record nobody can trust. Shallow, which matches the shape the
298
+ type declares. */
299
+ values: { ...values },
300
+ occurredAt: chosen === null || Number.isNaN(chosen.getTime())
301
+ ? recordedAt.toISOString()
302
+ : chosen.toISOString(),
303
+ recordedAt: recordedAt.toISOString(),
304
+ backdated: timeEdited,
305
+ provenance: "self-reported",
306
+ ...(trimmed === "" ? {} : { note: trimmed }),
307
+ };
308
+ }
309
+ /* DISMISSAL, AND THE ONE THING THIS COMPONENT WILL NOT LET HAPPEN.
310
+ Sheet reports which route a close arrived by precisely so that a surface
311
+ holding unsaved input can ask first. It asks by the same route as a
312
+ background tap, which is the wording its page uses. Every route asks,
313
+ including the close control in the header: the specification says Cancel
314
+ "never discards without asking", and a reader who taps the scrim by
315
+ accident and one who reaches for Close deliberately both lose the same
316
+ typing. Every route asks the same question once. After it is up the ambient
317
+ routes answer it with the safe answer while the close control leaves it
318
+ standing, because one of those is a gesture and the other is an act.
319
+
320
+ The question is asked IN PLACE, in the footer, rather than in a second
321
+ modal surface. A Dialog opening from a Sheet is a composition error by
322
+ Sheet's own page, and two stacked modal surfaces produce a focus order
323
+ nobody can predict and an escape key with two plausible meanings. */
324
+ function handleOpenChange(nextOpen, taken) {
325
+ if (nextOpen) {
326
+ onOpenChange(true, taken);
327
+ return;
328
+ }
329
+ /* While the question is on screen a dismissal answers it, and the answer is
330
+ the safe one for every route except the header close control. Escape, a
331
+ scrim tap and a drag are gestures a reader can make by accident, so they
332
+ take the reader back to what they were typing, with the Discard entry
333
+ control one Shift+Tab away. The close control is different: a reader who
334
+ taps Close, reads "Discard it?" and taps Close again is repeating a
335
+ deliberate act, and withdrawing the question in reply would make the same
336
+ gesture flip the sheet between two states for ever and never close it. So
337
+ for that one route the question stays up and focus goes back to the
338
+ answers, where the reader has to choose one of two words. It does not
339
+ close, does not discard and sets no state: this handler owns the decision,
340
+ and returning without propagating the close to the product's onOpenChange
341
+ leaves `open` true, so the sheet stays open behind the question. */
342
+ if (confirming) {
343
+ if (taken === "close-control") {
344
+ keepRef.current
345
+ ?.querySelector('[data-slot="button"]')
346
+ ?.focus();
347
+ return;
348
+ }
349
+ keepEditing();
350
+ return;
351
+ }
352
+ if (dirty) {
353
+ /* Remember where focus was before the question replaces the footer, so
354
+ Keep editing can put it back. The containment test keeps it honest: a
355
+ scrim tap usually leaves focus on the body or the scrim, and restoring
356
+ focus to the body is worse than leaving it alone, so that case captures
357
+ null. `sheet-container` is the popup's slot. `document` is safe here
358
+ because this runs in an event handler, never in a render. */
359
+ const active = document.activeElement;
360
+ focusBeforeConfirm.current =
361
+ active instanceof HTMLElement &&
362
+ active.closest('[data-slot="sheet-container"]') !== null
363
+ ? active
364
+ : null;
365
+ setRoute(taken);
366
+ setConfirming(true);
367
+ return;
368
+ }
369
+ onOpenChange(false, taken);
370
+ }
371
+ /* Focus moves BEFORE the state change, and that ordering is the whole trick.
372
+ The answers are still mounted at this point, so moving focus out of the row
373
+ and then removing the row leaves focus where it was put. The other order
374
+ removes the focused element first, which drops focus on the document body
375
+ and is the defect this repairs. It is also why there is no effect and no
376
+ flushSync here. The fallback is Sheet's close control, for a question that
377
+ went up over a scrim tap where there was no in-sheet control to return to. */
378
+ function keepEditing() {
379
+ const previous = focusBeforeConfirm.current;
380
+ focusBeforeConfirm.current = null;
381
+ const fallback = keepRef.current
382
+ ?.closest('[data-slot="sheet-container"]')
383
+ ?.querySelector('[data-slot="sheet-close"]') ?? null;
384
+ const target = previous !== null && previous.isConnected ? previous : fallback;
385
+ target?.focus();
386
+ setConfirming(false);
387
+ }
388
+ /* EVERY CONTROL BELOW SITS IN A WRAPPER THAT CARRIES THE SLOT, and that is
389
+ not decoration. `Button` stamps `data-slot="button"` AFTER spreading the
390
+ props it was given, so a slot passed to it is silently dropped. The
391
+ parts named in this component's anatomy have to exist in the DOM or the
392
+ anatomy is a description of something else. The alternative was hand-rolled
393
+ controls, which teaches, in shipped source, that the primary action at the
394
+ foot of a sheet is a styled `<button>`. */
395
+ const footer = confirming ? (_jsxs("div", { "data-slot": "log-sheet-confirm", className: "flex w-full flex-col gap-opsin-3", children: [_jsx("p", { id: questionId, className: "m-0 text-opsin-headline text-foreground", children: "You have not saved this entry. Discard it?" }), _jsxs("div", { "data-slot": "log-sheet-answers", className: "flex w-full flex-col gap-(--opsin-space-4,1rem)", children: [_jsx("div", { "data-slot": "log-sheet-discard", children: _jsx(Button, { variant: "destructive", "aria-describedby": questionId, onClick: () => {
396
+ const entry = buildEntry();
397
+ setConfirming(false);
398
+ /* The sheet is leaving, so a captured element must not be focused
399
+ after it has gone and Sheet's own return-to-trigger must not be
400
+ fought. */
401
+ focusBeforeConfirm.current = null;
402
+ onDiscard?.(entry);
403
+ onOpenChange(false, route);
404
+ }, children: "Discard entry" }) }), _jsx("div", { "data-slot": "log-sheet-keep", ref: keepRef, className: "w-full", children: _jsx(Button, { variant: "primary", fullWidth: true, autoFocus: true, "aria-describedby": questionId, onClick: keepEditing, children: "Keep editing" }) })] })] })) : (_jsx("div", { "data-slot": "log-sheet-save", className: "w-full", children: _jsx(Button, { variant: "primary", fullWidth: true, onClick: () => {
405
+ onSave(buildEntry());
406
+ /* The record is now the product's, so nothing on this sheet is
407
+ unsaved any more. A product that closes the sheet here never sees
408
+ the difference. One that keeps it open would otherwise be told,
409
+ untruthfully, that it holds input nobody has saved. It might keep
410
+ the sheet open to retry, or to log a second entry. */
411
+ setBaseline({ values, typedAt, note });
412
+ }, children: saveLabel }) }));
413
+ return (_jsx(Sheet, { ...sheet, open: open, onOpenChange: handleOpenChange, title: title, footer: footer, children: _jsx(Sheet.Content, { children: _jsxs("div", { "data-slot": "log-sheet", className: "flex flex-col gap-opsin-6 py-opsin-2", children: [tint === undefined ? null : (
414
+ /* The category axis, and the only element in this sheet it reaches.
415
+ `data-category` and the class are two spellings of one decision:
416
+ the attribute is the DOM contract a product's stylesheet, its
417
+ print rules and its tests key on, and the class is what paints.
418
+ `aria-hidden`, because it carries identity and no words, and the
419
+ title above it has already said what is being logged. */
420
+ _jsx("div", { "data-slot": "log-sheet-category", "data-category": tint, "aria-hidden": "true", className: cn("h-opsin-1 w-full shrink-0 rounded-full", CATEGORY_ACCENT[tint]) })), _jsx("div", { "data-slot": "log-sheet-fields", className: "flex flex-col gap-opsin-6", children: children }), _jsx("div", { "data-slot": "log-sheet-time", children: _jsx(Field, { label: timeLabel?.trim() ? timeLabel : "Time of this entry",
421
+ /* Through `Field`'s own hint rather than beside it. Base UI's
422
+ field context registers the description's id on the control and
423
+ removes it again when the field unmounts, which is the wiring
424
+ this component exists not to hand-roll. An `aria-describedby`
425
+ written here would be merged with, or replaced by, the one that
426
+ context maintains. */
427
+ hint: timeHint, children: _jsx(Field.Control, { type: "datetime-local", value: occurredAt,
428
+ /* The window the product owns, handed to the platform's own
429
+ picker. On a platform with a keyboard a reader can still
430
+ type a time outside it and the save still goes through,
431
+ because nothing in this component blocks a save. On a touch
432
+ platform the picker is the only way to change a
433
+ datetime-local, so there the window is a floor rather than a
434
+ statement. Both are true and the page says which is which. */
435
+ min: earliest ? toDateTimeLocal(earliest) : undefined, onChange: (event) => setTypedAt(event.target.value) }) }) }), noteLabel?.trim() ? (_jsx("div", { "data-slot": "log-sheet-note", children: _jsx(Field, { label: noteLabel, optionality: "optional", children: _jsx(Field.Control, { render: _jsx("textarea", { rows: 3 }), className: "resize-none", value: note, onChange: (event) => setNote(event.target.value) }) }) })) : null] }) }) }));
436
+ }
437
+ //# sourceMappingURL=log-sheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-sheet.js","sourceRoot":"","sources":["../../src/components/log-sheet.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAE/D,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,QAAQ,GAET,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAc,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAa,CAAA;AACnC,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAa,CAAA;AAapD;;;;;;;;;GASG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAA;AAEtC,SAAS,mBAAmB,CAAC,KAAa,EAAE,OAAe;IACzD,IAAI,CAAC,aAAa,EAAE,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAM;IACvD,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,eAAe,GAAmC;IACtD,KAAK,EAAE,mBA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,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB;4BAC3D;;;;;oDAKwB;4BACxB,IAAI,EAAE,QAAQ,YAEd,KAAC,KAAK,CAAC,OAAO,IACZ,IAAI,EAAC,gBAAgB,EACrB,KAAK,EAAE,UAAU;gCACjB;;;;;;gGAMgE;gCAChE,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,EACrD,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GACnD,GACI,GACJ,EAEL,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CACnB,2BAAe,gBAAgB,YAC7B,KAAC,KAAK,IAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAC,UAAU,YAqB7C,KAAC,KAAK,CAAC,OAAO,IACZ,MAAM,EAAE,mBAAU,IAAI,EAAE,CAAC,GAAI,EAC7B,SAAS,EAAC,aAAa,EACvB,KAAK,EAAE,IAAI,EACX,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAChD,GACI,GACJ,CACP,CAAC,CAAC,CAAC,IAAI,IACJ,GACQ,GACV,CACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { type ReactElement } from "react";
2
+ /**
3
+ * One action in the list. Kept as a local type rather than a fourth public
4
+ * export, for the reason `select.tsx` gives about its own option shape: the
5
+ * registry contract fixes this file at three public exports, so a consumer names
6
+ * this shape as `MenuProps["items"][number]` rather than importing a fourth
7
+ * symbol.
8
+ */
9
+ interface MenuAction {
10
+ /**
11
+ * The visible words, and what a screen reader reads for the item. Name the
12
+ * action as an imperative the reader is choosing, "Rename" rather than
13
+ * "Renaming", and let a destructive one say what it removes, because the word
14
+ * is the only thing that marks it apart in a system with no destructive tint.
15
+ */
16
+ label: string;
17
+ /**
18
+ * Called when the reader runs the item. The menu closes on the same press, so
19
+ * an action that cannot be undone opens a confirming Dialog from here rather
20
+ * than doing the irreversible thing straight away. Omitted, the item renders
21
+ * but does nothing, which is a mistake a development warning names.
22
+ */
23
+ onClick?: () => void;
24
+ /**
25
+ * Whether this action cannot be run right now. A disabled item drops to the
26
+ * muted ink and is skipped by the Arrow keys rather than removed, so the
27
+ * reader can still see it is an action that is not available to them.
28
+ */
29
+ disabled?: boolean;
30
+ /**
31
+ * Draws a separator above this item, for grouping a related run of actions
32
+ * apart from the one before it. Ignored on the first item, where a separator
33
+ * would have nothing above it. The separator is decorative neutral chrome and
34
+ * carries no meaning of its own beyond the grouping the reader sees.
35
+ */
36
+ separatorBefore?: boolean;
37
+ }
38
+ export interface MenuProps {
39
+ /**
40
+ * The button that opens the menu. It is the caller's own element, and Base UI
41
+ * merges the open behaviour and the `aria-haspopup` and `aria-expanded` state
42
+ * onto it, so it must be a single focusable element such as a button, not a
43
+ * string or a fragment. The system's own Button and IconButton are both fit
44
+ * for this. There is no default, because a menu with no trigger cannot be
45
+ * opened.
46
+ */
47
+ trigger: ReactElement;
48
+ /**
49
+ * The actions, in the order they appear in the list. Each action is a visible
50
+ * label, an optional `onClick`, an optional `disabled` flag and an optional
51
+ * `separatorBefore`. A menu with no actions has nothing to open and a menu
52
+ * with a single action is a button that has not admitted it, so both raise a
53
+ * development warning. Keep a safety-relevant or destructive command out of
54
+ * here entirely: it belongs on the screen as a button, with a Dialog to
55
+ * confirm it, because a reader cannot weigh a command they cannot see.
56
+ */
57
+ items: MenuAction[];
58
+ /**
59
+ * Merged onto the popup. Width and a wider minimum belong here. A class you
60
+ * pass wins over the popup's own where the two conflict, because it is merged
61
+ * last. It is the one route by which colour can reach the control, and the
62
+ * two-colour-axes rule applies to it in full: a menu takes neither a status
63
+ * nor a category tint, and there is no destructive red to reach for either.
64
+ */
65
+ className?: string;
66
+ }
67
+ export declare function Menu({ trigger, items, className }: MenuProps): import("react").JSX.Element | null;
68
+ export {};
69
+ //# sourceMappingURL=menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../src/components/menu.tsx"],"names":[],"mappings":"AAgEA,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,OAAO,CAAA;AAKnD;;;;;;GAMG;AACH,UAAU,UAAU;IAClB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AA0GD,MAAM,WAAW,SAAS;IACxB;;;;;;;OAOG;IACH,OAAO,EAAE,YAAY,CAAA;IACrB;;;;;;;;OAQG;IACH,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,sCA8D5D"}