@slashsuite/ui-react 0.12.1 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/MIGRATING.md +386 -8
  2. package/README.md +89 -44
  3. package/agent-docs/components/app-shell.md +9 -6
  4. package/agent-docs/components/article-layout.md +140 -0
  5. package/agent-docs/components/audio.md +42 -0
  6. package/agent-docs/components/badge.md +2 -1
  7. package/agent-docs/components/body-text.md +26 -15
  8. package/agent-docs/components/bottom-sheet.md +27 -17
  9. package/agent-docs/components/breadcrumbs.md +10 -6
  10. package/agent-docs/components/button.md +2 -2
  11. package/agent-docs/components/call-to-action.md +59 -0
  12. package/agent-docs/components/callout.md +4 -3
  13. package/agent-docs/components/card-grid.md +15 -7
  14. package/agent-docs/components/card.md +33 -18
  15. package/agent-docs/components/cart-button.md +63 -0
  16. package/agent-docs/components/chat-composer.md +4 -3
  17. package/agent-docs/components/checkbox.md +11 -5
  18. package/agent-docs/components/cluster.md +10 -8
  19. package/agent-docs/components/code-example.md +2 -2
  20. package/agent-docs/components/code.md +7 -5
  21. package/agent-docs/components/colour-scheme-toggle.md +12 -6
  22. package/agent-docs/components/colour-swatch.md +41 -0
  23. package/agent-docs/components/combobox.md +88 -0
  24. package/agent-docs/components/confirm-dialog.md +98 -0
  25. package/agent-docs/components/container.md +2 -1
  26. package/agent-docs/components/copy-button.md +7 -5
  27. package/agent-docs/components/copy-line.md +6 -5
  28. package/agent-docs/components/date-field.md +14 -11
  29. package/agent-docs/components/date-range-picker.md +16 -9
  30. package/agent-docs/components/date-time-field.md +73 -0
  31. package/agent-docs/components/dialog.md +22 -68
  32. package/agent-docs/components/disclosure.md +4 -0
  33. package/agent-docs/components/docs-layout.md +10 -6
  34. package/agent-docs/components/drawer.md +13 -4
  35. package/agent-docs/components/embed-frame.md +48 -0
  36. package/agent-docs/components/empty-state.md +4 -1
  37. package/agent-docs/components/field-dialog.md +6 -5
  38. package/agent-docs/components/field.md +10 -7
  39. package/agent-docs/components/fieldset.md +4 -4
  40. package/agent-docs/components/flow-diagram.md +87 -0
  41. package/agent-docs/components/form-layout.md +4 -1
  42. package/agent-docs/components/form-row.md +7 -7
  43. package/agent-docs/components/full-bleed-layout.md +0 -2
  44. package/agent-docs/components/headings.md +13 -7
  45. package/agent-docs/components/hero.md +11 -2
  46. package/agent-docs/components/icon-button.md +1 -3
  47. package/agent-docs/components/icon.md +6 -13
  48. package/agent-docs/components/image.md +24 -14
  49. package/agent-docs/components/input.md +8 -7
  50. package/agent-docs/components/key-value-list.md +4 -1
  51. package/agent-docs/components/lightbox.md +1 -1
  52. package/agent-docs/components/list-layout.md +5 -7
  53. package/agent-docs/components/list-row.md +37 -34
  54. package/agent-docs/components/loading.md +2 -2
  55. package/agent-docs/components/markdown.md +13 -13
  56. package/agent-docs/components/media-tile.md +8 -4
  57. package/agent-docs/components/menu.md +19 -12
  58. package/agent-docs/components/meta-list.md +2 -2
  59. package/agent-docs/components/morph.md +11 -5
  60. package/agent-docs/components/navigation-progress.md +2 -2
  61. package/agent-docs/components/number-field.md +75 -0
  62. package/agent-docs/components/outline-region.md +19 -8
  63. package/agent-docs/components/page-fade.md +2 -1
  64. package/agent-docs/components/pill.md +7 -6
  65. package/agent-docs/components/popover.md +63 -0
  66. package/agent-docs/components/price.md +49 -0
  67. package/agent-docs/components/product-tile.md +78 -0
  68. package/agent-docs/components/promo-banner.md +46 -0
  69. package/agent-docs/components/prose-layout.md +1 -1
  70. package/agent-docs/components/radio-group.md +9 -6
  71. package/agent-docs/components/scroll-strip.md +3 -3
  72. package/agent-docs/components/segmented-control.md +4 -2
  73. package/agent-docs/components/select.md +8 -3
  74. package/agent-docs/components/show.md +2 -2
  75. package/agent-docs/components/side-column.md +13 -9
  76. package/agent-docs/components/sidebar-layout.md +1 -1
  77. package/agent-docs/components/site-footer.md +4 -4
  78. package/agent-docs/components/site-search.md +21 -9
  79. package/agent-docs/components/slider.md +59 -0
  80. package/agent-docs/components/sortable-list.md +15 -10
  81. package/agent-docs/components/stack.md +3 -3
  82. package/agent-docs/components/stacked-bar.md +7 -4
  83. package/agent-docs/components/state-machine.md +95 -0
  84. package/agent-docs/components/status-pages.md +13 -6
  85. package/agent-docs/components/stepper.md +54 -0
  86. package/agent-docs/components/switch.md +4 -4
  87. package/agent-docs/components/table-of-contents.md +78 -0
  88. package/agent-docs/components/table.md +35 -24
  89. package/agent-docs/components/tabs.md +24 -26
  90. package/agent-docs/components/text-link.md +12 -7
  91. package/agent-docs/components/textarea.md +4 -2
  92. package/agent-docs/components/toast.md +19 -14
  93. package/agent-docs/components/video.md +7 -2
  94. package/agent-docs/llms.txt +22 -3
  95. package/dist/AppShell.d.ts +25 -9
  96. package/dist/AppShell.js +67 -33
  97. package/dist/AppShellMenu.d.ts +31 -18
  98. package/dist/AppShellMenu.js +72 -45
  99. package/dist/ArticleLayout.d.ts +36 -0
  100. package/dist/ArticleLayout.js +27 -0
  101. package/dist/Audio.d.ts +16 -0
  102. package/dist/Audio.js +11 -0
  103. package/dist/Badge.d.ts +2 -1
  104. package/dist/Badge.js +3 -2
  105. package/dist/BottomSheet.d.ts +17 -6
  106. package/dist/BottomSheet.js +62 -11
  107. package/dist/Breadcrumbs.d.ts +8 -6
  108. package/dist/Breadcrumbs.js +17 -7
  109. package/dist/Button.d.ts +4 -2
  110. package/dist/Button.js +9 -87
  111. package/dist/CallToAction.d.ts +25 -0
  112. package/dist/CallToAction.js +17 -0
  113. package/dist/Callout.d.ts +2 -2
  114. package/dist/Callout.js +2 -2
  115. package/dist/Card.d.ts +88 -31
  116. package/dist/Card.js +55 -92
  117. package/dist/CardBody.d.ts +2 -0
  118. package/dist/CardBody.js +33 -3
  119. package/dist/CardGrid.d.ts +32 -4
  120. package/dist/CardGrid.js +42 -8
  121. package/dist/CardParts.d.ts +7 -1
  122. package/dist/CardParts.js +7 -2
  123. package/dist/CartButton.d.ts +33 -0
  124. package/dist/CartButton.js +18 -0
  125. package/dist/ChatComposer.d.ts +10 -4
  126. package/dist/ChatComposer.js +35 -13
  127. package/dist/Checkbox.d.ts +21 -3
  128. package/dist/Checkbox.js +66 -20
  129. package/dist/Chevron.js +1 -1
  130. package/dist/Cluster.d.ts +28 -15
  131. package/dist/Cluster.js +21 -4
  132. package/dist/Code.d.ts +15 -3
  133. package/dist/Code.js +23 -3
  134. package/dist/CodeBlock.d.ts +4 -4
  135. package/dist/CodeBlock.js +2 -2
  136. package/dist/CodeBody.d.ts +1 -1
  137. package/dist/CodeBody.js +4 -10
  138. package/dist/CodeExample.d.ts +1 -1
  139. package/dist/CodeExample.js +3 -2
  140. package/dist/ColourSchemeToggle.d.ts +21 -5
  141. package/dist/ColourSchemeToggle.js +15 -9
  142. package/dist/ColourSwatch.d.ts +15 -0
  143. package/dist/ColourSwatch.js +14 -0
  144. package/dist/Combobox.d.ts +42 -0
  145. package/dist/Combobox.js +43 -0
  146. package/dist/ConfirmDialog.d.ts +40 -0
  147. package/dist/ConfirmDialog.js +36 -0
  148. package/dist/Container.d.ts +3 -3
  149. package/dist/Container.js +1 -1
  150. package/dist/CopyButton.d.ts +8 -2
  151. package/dist/CopyButton.js +38 -28
  152. package/dist/CopyLine.d.ts +4 -2
  153. package/dist/CopyLine.js +4 -4
  154. package/dist/DateCalendar.d.ts +2 -0
  155. package/dist/DateCalendar.js +11 -9
  156. package/dist/DateField.d.ts +52 -21
  157. package/dist/DateField.js +73 -37
  158. package/dist/DateFieldCalendar.d.ts +12 -8
  159. package/dist/DateFieldCalendar.js +37 -18
  160. package/dist/DateRangePicker.d.ts +23 -3
  161. package/dist/DateRangePicker.js +10 -8
  162. package/dist/DateTimeField.d.ts +31 -0
  163. package/dist/DateTimeField.js +19 -0
  164. package/dist/Dialog.d.ts +42 -6
  165. package/dist/Dialog.js +50 -12
  166. package/dist/Disclosure.js +9 -1
  167. package/dist/DocsLayout.d.ts +13 -5
  168. package/dist/DocsLayout.js +11 -9
  169. package/dist/Drawer.d.ts +22 -7
  170. package/dist/Drawer.js +89 -8
  171. package/dist/EmbedFrame.d.ts +36 -0
  172. package/dist/EmbedFrame.js +18 -0
  173. package/dist/Field.d.ts +41 -4
  174. package/dist/Field.js +61 -25
  175. package/dist/FieldDialog.d.ts +8 -3
  176. package/dist/FieldDialog.js +19 -9
  177. package/dist/Fieldset.d.ts +3 -3
  178. package/dist/Fieldset.js +7 -9
  179. package/dist/FileDrop.js +2 -1
  180. package/dist/FlowDiagram.d.ts +92 -0
  181. package/dist/FlowDiagram.js +100 -0
  182. package/dist/FormRow.d.ts +6 -4
  183. package/dist/FormRow.js +11 -9
  184. package/dist/Hero.d.ts +30 -7
  185. package/dist/Hero.js +23 -9
  186. package/dist/Icon.d.ts +1 -1
  187. package/dist/Icon.js +1 -1
  188. package/dist/IconButton.js +1 -1
  189. package/dist/Image.d.ts +33 -9
  190. package/dist/Image.js +61 -16
  191. package/dist/Input.d.ts +1 -1
  192. package/dist/Input.js +4 -4
  193. package/dist/InputShell.d.ts +7 -0
  194. package/dist/InputShell.js +18 -3
  195. package/dist/KeyValueList.d.ts +2 -2
  196. package/dist/Lightbox.js +5 -3
  197. package/dist/ListRow.d.ts +4 -5
  198. package/dist/ListRow.js +36 -26
  199. package/dist/Mark.d.ts +10 -0
  200. package/dist/Mark.js +9 -0
  201. package/dist/Markdown.d.ts +18 -4
  202. package/dist/Markdown.js +176 -37
  203. package/dist/MediaTile.d.ts +9 -3
  204. package/dist/MediaTile.js +8 -4
  205. package/dist/Menu.d.ts +19 -8
  206. package/dist/Menu.js +13 -11
  207. package/dist/MetaList.d.ts +4 -3
  208. package/dist/MetaList.js +12 -4
  209. package/dist/Morph.d.ts +15 -1
  210. package/dist/Morph.js +70 -22
  211. package/dist/NavigationProgress.d.ts +2 -2
  212. package/dist/NavigationProgress.js +7 -5
  213. package/dist/NumberField.d.ts +66 -0
  214. package/dist/NumberField.js +68 -0
  215. package/dist/OutlineRegion.d.ts +41 -10
  216. package/dist/OutlineRegion.js +31 -6
  217. package/dist/PageFade.d.ts +9 -5
  218. package/dist/PageFade.js +39 -8
  219. package/dist/PageLayouts.d.ts +15 -5
  220. package/dist/PageLayouts.js +3 -3
  221. package/dist/Pill.d.ts +9 -4
  222. package/dist/Pill.js +15 -6
  223. package/dist/Popover.d.ts +31 -0
  224. package/dist/Popover.js +43 -0
  225. package/dist/Price.d.ts +21 -0
  226. package/dist/Price.js +34 -0
  227. package/dist/ProductTile.d.ts +36 -0
  228. package/dist/ProductTile.js +31 -0
  229. package/dist/ProgressBar.js +4 -2
  230. package/dist/PromoBanner.d.ts +25 -0
  231. package/dist/PromoBanner.js +16 -0
  232. package/dist/RadioGroup.d.ts +18 -8
  233. package/dist/RadioGroup.js +42 -18
  234. package/dist/ScrollStrip.d.ts +1 -1
  235. package/dist/ScrollStrip.js +1 -1
  236. package/dist/SearchInput.d.ts +17 -2
  237. package/dist/SearchInput.js +72 -13
  238. package/dist/SegmentedField.d.ts +15 -0
  239. package/dist/SegmentedField.js +15 -0
  240. package/dist/Select.js +5 -4
  241. package/dist/Show.d.ts +1 -1
  242. package/dist/Show.js +1 -1
  243. package/dist/SideColumn.d.ts +42 -15
  244. package/dist/SideColumn.js +45 -19
  245. package/dist/SiteFooter.d.ts +3 -3
  246. package/dist/SiteFooter.js +4 -3
  247. package/dist/SiteSearch.d.ts +57 -27
  248. package/dist/SiteSearch.js +13 -93
  249. package/dist/Slider.d.ts +27 -0
  250. package/dist/Slider.js +58 -0
  251. package/dist/SortableList.d.ts +19 -35
  252. package/dist/SortableList.js +36 -88
  253. package/dist/Stack.d.ts +4 -4
  254. package/dist/StackedBar.d.ts +13 -4
  255. package/dist/StackedBar.js +12 -7
  256. package/dist/StateMachine.d.ts +65 -0
  257. package/dist/StateMachine.js +116 -0
  258. package/dist/StatusPages.d.ts +28 -10
  259. package/dist/StatusPages.js +10 -10
  260. package/dist/Stepper.d.ts +21 -0
  261. package/dist/Stepper.js +33 -0
  262. package/dist/Steps.js +4 -3
  263. package/dist/Switch.d.ts +3 -3
  264. package/dist/Switch.js +18 -14
  265. package/dist/Table.d.ts +32 -9
  266. package/dist/Table.js +50 -20
  267. package/dist/TableCells.d.ts +24 -21
  268. package/dist/TableCells.js +68 -27
  269. package/dist/TableEditCell.d.ts +1 -1
  270. package/dist/TableOfContents.d.ts +34 -0
  271. package/dist/TableOfContents.js +23 -0
  272. package/dist/Tabs.d.ts +31 -16
  273. package/dist/Tabs.js +97 -22
  274. package/dist/TextLink.d.ts +18 -5
  275. package/dist/TextLink.js +19 -6
  276. package/dist/Textarea.d.ts +12 -1
  277. package/dist/Textarea.js +15 -2
  278. package/dist/ToastRegion.d.ts +17 -9
  279. package/dist/ToastRegion.js +70 -13
  280. package/dist/Tooltip.d.ts +10 -2
  281. package/dist/Tooltip.js +32 -11
  282. package/dist/Video.d.ts +19 -4
  283. package/dist/Video.js +15 -5
  284. package/dist/cardContext.d.ts +7 -0
  285. package/dist/cardContext.js +14 -0
  286. package/dist/cardControl.d.ts +15 -0
  287. package/dist/cardControl.js +32 -0
  288. package/dist/cardForm.d.ts +39 -0
  289. package/dist/cardForm.js +81 -0
  290. package/dist/cardWait.js +2 -1
  291. package/dist/colourScheme.d.ts +12 -2
  292. package/dist/colourScheme.js +32 -6
  293. package/dist/control.d.ts +30 -8
  294. package/dist/control.js +74 -7
  295. package/dist/copyScript.d.ts +7 -8
  296. package/dist/copyScript.js +8 -9
  297. package/dist/core/button.d.ts +33 -0
  298. package/dist/core/button.js +89 -0
  299. package/dist/core/control.d.ts +15 -0
  300. package/dist/core/control.js +14 -0
  301. package/dist/core/fixtures/button.d.ts +26 -0
  302. package/dist/core/fixtures/button.js +52 -0
  303. package/dist/core/fixtures/types.d.ts +13 -0
  304. package/dist/core/fixtures/types.js +10 -0
  305. package/dist/core/focus.d.ts +7 -0
  306. package/dist/core/focus.js +7 -0
  307. package/dist/core/index.d.ts +12 -0
  308. package/dist/core/index.js +12 -0
  309. package/dist/core/parity.d.ts +22 -0
  310. package/dist/core/parity.js +53 -0
  311. package/dist/core/themeNative.d.ts +62 -0
  312. package/dist/core/themeNative.js +290 -0
  313. package/dist/cx.d.ts +17 -5
  314. package/dist/cx.js +18 -5
  315. package/dist/dateLocale.d.ts +17 -0
  316. package/dist/dateLocale.js +30 -0
  317. package/dist/density.d.ts +17 -3
  318. package/dist/density.js +30 -19
  319. package/dist/emptySlot.d.ts +1 -0
  320. package/dist/fieldAnnounce.d.ts +11 -0
  321. package/dist/fieldAnnounce.js +36 -0
  322. package/dist/fieldControl.d.ts +7 -2
  323. package/dist/fieldControl.js +6 -2
  324. package/dist/fieldWait.d.ts +3 -3
  325. package/dist/fieldWait.js +3 -4
  326. package/dist/flowLayout.d.ts +68 -0
  327. package/dist/flowLayout.js +105 -0
  328. package/dist/focus.d.ts +2 -0
  329. package/dist/focus.js +9 -0
  330. package/dist/fromXState.d.ts +73 -0
  331. package/dist/fromXState.js +110 -0
  332. package/dist/icons.d.ts +1 -1
  333. package/dist/icons.js +15 -0
  334. package/dist/index.d.ts +37 -11
  335. package/dist/index.js +24 -2
  336. package/dist/isoDate.d.ts +8 -1
  337. package/dist/isoDate.js +20 -1
  338. package/dist/labelWords.d.ts +16 -7
  339. package/dist/labelWords.js +14 -12
  340. package/dist/listRowProps.d.ts +17 -15
  341. package/dist/modal.d.ts +5 -0
  342. package/dist/modal.js +21 -1
  343. package/dist/navFold.js +6 -3
  344. package/dist/optionCard.d.ts +18 -0
  345. package/dist/optionCard.js +16 -0
  346. package/dist/scrollBody.d.ts +16 -0
  347. package/dist/scrollBody.js +15 -0
  348. package/dist/scrollEdges.d.ts +7 -0
  349. package/dist/scrollEdges.js +39 -5
  350. package/dist/scrollStop.d.ts +6 -2
  351. package/dist/scrollStop.js +24 -8
  352. package/dist/shownDate.d.ts +28 -10
  353. package/dist/shownDate.js +41 -22
  354. package/dist/siteSearchBody.d.ts +34 -0
  355. package/dist/siteSearchBody.js +117 -0
  356. package/dist/size.d.ts +7 -1
  357. package/dist/sortableDrop.d.ts +44 -0
  358. package/dist/sortableDrop.js +78 -0
  359. package/dist/sortableSlide.d.ts +9 -0
  360. package/dist/sortableSlide.js +70 -0
  361. package/dist/sortableTitle.d.ts +10 -0
  362. package/dist/sortableTitle.js +48 -0
  363. package/dist/stateMachineDots.d.ts +77 -0
  364. package/dist/stateMachineDots.js +188 -0
  365. package/dist/stickyColumn.d.ts +2 -2
  366. package/dist/stickyColumn.js +2 -2
  367. package/dist/switcher.d.ts +10 -5
  368. package/dist/switcher.js +7 -5
  369. package/dist/tableColumns.d.ts +17 -0
  370. package/dist/tableColumns.js +30 -2
  371. package/dist/tableEmpty.js +5 -5
  372. package/dist/tableRow.d.ts +26 -2
  373. package/dist/tableRow.js +23 -1
  374. package/dist/tableSort.d.ts +10 -5
  375. package/dist/tableSort.js +15 -4
  376. package/dist/target.d.ts +12 -0
  377. package/dist/target.js +12 -0
  378. package/dist/textBox.js +1 -1
  379. package/dist/truncated.d.ts +31 -0
  380. package/dist/truncated.js +51 -0
  381. package/dist/typography.d.ts +19 -11
  382. package/dist/typography.js +11 -13
  383. package/dist/useFlowLayout.d.ts +38 -0
  384. package/dist/useFlowLayout.js +122 -0
  385. package/package.json +5 -3
