@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,573 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Dialog is the window that takes a reader's place, their focus and their
5
+ * ability to do anything else, and hands all three back where it found them.
6
+ *
7
+ * THE PAGE ASKED FOR TWO THINGS THAT CANNOT BOTH BE TRUE, AND THIS FILE ANSWERS
8
+ * ONE OF THEM. `dialog.mdx:114` says `severity="alert"` "removes the close
9
+ * control and makes the scrim non-dismissing: an alert dialogue has no valid
10
+ * 'went away' outcome". `dialog.mdx:124` says that below `sheetBelow` pixels
11
+ * "the dialog renders as a Sheet instead". A Sheet is, by its own
12
+ * specification, draggable and dismissible. Put together, an alert dialogue
13
+ * that nobody may dismiss on a laptop becomes dismissible with a thumb on a
14
+ * phone, silently, at whichever width the caller happened to pass. That is not
15
+ * a styling difference; it is the safety contract inverting on the device most
16
+ * readers use. So `sheetBelow` is not implemented and is not a prop.
17
+ *
18
+ * What the sentence under it was complaining about is kept. "A modal window on
19
+ * a 360px screen is a sheet wearing the wrong clothes" is a complaint about
20
+ * SHAPE, and shape is free: at every width this dialog floats inset from all
21
+ * four edges of the screen and rounds all four of its corners, which is what
22
+ * `tokens/shape.json` publishes `radius-xl` for. It does that in CSS, with no
23
+ * prop, no measurement and no change of component, so a modal never wears a
24
+ * docked sheet's silhouette on a phone. The role, the focus trap, the treatment
25
+ * of the background and the dismissal rules are identical on a phone and on a
26
+ * desktop. A dialog never becomes something else.
27
+ *
28
+ * TWO ROOTS, NOT A FLAG. `severity` swaps `AlertDialog.Root` for `Dialog.Root`
29
+ * rather than toggling props on one of them. Base UI's alert-dialog root is the
30
+ * same store in a different mode: it forces `modal`, forces
31
+ * `disablePointerDismissal`, and sets `role="alertdialog"`. Those are three
32
+ * behaviours the specification requires together, arriving together, with no
33
+ * way for a caller or a later refactor to get two of the three. Faking it with
34
+ * `disablePointerDismissal` on the ordinary root would produce a
35
+ * non-dismissing surface still announced as a plain dialog, which is the
36
+ * failure that looks correct in review.
37
+ *
38
+ * ESCAPE IS THE ONE PART BASE UI DOES NOT DO FOR US, AND THIS FILE ANSWERS IT.
39
+ * `useDialogRoot` passes `escapeKey: isTopmost` to `useDismiss` in every mode,
40
+ * alert-dialog included, so an untouched alert dialog closes on Escape and the
41
+ * whole contract is lost on the keyboard. This file cancels that close through
42
+ * the change event's own `cancel()`, so the dialog stays in every
43
+ * configuration, and then moves focus to the popup element itself.
44
+ *
45
+ * Moving focus to the popup is what makes the refusal audible. The popup
46
+ * carries `tabindex=-1`, `role="alertdialog"`, `aria-labelledby` the title and
47
+ * `aria-describedby` the description, so landing focus on it re-announces the
48
+ * question and its consequence on every screen reader, with no live region
49
+ * mounted on the caller's behalf. It fires in the default configuration too,
50
+ * where `initialFocus="safest"` has already put focus on the safest action:
51
+ * the popup is never the element that already has focus, so the announcement
52
+ * happens rather than being the specification no-op that focusing the already
53
+ * focused action would be.
54
+ *
55
+ * Two candidate repairs stay rejected. Focusing the FIRST action points the
56
+ * key at the control that changes something, and a live region is banned
57
+ * outright, because a component never mounts one on the caller's behalf.
58
+ * `patterns/alert-escalation.mdx` asks for the reason to be announced, and the
59
+ * popup's own role and labelling are how that is done here. What the component
60
+ * still does not do is write the product's own sentence about why an answer is
61
+ * needed: those are the product's words, they belong in `description`, and a
62
+ * development warning asks for them.
63
+ *
64
+ * IT IS A CLIENT COMPONENT, and three refs are why. `initialFocus` has to
65
+ * resolve to an ELEMENT, because Base UI takes a ref or a function, never a
66
+ * string: `actionsRef` finds the last control in the actions slot, which is
67
+ * what `initialFocus="safest"` means, and `contentRef` finds the first
68
+ * focusable in the body, which is what `initialFocus="content"` means.
69
+ * `popupRef` is the third, and it is what a refused Escape and a refused scrim
70
+ * press move focus to. Nothing else here is stateful: there is no width
71
+ * observation, no media query listener and no measurement, because the
72
+ * responsive behaviour is a stylesheet's job.
73
+ *
74
+ * WHAT IT DOES NOT DO. It does not move focus on appearance beyond the one
75
+ * placement Base UI performs on open, does not mount a live region, does not
76
+ * animate anything a reader has asked not to see, and does not know what any of
77
+ * its actions do. It renders no measurement, carries no clinical level, and
78
+ * stamps neither `data-status` nor `data-category`.
79
+ */
80
+ import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
81
+ import { Dialog as DialogPrimitive, } from "@base-ui/react/dialog";
82
+ import { X } from "lucide-react";
83
+ import { useEffect, useRef } from "react";
84
+ import { isDevelopment } from "../opsinjs.js";
85
+ import { cn } from "../utils.js";
86
+ import { Surface } from "./surface.js";
87
+ /**
88
+ * What counts as somewhere focus can be put.
89
+ *
90
+ * Deliberately does NOT exclude `[aria-disabled="true"]`. That is how this
91
+ * system spells a control which is busy rather than unavailable. A Button
92
+ * saving a change keeps its tab stop and its name on purpose, and skipping it
93
+ * would send initial focus past the control the reader is waiting on.
94
+ *
95
+ * The popup itself carries `tabindex="-1"` from Base UI so that a touch screen
96
+ * reader can land on it, and the final clause is what keeps this selector from
97
+ * treating that as an answer.
98
+ */
99
+ const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),' +
100
+ 'textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
101
+ /**
102
+ * Development warnings, said once per offending call site.
103
+ *
104
+ * `tokens/errors.json` states the policy: development only, once per offending
105
+ * call site, through `console.warn`. Every warning in this file is in a render
106
+ * body or in an effect keyed on a `ReactNode`, which is the shape that repeats.
107
+ * A dialog wrapped around a short form re-renders on every keystroke
108
+ * and the same two paragraphs printed on every pass, twice more again under
109
+ * Strict Mode; the effect below was worse still, because `actions` is a fresh
110
+ * identity on every parent render. A channel somebody filters is a channel that
111
+ * no longer carries the one finding they needed, and this file's warnings are
112
+ * about a reader who cannot leave a modal surface.
113
+ *
114
+ * It is a module-local set rather than the substrate's `warnOnce` for the reason
115
+ * the block at the call sites gives: `warnOnce` is keyed to an `OpsinErrorCode`,
116
+ * and none of these interface defects has a code allocated. The key names the
117
+ * offence first and the dialog second, so an empty `title` still dedupes.
118
+ */
119
+ const warned = new Set();
120
+ function warnDev(key, message) {
121
+ if (!isDevelopment() || warned.has(key))
122
+ return;
123
+ warned.add(key);
124
+ console.warn(message);
125
+ }
126
+ /**
127
+ * The first or the last place focus can go inside a region.
128
+ *
129
+ * `last` is the one that matters and it is not an arbitrary end of the row. The
130
+ * page's own worked example orders its actions **[Delete reading] [Keep it]**
131
+ * and then puts initial focus on *Keep it*. That is the action that changes
132
+ * nothing, at the end. So the rule this component states, and the page repeats,
133
+ * is that the action which changes something comes first and the safest one
134
+ * comes last, and the last is where focus lands. A reader who presses Return
135
+ * without reading gets the answer that does nothing, which is what "defaults
136
+ * should be safe" means in a component rather than in a sentence.
137
+ */
138
+ function focusableIn(region, which) {
139
+ if (region === null) {
140
+ return null;
141
+ }
142
+ const found = region.querySelectorAll(FOCUSABLE);
143
+ return (which === "first" ? found[0] : found[found.length - 1]) ?? null;
144
+ }
145
+ /**
146
+ * The shape, and why it no longer changes with the viewport.
147
+ *
148
+ * `tokens/shape.json` publishes `radius-xl` as "sheets and dialogs", with the
149
+ * qualifier that it is "applied to the leading edge only when the surface meets
150
+ * a screen edge on the other side". A sheet meets that edge and takes the
151
+ * radius on its leading edge alone. A dialog does not. It floats inset from all
152
+ * four screen edges at every width, phone included, so it takes the radius on
153
+ * all four corners everywhere. That inset is the point. The family doctrine
154
+ * holds that a dialog and a sheet differ by obligation rather than by size, and
155
+ * the four-sided margin together with the four-sided radius is what a reader
156
+ * sees that difference in. A dialog that docked to the bottom edge would wear a
157
+ * sheet's silhouette and lose the one cue that tells a question you must answer
158
+ * apart from a place you may leave.
159
+ *
160
+ * `corner-shape` is a property here rather than the product theme's
161
+ * `data-opsin-shape="squircle"` attribute, for the reason Card gives: the
162
+ * attribute would be a fifth member of a data-attribute vocabulary closed at
163
+ * four, and a rule that reads it would have to live in the opt-in
164
+ * `@opsinjs/react/base.css`, which somebody else's app may never load. An
165
+ * engine without `corner-shape` draws an ordinary rounded corner, which every
166
+ * radius on the ladder is chosen to survive.
167
+ */
168
+ const SHAPE = "rounded-opsin-xl [corner-shape:var(--opsin-corner-shape)]";
169
+ /**
170
+ * The entrance and the exit, and what a reader who asked for less motion gets
171
+ * instead of nothing.
172
+ *
173
+ * The entrance is the dialog's own token pair: `spring-sheet` on its own
174
+ * duration, which is the overdamped curve `tokens/motion.json` publishes for
175
+ * "sheets, dialogs, full-screen pushes". A spring's `linear()` stop list runs
176
+ * from 0 to 1 whatever the spring, so its curve is never crossed with another
177
+ * duration, because that makes a different spring rather than a faster one. The
178
+ * exit takes `ease-exit` on `--opsin-duration-base`, because something leaving
179
+ * accelerates and is shorter than its arrival. The `data-[ending-style]:` pair
180
+ * outranks the base pair on specificity, and both halves move together so the
181
+ * easing is never left behind on the 483ms spring duration.
182
+ *
183
+ * Under reduced motion the transition is NOT removed, and that is a correction
184
+ * of an earlier version that removed it and argued the case in a comment.
185
+ * `health/motion-in-health-ui.mdx` lists this surface's family by name, and its
186
+ * rule 5 says the reduced-motion fallback "is not 'no animation' by default. It
187
+ * is an instant, complete, equally informative state", with a Do of "show the
188
+ * sheet in place with a crossfade of opacity only". So the distance goes and
189
+ * the transition stays: `motion-reduce:transition-opacity` switches the
190
+ * transitioned property to opacity alone, and the phone's travel and the wide
191
+ * screen's scale are pinned to their resting values under the query. A modal
192
+ * that appears between frames trades a vestibular problem for a comprehension
193
+ * one, and the reader most likely to have reduced motion on is the one least
194
+ * able to afford a surface arriving from nowhere.
195
+ *
196
+ * The 120ms of the crossfade is the token layer's, not this file's.
197
+ * `@opsinjs/tokens/tokens.css` collapses `--opsin-duration-spring-sheet` to
198
+ * 120ms and `--opsin-ease-spring-sheet` to `linear` under the query, so the
199
+ * duration and the easing are deliberately not restated here. A consumer whose
200
+ * app does not load that stylesheet loses only the 120ms figure, because the
201
+ * duration is a token; the crossfade itself still happens, because the
202
+ * transition is no longer removed. Depth is then carried by the scrim and by
203
+ * the surface's edge, which is why the specification makes neither optional and
204
+ * why no prop removes them.
205
+ *
206
+ * THE TRAVEL IS A FIXED DISTANCE AND THE SCALE IS A BARE NUMBER, ON PURPOSE.
207
+ * The phone entrance moves the panel by `--opsin-space-4`, a fixed 1rem,
208
+ * written as an arbitrary `translate-y-[var(--opsin-space-4,1rem)]` rather than
209
+ * as `translate-y-4`. The utility form resolved through `--spacing`, which the
210
+ * density attribute scales, so a reader on a denser setting got a shorter
211
+ * entrance for no reason a reader could name: how far a surface travels to
212
+ * arrive is not a function of how tightly that reader packs their lists, and
213
+ * the travel is now identical at every density. The literal fallback rides
214
+ * along because the token sheet reaches a page only when the app imports it.
215
+ *
216
+ * The wide-screen `scale-95` stays a bare number and is NOT promoted to a
217
+ * token, which is a deliberate departure from the audit's proposed
218
+ * entrance-distance token. `sheet.tsx` settled this in argued prose: the token
219
+ * layer cannot know the DISTANCE or the scale a particular surface should
220
+ * enter by, because that is not a token but the component's own answer. And the
221
+ * scale was never the defect the raw-value finding was really about: Tailwind's
222
+ * scale utilities emit a percentage rather than a multiple of `--spacing`, so
223
+ * `scale-95` is already density-independent and needs no repair. Only the
224
+ * travel was density-coupled, and only the travel changed.
225
+ */
226
+ const MOTION = cn("transition-[opacity,translate,scale] duration-(--opsin-duration-spring-sheet) ease-opsin-spring-sheet", "data-[ending-style]:ease-opsin-exit data-[ending-style]:duration-(--opsin-duration-base)", "motion-reduce:transition-opacity", "data-[starting-style]:opacity-0 data-[ending-style]:opacity-0", "data-[starting-style]:translate-y-[var(--opsin-space-4,1rem)] data-[ending-style]:translate-y-[var(--opsin-space-4,1rem)]", "motion-reduce:data-[starting-style]:translate-y-0 motion-reduce:data-[ending-style]:translate-y-0", "sm:data-[starting-style]:translate-y-0 sm:data-[ending-style]:translate-y-0", "sm:data-[starting-style]:scale-95 sm:data-[ending-style]:scale-95", "motion-reduce:sm:data-[starting-style]:scale-100 motion-reduce:sm:data-[ending-style]:scale-100");
227
+ export function Dialog({ open, onOpenChange, title, description, severity = "default", closeLabel = "Close", initialFocus = "safest", actions, children, className, }) {
228
+ const contentRef = useRef(null);
229
+ const actionsRef = useRef(null);
230
+ const popupRef = useRef(null);
231
+ const nonDismissing = severity === "alert";
232
+ /* A blank string is an absence, not a description. `title` has had this
233
+ treatment since the first version and `description` had only an
234
+ `undefined` check, which meant `description=""` on an alert dialog raised
235
+ no warning and then wired an EMPTY `aria-describedby` onto the popup. That
236
+ is a surface with no close control, a refused Escape key and nothing
237
+ announced about why either of those is true. Absence and emptiness are the
238
+ same thing to a reader, so they are the same thing here. */
239
+ const hasDescription = description !== undefined && description.trim() !== "";
240
+ /* Development-only, and none of these is an OPSIN code. `tokens/errors.json`
241
+ allocates codes for mistakes a consumer makes with the CLINICAL API, and a
242
+ component may not mint one, because that table is generated from that file
243
+ and the codes are a versioned contract. Those mistakes are a status
244
+ without a word, a range without a source. These, and the effect below them,
245
+ are ordinary interface defects, reported in the ordinary channel.
246
+
247
+ They all render anyway. A dialog is already on screen and already holding
248
+ the reader's focus by the time any of this is true; taking it away to
249
+ report a mistake would leave a reader stranded mid-decision. */
250
+ if (title.trim() === "") {
251
+ warnDev("title-empty", "[opsinjs] <Dialog> was given an empty `title`. The title is the " +
252
+ "dialog's accessible name, so without it the surface is announced as " +
253
+ '"dialog" and nothing else, and a reader arriving by screen reader is ' +
254
+ "told that something has taken over without being told what.");
255
+ }
256
+ if (nonDismissing && actions === undefined) {
257
+ warnDev(`alert-no-actions:${title}`, '[opsinjs] <Dialog severity="alert"> has no `actions`. An alert dialog ' +
258
+ "has no close control, its scrim does not dismiss and Escape does not " +
259
+ "close it, so its actions are the only way out of it. One with none is " +
260
+ "a surface a reader cannot leave. Either give it the answers it is " +
261
+ 'asking for, or use severity="default", where going away is a valid ' +
262
+ "outcome.");
263
+ }
264
+ if (nonDismissing && !hasDescription) {
265
+ warnDev(`alert-no-description:${title}`, '[opsinjs] <Dialog severity="alert"> has no `description`. On an alert ' +
266
+ "dialog the description is where the reader is told that an answer is " +
267
+ "needed and what each answer does. Escape will not let them out, and " +
268
+ "this component will not write that sentence on your behalf, because " +
269
+ "the words belong to the product that knows what the answers mean.");
270
+ }
271
+ /* THE SECOND HALF OF THE ALERT-DIALOG WARNING, AND IT HAS TO RUN AFTER THE
272
+ DOM EXISTS.
273
+
274
+ The check above catches `actions={undefined}` and nothing else, because at
275
+ render time that is all it can see. `actions` is a `ReactNode`: `null`,
276
+ `false`, `""` and `<></>` are every one of them legal, every one of them
277
+ not `undefined`, and every one of them renders an actions row with nothing
278
+ focusable in it. On an alert dialog that is a modal surface with no close
279
+ control, a scrim that does not dismiss, an Escape key that is refused and
280
+ nothing at all to press. That is the outcome the warning above describes
281
+ in words and, until this effect existed, did not report.
282
+
283
+ The ref is what makes the check possible: `React.Children.count` cannot see
284
+ through a fragment, and it cannot see a control a caller rendered
285
+ conditionally either. The ref sees the DOM, which is the thing the reader
286
+ is stuck in. It renders anyway, for the reason above: a dialog already
287
+ holding somebody's focus is not made safer by being unmounted.
288
+
289
+ AND IT IS DEFERRED A FRAME, WHICH IS THE WHOLE DIFFERENCE BETWEEN A GUARD
290
+ AND A LIAR. Read on the render where `open` flips true, `actionsRef.current`
291
+ is still null: the popup lives in a portal Base UI has not mounted yet, so
292
+ the check reported "nothing focusable" against a row that had not been
293
+ built. The dependency array never changes again after that, so the verdict
294
+ stood for the life of the dialog. It was wrong on this repository's own
295
+ alert-dialog example, where two buttons are present and Tab cycles between
296
+ them. A developer who is told their reader is trapped, opens the dialog and
297
+ finds two working answers learns that this warning lies, which costs more
298
+ than the warning was ever worth. One frame is enough: Base UI has portalled
299
+ the popup and placed initial focus by then, through the same
300
+ `focusableIn(actionsRef.current, "last")` call `resolveInitialFocus` makes.
301
+ The frame is cancelled on cleanup so a dialog closed or unmounted inside it
302
+ never reads a torn-down ref. */
303
+ useEffect(() => {
304
+ if (!isDevelopment() || !open || !nonDismissing || actions === undefined) {
305
+ return;
306
+ }
307
+ const frame = requestAnimationFrame(() => {
308
+ if (focusableIn(actionsRef.current, "last") === null) {
309
+ warnDev(`alert-actions-empty:${title}`, '[opsinjs] <Dialog severity="alert"> was given `actions` with nothing ' +
310
+ "focusable inside it. An alert dialog has no close control, its scrim " +
311
+ "does not dismiss and Escape does not close it, so its actions are the " +
312
+ "only way out. An empty row, a `null`, a `false` or a fragment " +
313
+ "with no controls in it is a surface a reader cannot leave at all. " +
314
+ 'Give it the answers it is asking for, or use severity="default", ' +
315
+ "where going away is a valid outcome.");
316
+ }
317
+ });
318
+ return () => {
319
+ cancelAnimationFrame(frame);
320
+ };
321
+ }, [open, nonDismissing, actions, title]);
322
+ /**
323
+ * Base UI takes a ref, `true`, `false`, or a function returning an element.
324
+ * There is no string form, so the two values this component publishes are
325
+ * resolved here, at open time, when the popup and its parts are in the DOM.
326
+ *
327
+ * Falling back to `true` rather than to `false` is the safe direction: `true`
328
+ * is Base UI's own behaviour, which puts focus on the first tabbable element
329
+ * inside the popup, and `false` would leave focus outside a surface that has
330
+ * hidden everything outside it from assistive technology and holds the tab
331
+ * ring inside itself.
332
+ *
333
+ * BUT `true` IS NOT SAFE ENOUGH TO REACH DIRECTLY FROM `content`, which is
334
+ * why the chain below has three links rather than two. `children` may be
335
+ * absent, in which case the content div is never rendered and the ref is
336
+ * null; or it may hold nothing focusable. Either way the old fallback landed
337
+ * on `true`, Base UI resolved that to the first tabbable element in the
338
+ * popup, and an alert dialog has no close control. So the first tabbable
339
+ * element in one is the FIRST action, which this component's own ordering
340
+ * rule reserves for the answer that changes something. A stray Return then
341
+ * did the destructive thing, on the path the props documentation said could
342
+ * not happen. Falling through the safest action first makes the sentence
343
+ * true in every branch instead of in the common one.
344
+ */
345
+ function resolveInitialFocus() {
346
+ if (initialFocus === "content") {
347
+ return (focusableIn(contentRef.current, "first") ??
348
+ focusableIn(actionsRef.current, "last") ??
349
+ true);
350
+ }
351
+ return focusableIn(actionsRef.current, "last") ?? true;
352
+ }
353
+ /**
354
+ * THE ESCAPE KEY, WHICH IS THE ONLY PLACE THIS COMPONENT OVERRULES THE
355
+ * PRIMITIVE.
356
+ *
357
+ * `useDialogRoot` passes `escapeKey: isTopmost` to `useDismiss` in every mode,
358
+ * so Base UI's alert dialog closes on Escape exactly like an ordinary one.
359
+ * `DialogStore.setOpen` calls this handler first and returns early when
360
+ * `eventDetails.isCanceled`, which is what makes `cancel()` a refusal rather
361
+ * than a request.
362
+ *
363
+ * Cancelling on its own would make the key do nothing at all, and the
364
+ * specification is explicit that the dialog "does not simply swallow the
365
+ * key". So focus moves to the popup element itself. The popup carries
366
+ * `tabindex=-1`, `role="alertdialog"`, `aria-labelledby` the title and
367
+ * `aria-describedby` the description, so moving focus onto it makes every
368
+ * screen reader re-announce the title and the description without this
369
+ * component mounting a live region of its own. That is the response the
370
+ * pattern page asks for: the reason the dialog is still here is spoken
371
+ * again, rather than the key silently doing nothing.
372
+ *
373
+ * Focusing the safest action was the old move, and in the default
374
+ * configuration it was silent: `initialFocus="safest"` has already put focus
375
+ * on the last action, so focusing it again focuses the element that already
376
+ * has focus, which the DOM specification defines as doing nothing. The popup
377
+ * is never the element that already has focus, so the announcement fires in
378
+ * every configuration.
379
+ *
380
+ * The cost is named rather than hidden. Focus leaves the safest action and
381
+ * lands on the container, so a reader who then presses Return activates
382
+ * nothing, and one Tab returns them to the first action. The safest action
383
+ * stays the INITIAL focus: `initialFocus={resolveInitialFocus}` is
384
+ * unchanged, so opening the dialog still lands on the answer that changes
385
+ * nothing. Only a refused Escape moves focus to the container.
386
+ *
387
+ * It is not a sentence, and it was never meant to be one. The sentence
388
+ * lives in `description`, in the product's own words, and the popup's
389
+ * `aria-describedby` is what points a screen reader back at it.
390
+ */
391
+ function handleOpenChange(next, details) {
392
+ if (!next && nonDismissing && details.reason === "escape-key") {
393
+ details.cancel();
394
+ popupRef.current?.focus({ preventScroll: true });
395
+ return;
396
+ }
397
+ onOpenChange(next);
398
+ }
399
+ const hasBody = hasDescription || children !== undefined;
400
+ /* The whole tree below the root, written once. The root is the only thing
401
+ `severity` changes, and building the body separately is what keeps that
402
+ true: there is no branch inside here that could drift between the two
403
+ modes, so the alert dialog is the ordinary dialog minus its close control
404
+ and nothing else. */
405
+ const body = (_jsxs(DialogPrimitive.Portal, { "data-slot": "dialog", children: [_jsx(DialogPrimitive.Backdrop, { "data-slot": "dialog-scrim", className: cn("fixed inset-0", "transition-opacity duration-(--opsin-duration-base) ease-opsin-standard", "motion-reduce:transition-none", "data-[starting-style]:opacity-0 data-[ending-style]:opacity-0"),
406
+ /* A REFUSED SCRIM PRESS KEEPS FOCUS INSIDE THE ALERT DIALOG, and this
407
+ is handled here rather than in `handleOpenChange` because there is no
408
+ change event to answer. `useDialogRoot.mjs:34-69` gates `outsidePress`
409
+ on `isTopmost && !disablePointerDismissal`, and the alert-dialog root
410
+ forces `disablePointerDismissal`, so the predicate returns false, Base
411
+ UI raises no `open` change for a scrim press and there is no refusal
412
+ branch to hook. What the press still does is blur the focused control
413
+ to `body`, leaving the reader's focus outside a modal whose siblings
414
+ are `aria-hidden`, so a screen reader's cursor is on an element the
415
+ tree says is gone. `preventDefault` on `pointerdown` is what stops
416
+ that blur in the first place; the click handler then puts focus back
417
+ on the popup for an engine that focuses on click regardless. The
418
+ popup carries `tabindex=-1`, `role=alertdialog` and its labelling, so
419
+ landing focus on it re-announces the reason the dialog is still here,
420
+ the same recovery the escape-key refusal makes. Both handlers are
421
+ `undefined` on an ordinary dialog, whose scrim press is a valid
422
+ dismissal that closes it and returns focus to its trigger. */
423
+ onPointerDown: nonDismissing
424
+ ? (event) => {
425
+ event.preventDefault();
426
+ }
427
+ : undefined, onClick: nonDismissing
428
+ ? () => {
429
+ popupRef.current?.focus({ preventScroll: true });
430
+ }
431
+ : undefined, children: _jsx(Surface, { rung: "scrim", className: "absolute inset-0", children: null }) }), _jsx(DialogPrimitive.Viewport, { "data-slot": "dialog-viewport", className: cn("pointer-events-none fixed inset-0 flex items-end justify-center px-opsin-4 pt-opsin-16", "pb-[max(var(--opsin-space-4,1rem),var(--opsin-safe-bottom,0px))]", "sm:items-center sm:p-opsin-6"), children: _jsx(DialogPrimitive.Popup, { "data-slot": "dialog-container", ref: popupRef, initialFocus: resolveInitialFocus, className: cn("pointer-events-auto flex max-h-full w-full flex-col overflow-hidden", "sm:max-w-(--opsin-measure-tight,45ch)", SHAPE, MOTION, className), children: _jsxs(Surface, { rung: "sheet", className: cn(
432
+ /* THE RUNG IS `sheet`, AND `overlay` IS WHAT A READER OF AN OLDER
433
+ DESIGN FILE WILL EXPECT HERE. ADR 0014 made
434
+ the six rung names the token names, and the retired vocabulary
435
+ the specification was written in put `overlay` on the rung that
436
+ covers the page while leaving it recognisable. That rung is now
437
+ called `sheet`. This ladder's `overlay` is chrome that content
438
+ scrolls beneath, and it is the rung for a pinned toolbar or a
439
+ tab bar. So mapping the old name by spelling rather than by
440
+ job would put a modal dialog on the rung built for a tab bar,
441
+ and it would compile. */
442
+ "flex min-h-0 flex-col rounded-[inherit]",
443
+ /* No safe-area inset on the Surface any more. It was there to make
444
+ a docked surface's material reach under the home indicator,
445
+ because Surface's three decorative layers are positioned to
446
+ `inset-0` so the fill and the edge stopped above the indicator
447
+ otherwise. This dialog floats inset from every screen edge, so
448
+ it never meets the bottom edge and never covers the home
449
+ indicator in the first place. The viewport's bottom inset holds
450
+ the whole card clear of it instead. */
451
+ /* Surface owns its content wrapper, so the column that holds the
452
+ three regions has to be declared from out here. Without the
453
+ `min-h-0` the wrapper refuses to shrink below its content and
454
+ the scroll region below never gets a height to scroll in. */
455
+ "[&>[data-slot=surface-content]]:flex", "[&>[data-slot=surface-content]]:min-h-0", "[&>[data-slot=surface-content]]:flex-col"), children: [_jsxs("div", { "data-slot": "dialog-header", className: cn(
456
+ /* The dialog insets use the fixed px-opsin-5 token here and in
457
+ the body and footer below, deliberately, so they hold 20px at
458
+ every [data-density] setting rather than tracking the
459
+ density-scaled p-5 that Card uses. A modal takes its measure
460
+ from the viewport, not from the surrounding document, and a
461
+ reader who asks for a denser list has not asked to shrink the
462
+ only exit from a destructive confirmation. This is why Dialog
463
+ is not among the surfaces moved onto the scaled scale. */
464
+ "flex shrink-0 items-start gap-opsin-3 px-opsin-5 pt-opsin-5",
465
+ /* THE HEADER RESERVES ONE HEIGHT FOR BOTH SEVERITIES, so the
466
+ description starts at the same offset whether or not a close
467
+ control is rendered. Without this floor an ordinary dialog's
468
+ header was the close control's target height plus the top
469
+ inset while an alert dialog's was only its title, so the same
470
+ component looked looser or tighter by the height of the
471
+ control the reader could not even see, which is a difference
472
+ they have no reason to meet. The floor is the top inset
473
+ (`space-5`) plus one close target (`target-minimum`) less the
474
+ `space-2` the control overhangs upward, which is exactly the
475
+ room the lifted control below occupies, so the two numbers
476
+ move together and must stay in step: change the control's
477
+ `-mt-opsin-2` and this term follows it. The calc is spelled
478
+ in tokens rather than in one measured constant so a later
479
+ change to any of the three tracks the header, and each `var`
480
+ carries its own literal fallback for the reason the close
481
+ control's floor argues, because the properties live only in
482
+ `@opsinjs/tokens/tokens.css`, which reaches a page only when
483
+ the app imports it, and a bare reference to an undeclared one
484
+ is invalid at computed-value time. */
485
+ "min-h-[calc(var(--opsin-space-5,1.25rem)_+_var(--opsin-target-minimum,2.75rem)_-_var(--opsin-space-2,0.5rem))]",
486
+ /* Every region below this one pads its own foot, so the header
487
+ only pads its own when it is the last thing in the dialog.
488
+ That is a title with no consequence, no content and no
489
+ answer, which is a degenerate dialog rather than an
490
+ impossible one. */
491
+ hasBody || actions !== undefined ? null : "pb-opsin-5"), children: [_jsx(DialogPrimitive.Title, { "data-slot": "dialog-title", className: "m-0 min-w-0 flex-1 wrap-break-word text-opsin-title3", children: title }), nonDismissing ? null : (_jsxs(DialogPrimitive.Close, { "data-slot": "dialog-close",
492
+ /* JOINED, NOT run through cn, and the join is the fix rather
493
+ than a style, the same one sheet.tsx makes and for the same
494
+ reason. `cn` is `twMerge(clsx(…))` and tailwind-merge is
495
+ unconfigured: it has never been told that `--text-opsin-*`
496
+ is a font-size namespace, so it files `text-opsin-callout`
497
+ and `text-foreground` in the SAME conflict group and
498
+ keeps only the later one, which silently costs this control
499
+ its type step. The two utilities set different CSS
500
+ properties, so passing both through applies both. There is
501
+ no caller `className` on this control, so nothing is lost by
502
+ not merging. */
503
+ className:
504
+ /* THE LIFT AND THE PULL align the control's ink to the
505
+ title rather than to the corner of its own hit box. The
506
+ control is a 44px target with its content centred, so
507
+ top-aligned in the header its word and glyph sit below the
508
+ title's first line by half the difference between the
509
+ target and the title's line box. `-mt-opsin-2` raises the
510
+ hit box into the top inset so the centred ink shares the
511
+ title's first-line band, and the header's own floor above
512
+ is written to expect exactly this overhang. `-mr-opsin-2`
513
+ cancels the control's own `px-opsin-2`, so the ink meets
514
+ the same inset from the panel edge that the title keeps on
515
+ the other side rather than sitting a control's padding
516
+ further in. The 44px hit area is unchanged: the negative
517
+ margins move the box, not its size. */
518
+ "-mt-opsin-2 -mr-opsin-2 " +
519
+ "inline-flex shrink-0 items-center justify-center gap-opsin-1 rounded-opsin-sm px-opsin-2 " +
520
+ /* The word rides beside the glyph at the `callout` step in
521
+ the full foreground role, which is the recipe Sheet moved
522
+ to. Footnote in a muted grey made this word the smallest,
523
+ lowest-contrast thing on the surface, and that role's
524
+ declared use is provenance rather than a control. It stays
525
+ quieter than the footer's primary action and is not raised
526
+ to Button's `headline` step, so a reader who learned Close
527
+ on a sheet meets the same weight on the one surface that
528
+ decides whether a reading is deleted. The hover feedback is
529
+ a muted background rather than an ink change, because the
530
+ ink is already the foreground. */
531
+ "text-opsin-callout text-foreground " +
532
+ /* The floor is carried by the control rather than by the
533
+ backstop in `@opsinjs/react/base.css`, because that
534
+ stylesheet is opt-in. It is a rem, so at 200% text it
535
+ doubles with the glyph instead of pinning at 44 device
536
+ pixels.
537
+
538
+ The `2.75rem` inside the `var()` is the same argument one
539
+ step further in: `--opsin-target-minimum` is declared only
540
+ in `@opsinjs/tokens/tokens.css`, which reaches a page only
541
+ when the app imports it, and a bare reference to an
542
+ undeclared property is invalid at computed-value time.
543
+ `min-height` would revert to `auto` and this control, the
544
+ only exit from a modal surface, would lose its floor with
545
+ no error anywhere. */
546
+ "min-h-(--opsin-target-minimum,2.75rem) min-w-(--opsin-target-minimum,2.75rem) " +
547
+ /* It sinks when pressed, the press Button carries (ADR
548
+ 0031): down to 0.97 on pointer-down over
549
+ `duration-instant`, back on `spring-snap`. Hover alone
550
+ gave a touch reader nothing, and a tap on the way out of a
551
+ modal that shows no change reads as a tap that missed.
552
+ Under reduced motion both durations collapse to a frame. */
553
+ "transition-[color,background-color,scale] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
554
+ "active:scale-97 active:duration-(--opsin-duration-instant) active:ease-opsin-standard " +
555
+ "hover:bg-muted active:bg-muted " +
556
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", children: [_jsx(X, { "aria-hidden": "true", className: "size-[1em] shrink-0" }), closeLabel] }))] }), _jsxs("div", { "data-slot": "dialog-body", className: cn("min-h-0 overflow-y-auto overscroll-contain", hasBody ? "px-opsin-5 pt-opsin-2 pb-opsin-5" : null), children: [!hasDescription ? null : (
557
+ /* Plain foreground, not the muted role. A muted caption on a
558
+ translucent surface is the thing this system's own material
559
+ guidance tells products not to do, and the description is
560
+ where the consequence of each answer is written. That is
561
+ the last text on the screen that should be quiet.
562
+
563
+ `wrap-break-word` for the same reason the title carries it:
564
+ an account identifier or a URL in a consequence has no break
565
+ opportunity in it, and the popup clips rather than scrolls
566
+ horizontally. */
567
+ _jsx(DialogPrimitive.Description, { "data-slot": "dialog-description", className: "m-0 wrap-break-word text-opsin-body text-foreground", children: description })), children === undefined ? null : (_jsx("div", { "data-slot": "dialog-content", ref: contentRef, className: cn(description === undefined ? null : "mt-opsin-4"), children: children }))] }), actions === undefined ? null : (_jsx("div", { "data-slot": "dialog-actions", ref: actionsRef, className: cn("flex shrink-0 flex-col items-stretch gap-(--opsin-space-4,1rem)", "sm:flex-row sm:flex-wrap sm:items-center sm:justify-end px-opsin-5 pt-opsin-2 pb-opsin-5", "[&>*]:w-full sm:[&>*]:w-auto", "[&>*]:min-h-(--opsin-target-comfortable,3rem)"), children: actions }))] }) }) })] }));
568
+ if (nonDismissing) {
569
+ return (_jsx(AlertDialogPrimitive.Root, { open: open, onOpenChange: handleOpenChange, children: body }));
570
+ }
571
+ return (_jsx(DialogPrimitive.Root, { open: open, onOpenChange: handleOpenChange, children: body }));
572
+ }
573
+ //# sourceMappingURL=dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.js","sourceRoot":"","sources":["../../src/components/dialog.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAAE,WAAW,IAAI,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AACjF,OAAO,EACL,MAAM,IAAI,eAAe,GAE1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAA;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAA;AAEvC;;;;;;;;;;;GAWG;AACH,MAAM,SAAS,GACb,8EAA8E;IAC9E,0DAA0D,CAAA;AAE5D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;AAEhC,SAAS,OAAO,CAAC,GAAW,EAAE,OAAe;I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