@@ -0,0 +1,290 @@
1
+ /**
2
+ * The native theme generator: a theme's CSS (`themes/<id>.css`) as the style map a React Native
3
+ * renderer reads (`themes/<id>.native.json`). Pure: it takes the CSS text and the palette and
4
+ * returns the map, so the theme test can assert the committed file is current.
5
+ *
6
+ * Every palette utility lands in one place: a plain one (`bg-white`) in `utilities`, one behind a
7
+ * state variant in that state's slot (`hover:bg-violet-700` in `pressed`, `placeholder:text-slate-400`
8
+ * in `placeholderTextColor`, `backdrop:bg-slate-900/35` in `scrim`). A rule the map cannot hold as
9
+ * one utility (`.disabled\:opacity-50:disabled:is(…)`) is a compound. Anything else is listed in
10
+ * `unmapped`, so nothing is dropped silently, and the theme test requires that list to be empty.
11
+ */
12
+ /** Which slot each Tailwind variant the palette uses lands in. */
13
+ export const STATE_OF_VARIANT = {
14
+ hover: "pressed",
15
+ "focus-visible": "focused",
16
+ "has-focus-visible": "focused",
17
+ placeholder: "placeholderTextColor",
18
+ backdrop: "scrim",
19
+ disabled: "disabled",
20
+ "aria-invalid": "invalid",
21
+ "has-aria-invalid": "invalid",
22
+ "user-invalid": "invalid",
23
+ "has-user-invalid": "invalid",
24
+ target: "target",
25
+ };
26
+ const CSS_TO_NATIVE = {
27
+ "background-color": "backgroundColor",
28
+ color: "color",
29
+ "border-color": "borderColor",
30
+ "outline-color": "outlineColor",
31
+ "accent-color": "accentColor",
32
+ opacity: "opacity",
33
+ "font-weight": "fontWeight",
34
+ };
35
+ /** Declarations a native map has no use for: web-only, or carried in `base`. Listed, so nothing else is dropped. */
36
+ const WEB_ONLY = new Set([
37
+ "transition",
38
+ "text-underline-offset",
39
+ "color-scheme",
40
+ "font-family",
41
+ "--font-mono",
42
+ "--font-sans",
43
+ "--font-heading",
44
+ ]);
45
+ const COLOUR = /^(#[0-9a-f]{3,8}|rgba?\([^)]*\)|transparent)$/i;
46
+ /** One canonical form of a colour: lower-case hex, `rgba(r, g, b, a)`. */
47
+ function colourOf(value, where, unmapped) {
48
+ if (!COLOUR.test(value)) {
49
+ unmapped.push(`${where}: "${value}" is not a colour React Native parses`);
50
+ return undefined;
51
+ }
52
+ return value
53
+ .toLowerCase()
54
+ .replace(/\(\s*/, "(")
55
+ .replace(/\s*\)/, ")")
56
+ .replace(/\s*,\s*/g, ", ");
57
+ }
58
+ function declarationsOf(body, where, unmapped) {
59
+ const style = {};
60
+ for (const declaration of body.split(";")) {
61
+ const colon = declaration.indexOf(":");
62
+ if (colon < 0)
63
+ continue;
64
+ const property = declaration.slice(0, colon).trim();
65
+ const value = declaration
66
+ .slice(colon + 1)
67
+ .replace(/\s+/g, " ")
68
+ .trim();
69
+ if (property === "" || WEB_ONLY.has(property) || property.startsWith("--hc-"))
70
+ continue;
71
+ const native = CSS_TO_NATIVE[property];
72
+ if (native === undefined) {
73
+ unmapped.push(`${where} { ${property} }`);
74
+ continue;
75
+ }
76
+ if (native === "opacity")
77
+ style[native] = Number(value);
78
+ else if (native === "fontWeight")
79
+ style[native] = value;
80
+ else {
81
+ const colour = colourOf(value, `${where} ${property}`, unmapped);
82
+ if (colour !== undefined)
83
+ style[native] = colour;
84
+ }
85
+ }
86
+ return style;
87
+ }
88
+ /** Split a selector list on the commas outside brackets. */
89
+ function selectorsOf(list) {
90
+ const parts = [];
91
+ let depth = 0;
92
+ let current = "";
93
+ for (const char of list) {
94
+ if (char === "(" || char === "[")
95
+ depth += 1;
96
+ if (char === ")" || char === "]")
97
+ depth -= 1;
98
+ if (char === "," && depth === 0) {
99
+ parts.push(current.trim());
100
+ current = "";
101
+ }
102
+ else
103
+ current += char;
104
+ }
105
+ return [...parts, current.trim()].filter(Boolean);
106
+ }
107
+ const unescapeClass = (name) => name.replace(/\\(.)/g, "$1");
108
+ const CLASS = String.raw `((?:\\.|[\w-])+)`;
109
+ /** `hover:bg-violet-700` as its variant and plain utility; no variant gives `undefined`. */
110
+ function splitVariant(utility) {
111
+ const colon = utility.lastIndexOf(":");
112
+ if (colon < 0)
113
+ return { variant: undefined, plain: utility };
114
+ return { variant: utility.slice(0, colon), plain: utility.slice(colon + 1) };
115
+ }
116
+ function merge(table, key, style) {
117
+ table[key] = { ...table[key], ...style };
118
+ }
119
+ function emptyParsed(scope) {
120
+ return {
121
+ scope,
122
+ base: { backgroundColor: "", color: "", fontFamily: null, headingFontFamily: null },
123
+ selection: {},
124
+ utilities: {},
125
+ states: {
126
+ pressed: {},
127
+ focused: {},
128
+ placeholderTextColor: {},
129
+ scrim: {},
130
+ disabled: {},
131
+ invalid: {},
132
+ target: {},
133
+ },
134
+ within: {},
135
+ headings: {},
136
+ compounds: [],
137
+ };
138
+ }
139
+ /** The first family of a `--font-…` stack in the scope rule, unquoted; none gives `null`. */
140
+ function familyOf(body, variable) {
141
+ const family = new RegExp(`--font-${variable}:([^;]+);`)
142
+ .exec(body)?.[1]
143
+ ?.split(",")[0]
144
+ ?.trim()
145
+ .replace(/^["']|["']$/g, "");
146
+ return family === undefined || family === "" ? null : family;
147
+ }
148
+ /** The scope rule: the page's canvas, ink, sans family and heading family. */
149
+ function readScope(parsed, body, file, unmapped) {
150
+ const style = declarationsOf(body, `${file} .${parsed.scope}`, unmapped);
151
+ parsed.base.backgroundColor = String(style["backgroundColor"] ?? "");
152
+ parsed.base.color = String(style["color"] ?? "");
153
+ parsed.base.fontFamily = familyOf(body, "sans");
154
+ parsed.base.headingFontFamily = familyOf(body, "heading");
155
+ }
156
+ /**
157
+ * A rule on the headings. The heading face is `base.headingFontFamily`, read from the scope rule, so
158
+ * a bare heading rule of font-family alone is taken; a utility on a heading
159
+ * (`:is(h1, h2, h3).text-slate-900`) lands in `headings`; anything else is unmapped.
160
+ */
161
+ function readHeading(parsed, rest, style) {
162
+ if (rest === "")
163
+ return Object.keys(style).every((key) => key === "fontFamily");
164
+ const utility = new RegExp(`^\\.${CLASS}$`).exec(rest)?.[1];
165
+ if (utility === undefined)
166
+ return false;
167
+ merge(parsed.headings, unescapeClass(utility), style);
168
+ return true;
169
+ }
170
+ /** A selector that is not one utility: the selection, the headings, a utility on a tint. */
171
+ function readSpecial(parsed, selector, style) {
172
+ const scope = parsed.scope;
173
+ if (new RegExp(`^\\.${scope}\\s*::selection$`).test(selector)) {
174
+ Object.assign(parsed.selection, style);
175
+ return true;
176
+ }
177
+ const heading = new RegExp(`^\\.${scope}\\s+:is\\(h1, h2, h3[^)]*\\)(.*)$`).exec(selector);
178
+ if (heading)
179
+ return readHeading(parsed, heading[1] ?? "", style);
180
+ const within = new RegExp(`^\\.${scope}\\s+\\.${CLASS}\\s+\\.${CLASS}$`).exec(selector);
181
+ if (!within)
182
+ return false;
183
+ const tint = unescapeClass(within[1] ?? "");
184
+ parsed.within[tint] = parsed.within[tint] ?? {};
185
+ merge(parsed.within[tint], unescapeClass(within[2] ?? ""), style);
186
+ return true;
187
+ }
188
+ /** One utility, plain, behind a state variant, or held only alongside other classes. */
189
+ function readUtility(parsed, utility, rest, style) {
190
+ const requires = /:is\(([^)]*)\)/.exec(rest)?.[1];
191
+ if (requires !== undefined) {
192
+ const requiresAny = requires.split(",").map((name) => unescapeClass(name.trim().slice(1)));
193
+ parsed.compounds.push({ utility, requiresAny, style });
194
+ return true;
195
+ }
196
+ const { variant, plain } = splitVariant(utility);
197
+ if (variant === undefined) {
198
+ // A plain class with its own `:hover` (`.link:hover`) is that class pressed; any other
199
+ // pseudo-class on a plain class has no slot.
200
+ if (rest === ":hover")
201
+ merge(parsed.states.pressed, plain, style);
202
+ else if (rest === "")
203
+ merge(parsed.utilities, plain, style);
204
+ else
205
+ return false;
206
+ return true;
207
+ }
208
+ const state = STATE_OF_VARIANT[variant];
209
+ if (state === undefined)
210
+ return false;
211
+ merge(parsed.states[state], plain, state === "placeholderTextColor" ? asPlaceholder(style) : style);
212
+ return true;
213
+ }
214
+ /** One `.scope …` selector into its place in the map; false when it has none. */
215
+ function readSelector(parsed, selector, style) {
216
+ if (readSpecial(parsed, selector, style))
217
+ return true;
218
+ const plain = new RegExp(`^\\.${parsed.scope}\\s+\\.${CLASS}(.*)$`).exec(selector);
219
+ if (!plain)
220
+ return false;
221
+ return readUtility(parsed, unescapeClass(plain[1] ?? ""), plain[2] ?? "", style);
222
+ }
223
+ /** A placeholder's colour is a prop on a native text input, not a style. */
224
+ const asPlaceholder = (style) => style["color"] === undefined ? style : { placeholderTextColor: style["color"] };
225
+ /**
226
+ * The native map of one theme's CSS. `id` is the file name without `.css`. Returns the map and
227
+ * every rule or declaration it could not carry.
228
+ */
229
+ export function nativeTheme(css, id) {
230
+ const file = `${id}.css`;
231
+ const uncommented = css.replace(/\/\*[\s\S]*?\*\//g, "");
232
+ const scheme = /@custom-variant\s+dark\b/.test(uncommented) ? "dark" : "light";
233
+ const unmapped = [];
234
+ const { scope, base, selection, utilities, states, within, headings, compounds } = parse(uncommented.replace(/@[^;{}]*;/g, ""), file, unmapped);
235
+ return {
236
+ theme: {
237
+ id,
238
+ scope,
239
+ scheme,
240
+ statusBar: scheme === "dark" ? "light-content" : "dark-content",
241
+ base,
242
+ selection,
243
+ utilities,
244
+ states,
245
+ within,
246
+ headings,
247
+ compounds,
248
+ },
249
+ unmapped,
250
+ };
251
+ }
252
+ /** The scope rule's map, from the first rule: its selector must be the one scope class. */
253
+ function parseScope(list, body, file, unmapped) {
254
+ const scope = /^\.([\w-]+)$/.exec(selectorsOf(list)[0] ?? "")?.[1];
255
+ if (scope === undefined)
256
+ throw new Error(`${file}: the first rule is not the scope rule`);
257
+ const parsed = emptyParsed(scope);
258
+ readScope(parsed, body, file, unmapped);
259
+ return parsed;
260
+ }
261
+ /** The rules of one theme's CSS, comments and at-statements gone: the scope rule first. */
262
+ function parse(source, file, unmapped) {
263
+ let parsed;
264
+ for (const [, list = "", body = ""] of source.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
265
+ if (parsed === undefined) {
266
+ parsed = parseScope(list, body, file, unmapped);
267
+ continue;
268
+ }
269
+ for (const selector of selectorsOf(list)) {
270
+ const style = declarationsOf(body, `${file} ${selector}`, unmapped);
271
+ if (!readSelector(parsed, selector, style))
272
+ unmapped.push(`${file}: selector ${selector}`);
273
+ }
274
+ }
275
+ if (parsed === undefined)
276
+ throw new Error(`${file}: no scope rule`);
277
+ return parsed;
278
+ }
279
+ /** The palette utilities a native map does not hold: each in `utilities`, or in its variant's slot. */
280
+ export function missingFromNative(theme, palette) {
281
+ return palette.filter((utility) => {
282
+ const { variant, plain } = splitVariant(utility);
283
+ if (variant === undefined)
284
+ return theme.utilities[plain] === undefined;
285
+ const state = STATE_OF_VARIANT[variant];
286
+ return state === undefined || theme.states[state][plain] === undefined;
287
+ });
288
+ }
289
+ /** The map as the file holds it: two-space JSON with a trailing newline. */
290
+ export const nativeThemeJson = (theme) => `${JSON.stringify(theme, null, 2)}\n`;
package/dist/cx.d.ts CHANGED
@@ -1,7 +1,19 @@
1
1
  /** Join class names, dropping falsy parts. */
2
2
  export declare function cx(...parts: Array<string | false | null | undefined>): string;
3
- /** The keyboard focus ring every interactive control shares. */
4
- export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
3
+ export { focusRing, insetFocusRing } from "./focus.js";
4
+ /**
5
+ * A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
6
+ * wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
7
+ * `lines` clamp (one line with an ellipsis) still wins; a browser that has neither wraps as before.
8
+ */
9
+ export declare const balanced = "[text-wrap-style:balance]";
10
+ export declare const pretty = "[text-wrap-style:pretty]";
11
+ /**
12
+ * A fill that carries meaning (a bar's progress, the drop line, the current pill) in forced
13
+ * colours: there every background is painted the page's Canvas, so the fill would vanish. A system
14
+ * colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
15
+ */
16
+ export declare const forcedFill = "forced-colors:bg-[color:Highlight]!";
5
17
  /**
6
18
  * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
7
19
  * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
@@ -11,9 +23,9 @@ export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-
11
23
  */
12
24
  export declare const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
13
25
  /**
14
- * A thin scrollbar in the theme's muted ink instead of the heavy native one, for a box that
15
- * scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
26
+ * A scrollbar in the theme's muted ink instead of the native grey one, at the native width so it
27
+ * stays easy to grab, for a box that scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
16
28
  * element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
17
29
  * transparent. The element must not hold text of its own: put the readable colour on an inner box.
18
30
  */
19
- export declare const themedScrollbar = "text-slate-400 [scrollbar-width:thin] [scrollbar-color:currentColor_transparent]";
31
+ export declare const themedScrollbar = "text-slate-400 [scrollbar-color:currentColor_transparent]";
package/dist/cx.js CHANGED
@@ -2,8 +2,21 @@
2
2
  export function cx(...parts) {
3
3
  return parts.filter(Boolean).join(" ");
4
4
  }
5
- /** The keyboard focus ring every interactive control shares. */
6
- export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
5
+ // The keyboard focus ring and its inset twin are core's, the one copy both renderers read.
6
+ export { focusRing, insetFocusRing } from "./focus.js";
7
+ /**
8
+ * A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
9
+ * wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
10
+ * `lines` clamp (one line with an ellipsis) still wins; a browser that has neither wraps as before.
11
+ */
12
+ export const balanced = "[text-wrap-style:balance]";
13
+ export const pretty = "[text-wrap-style:pretty]";
14
+ /**
15
+ * A fill that carries meaning (a bar's progress, the drop line, the current pill) in forced
16
+ * colours: there every background is painted the page's Canvas, so the fill would vanish. A system
17
+ * colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
18
+ */
19
+ export const forcedFill = "forced-colors:bg-[color:Highlight]!";
7
20
  /**
8
21
  * On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
9
22
  * above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
@@ -13,9 +26,9 @@ export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2
13
26
  */
14
27
  export const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
15
28
  /**
16
- * A thin scrollbar in the theme's muted ink instead of the heavy native one, for a box that
17
- * scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
29
+ * A scrollbar in the theme's muted ink instead of the native grey one, at the native width so it
30
+ * stays easy to grab, for a box that scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
18
31
  * element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
19
32
  * transparent. The element must not hold text of its own: put the readable colour on an inner box.
20
33
  */
21
- export const themedScrollbar = "text-slate-400 [scrollbar-width:thin] [scrollbar-color:currentColor_transparent]";
34
+ export const themedScrollbar = "text-slate-400 [scrollbar-color:currentColor_transparent]";
@@ -0,0 +1,17 @@
1
+ import { type DateValue } from "@internationalized/date";
2
+ import type { ReactElement, ReactNode } from "react";
3
+ /**
4
+ * The locale a date field shows its segments, month names and messages in: `locale` when it is
5
+ * given, else the app's own `I18nProvider`, else the browser's.
6
+ */
7
+ export declare function DateLocale({ locale, children, }: {
8
+ locale: string | undefined;
9
+ children: ReactNode;
10
+ }): ReactElement;
11
+ /** The twelve month names in `locale`, January first. */
12
+ export declare function monthNames(locale: string): string[];
13
+ /**
14
+ * A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
15
+ * en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
16
+ */
17
+ export declare function shownIn(value: DateValue, locale: string, time: boolean): string;
@@ -0,0 +1,30 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { DateFormatter, toCalendarDateTime } from "@internationalized/date";
3
+ import { I18nProvider } from "react-aria-components";
4
+ /**
5
+ * The locale a date field shows its segments, month names and messages in: `locale` when it is
6
+ * given, else the app's own `I18nProvider`, else the browser's.
7
+ */
8
+ export function DateLocale({ locale, children, }) {
9
+ return locale ? _jsx(I18nProvider, { locale: locale, children: children }) : _jsx(_Fragment, { children: children });
10
+ }
11
+ /** The twelve month names in `locale`, January first. */
12
+ export function monthNames(locale) {
13
+ const months = new DateFormatter(locale, { month: "long", timeZone: "UTC" });
14
+ return Array.from({ length: 12 }, (_, i) => months.format(new Date(Date.UTC(2000, i, 1))));
15
+ }
16
+ /**
17
+ * A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
18
+ * en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
19
+ */
20
+ export function shownIn(value, locale, time) {
21
+ const clock = time ? { hour: "2-digit", minute: "2-digit" } : {};
22
+ const format = new DateFormatter(locale, {
23
+ day: "2-digit",
24
+ month: "2-digit",
25
+ year: "numeric",
26
+ ...clock,
27
+ timeZone: "UTC",
28
+ });
29
+ return format.format(toCalendarDateTime(value).toDate("UTC"));
30
+ }
package/dist/density.d.ts CHANGED
@@ -26,13 +26,27 @@ export declare function useResponsiveDensity(size: Size | ResponsiveSize | undef
26
26
  export declare function useTypeStep(): TypeStep | undefined;
27
27
  /** The size twins, for the data test that each is its table with `md:` on every class. */
28
28
  export declare const controlTextTables: {
29
- text: Record<"compact" | "default", Record<Size, string>>;
29
+ text: Record<import("./core/index.js").ControlTypeStep, Record<import("./core/index.js").ButtonSize, string>>;
30
30
  textMd: Record<"compact" | "default", Record<Size, string>>;
31
- leading: Record<Size, string>;
31
+ leading: Record<import("./core/index.js").ButtonSize, string>;
32
32
  leadingMd: Record<Size, string>;
33
33
  };
34
34
  /**
35
35
  * The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
36
- * a person types in. A responsive size adds its `md` size from the breakpoint up.
36
+ * a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
37
+ * holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
38
+ * wins over an `md:` size under 16px.
37
39
  */
38
40
  export declare function controlText(size: Size | ResponsiveSize, step: TypeStep | undefined, entry: boolean): string;
41
+ /** The field type table, for the data test. */
42
+ export declare const fieldTypeTable: Record<"compact" | "default", {
43
+ label: string;
44
+ note: string;
45
+ line: string;
46
+ }>;
47
+ /** The type of a field's label and its notes at the step in force. */
48
+ export declare function useFieldType(): {
49
+ label: string;
50
+ note: string;
51
+ line: string;
52
+ };
package/dist/density.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createContext, createElement, useContext, useMemo, } from "react";
2
+ import { CONTROL_LEADING, CONTROL_TEXT } from "./core/index.js";
2
3
  import { isResponsive } from "./size.js";
3
4
  const DensityContext = createContext({ size: undefined, type: undefined });
4
5
  /**
@@ -28,11 +29,6 @@ export function useResponsiveDensity(size) {
28
29
  export function useTypeStep() {
29
30
  return useContext(DensityContext).type;
30
31
  }
31
- /** A control's type size at each step: `md` is 16px at the default step, and `compact` is one step down. */
32
- const CONTROL_TEXT = {
33
- default: { sm: "text-sm", md: "text-base", lg: "text-lg" },
34
- compact: { sm: "text-xs", md: "text-sm", lg: "text-base" },
35
- };
36
32
  /** `CONTROL_TEXT` from the `md` breakpoint up, for a responsive size. */
37
33
  const CONTROL_TEXT_MD = {
38
34
  default: { sm: "md:text-sm", md: "md:text-base", lg: "md:text-lg" },
@@ -43,12 +39,8 @@ const CONTROL_TEXT_MD = {
43
39
  * not zoom the page when it takes the focus.
44
40
  */
45
41
  const TOUCH_TEXT = "pointer-coarse:text-base";
46
- /**
47
- * A control's line height by `size`, whatever its type step: 16, 20 and 24px, so with its padding
48
- * every control is 26, 38 and 46px tall at both steps, and a `Select`, an `IconButton` and a
49
- * `DateRangePicker`, whose heights are fixed, line up with it.
50
- */
51
- const CONTROL_LEADING = { sm: "leading-4", md: "leading-5", lg: "leading-6" };
42
+ // `CONTROL_TEXT` and `CONTROL_LEADING` are core's, the one copy both renderers read; a `Select`, an
43
+ // `IconButton` and a `DateRangePicker`, whose heights are fixed, line up with them.
52
44
  /** `CONTROL_LEADING` from the `md` breakpoint up, for a responsive size. */
53
45
  const CONTROL_LEADING_MD = {
54
46
  sm: "md:leading-4",
@@ -64,14 +56,33 @@ export const controlTextTables = {
64
56
  };
65
57
  /**
66
58
  * The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
67
- * a person types in. A responsive size adds its `md` size from the breakpoint up.
59
+ * a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
60
+ * holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
61
+ * wins over an `md:` size under 16px.
68
62
  */
69
63
  export function controlText(size, step, entry) {
70
- // The touch floor is judged on `base` only: no text-entry control takes a responsive size yet.
71
- const base = isResponsive(size) ? size.base : size;
72
- const plain = `${CONTROL_TEXT[step ?? "default"][base]} ${CONTROL_LEADING[base]}`;
73
- const text = entry && !/text-(base|lg)/.test(plain) ? `${plain} ${TOUCH_TEXT}` : plain;
74
- if (!isResponsive(size))
75
- return text;
76
- return `${text} ${CONTROL_TEXT_MD[step ?? "default"][size.md]} ${CONTROL_LEADING_MD[size.md]}`;
64
+ const table = CONTROL_TEXT[step ?? "default"];
65
+ const [base, wide] = isResponsive(size) ? [size.base, size.md] : [size, size];
66
+ const plain = `${table[base]} ${CONTROL_LEADING[base]}`;
67
+ const md = isResponsive(size)
68
+ ? ` ${CONTROL_TEXT_MD[step ?? "default"][wide]} ${CONTROL_LEADING_MD[wide]}`
69
+ : "";
70
+ const small = [table[base], table[wide]].some((text) => !/text-(base|lg)/.test(text));
71
+ return `${plain}${md}${entry && small ? ` ${TOUCH_TEXT}` : ""}`;
72
+ }
73
+ /**
74
+ * The type of a field's words at each step: the label is the type of a `md` control (16px, 14px
75
+ * compact), so a label sits at the size of the text typed under it, and the notes under a control
76
+ * (the hint and the error) are one step below. `line` is the height of a note's first line, for the
77
+ * error's alert icon.
78
+ */
79
+ const FIELD_TYPE = {
80
+ default: { label: "text-base", note: "text-sm", line: "h-5" },
81
+ compact: { label: "text-sm", note: "text-xs", line: "h-4" },
82
+ };
83
+ /** The field type table, for the data test. */
84
+ export const fieldTypeTable = FIELD_TYPE;
85
+ /** The type of a field's label and its notes at the step in force. */
86
+ export function useFieldType() {
87
+ return FIELD_TYPE[useTypeStep() ?? "default"];
77
88
  }
@@ -1,4 +1,5 @@
1
1
  import { type ReactElement, type ReactNode } from "react";
2
+ /** An `EmptyState`'s size: `md` a block with its heading, `sm` one muted line inside a card or a cell. */
2
3
  export type EmptySize = "sm" | "md";
3
4
  /** The size an `EmptyState` takes: its own, else its slot's, else `md`. */
4
5
  export declare function useEmptySize(own: EmptySize | undefined): EmptySize;
@@ -0,0 +1,11 @@
1
+ import { type ReactNode, type ReactPortal, type RefCallback } from "react";
2
+ /**
3
+ * Announces a field's error through its page's (or dialog's) one polite live region, not a
4
+ * `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
5
+ * its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
6
+ * error in place and names it in the control's `aria-describedby`.
7
+ */
8
+ export declare function useErrorAnnouncement(error: ReactNode): {
9
+ anchor: RefCallback<HTMLElement>;
10
+ announcement: ReactPortal | null;
11
+ };
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useState } from "react";
3
+ import { createPortal } from "react-dom";
4
+ /** The attribute that marks a field-error region. */
5
+ const REGION = "data-field-errors";
6
+ /**
7
+ * The polite live region for field errors under `host`, made on first use and shared by every field
8
+ * there: a hidden `<div aria-live="polite">` as the host's last child. The host is the open dialog the
9
+ * field sits in, or `body`: a modal dialog makes the rest of the page inert, and a screen reader
10
+ * does not announce a live region in inert content.
11
+ */
12
+ function errorRegion(host) {
13
+ const found = host.querySelector(`:scope > [${REGION}]`);
14
+ if (found)
15
+ return found;
16
+ const region = document.createElement("div");
17
+ region.setAttribute(REGION, "");
18
+ region.setAttribute("aria-live", "polite");
19
+ region.className = "sr-only";
20
+ host.append(region);
21
+ return region;
22
+ }
23
+ /**
24
+ * Announces a field's error through its page's (or dialog's) one polite live region, not a
25
+ * `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
26
+ * its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
27
+ * error in place and names it in the control's `aria-describedby`.
28
+ */
29
+ export function useErrorAnnouncement(error) {
30
+ const [region, setRegion] = useState(null);
31
+ const anchor = useCallback((node) => {
32
+ if (node)
33
+ setRegion(errorRegion(node.closest("dialog") ?? document.body));
34
+ }, []);
35
+ return { anchor, announcement: region ? createPortal(_jsx("p", { children: error }), region) : null };
36
+ }
@@ -2,22 +2,27 @@
2
2
  export type FieldControlContext = {
3
3
  /** The control's id, which the Field's label names. */
4
4
  id: string;
5
- /** The id of the note the Field draws (the error, or else the hint), none when it draws neither. */
5
+ /** The ids of the notes the Field draws (the hint, then the error), none when it draws neither. */
6
6
  describedBy: string | undefined;
7
7
  /** `true` when the Field shows an error. */
8
8
  invalid: boolean;
9
+ /** `true` when the Field is `required`. */
10
+ required: boolean;
9
11
  };
10
12
  export declare const FieldContext: import("react").Context<FieldControlContext | undefined>;
11
13
  type ControlA11y = {
12
14
  id?: string | undefined;
13
15
  "aria-describedby"?: string | undefined;
14
16
  "aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling" | undefined;
17
+ required?: boolean | undefined;
15
18
  };
16
19
  /**
17
20
  * Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
18
21
  * `Field` the id is the Field's, so its label always names the control; the caller's
19
22
  * `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
20
- * Outside a `Field` it returns the props unchanged.
23
+ * With no error the control says `aria-invalid="false"` outright, so a browser does not read an
24
+ * empty required control as invalid before anyone has typed. A `required` Field makes the control
25
+ * `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
21
26
  */
22
27
  export declare function useFieldControl(own: ControlA11y): ControlA11y;
23
28
  export {};
@@ -4,7 +4,9 @@ export const FieldContext = createContext(undefined);
4
4
  * Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
5
5
  * `Field` the id is the Field's, so its label always names the control; the caller's
6
6
  * `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
7
- * Outside a `Field` it returns the props unchanged.
7
+ * With no error the control says `aria-invalid="false"` outright, so a browser does not read an
8
+ * empty required control as invalid before anyone has typed. A `required` Field makes the control
9
+ * `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
8
10
  */
9
11
  export function useFieldControl(own) {
10
12
  const field = useContext(FieldContext);
@@ -13,12 +15,14 @@ export function useFieldControl(own) {
13
15
  id: own.id,
14
16
  "aria-describedby": own["aria-describedby"],
15
17
  "aria-invalid": own["aria-invalid"],
18
+ required: own.required,
16
19
  };
17
20
  }
18
21
  const describedBy = [own["aria-describedby"], field.describedBy].filter(Boolean).join(" ");
19
22
  return {
20
23
  id: field.id,
21
24
  "aria-describedby": describedBy === "" ? undefined : describedBy,
22
- "aria-invalid": own["aria-invalid"] ?? (field.invalid ? true : undefined),
25
+ "aria-invalid": own["aria-invalid"] ?? field.invalid,
26
+ required: own.required ?? (field.required || undefined),
23
27
  };
24
28
  }
@@ -1,8 +1,8 @@
1
1
  import type { ReactElement, ReactNode } from "react";
2
- import type { Size } from "./size.js";
2
+ import type { ResponsiveSize, Size } from "./size.js";
3
3
  /** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
4
4
  export declare function ControlBone({ size }: {
5
- size?: Size | undefined;
5
+ size?: Size | ResponsiveSize | undefined;
6
6
  }): ReactElement;
7
7
  /**
8
8
  * A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
@@ -25,6 +25,6 @@ export declare function WaitingField({ own, loadingLabel, label, look, size, att
25
25
  loadingLabel: string | undefined;
26
26
  label: ReactNode;
27
27
  look: string;
28
- size: Size | undefined;
28
+ size: Size | ResponsiveSize | undefined;
29
29
  attrs: object;
30
30
  }): ReactElement;