@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
@@ -1,33 +1,28 @@
1
- import { type CalendarDate } from "@internationalized/date";
1
+ import { type CalendarDate, type DateValue } from "@internationalized/date";
2
2
  import { type ContextType, type ReactElement, type ReactNode } from "react";
3
3
  import { type DateFieldProps as AriaDateFieldProps, DateFieldStateContext } from "react-aria-components";
4
- import { type Passthrough } from "./props.js";
4
+ import type { Passthrough } from "./props.js";
5
5
  import { type LoadingProps } from "./skeleton.js";
6
- import type { Size } from "./size.js";
7
- /** Fixed, whatever the browser's locale: DD/MM/YYYY and Monday-first weeks. */
8
- export declare const LOCALE = "en-GB";
9
- export declare const MONTH_OPTIONS: {
10
- month: number;
11
- name: string;
12
- }[];
6
+ import { type ResponsiveSize, type Size } from "./size.js";
13
7
  type Segment = NonNullable<ContextType<typeof DateFieldStateContext>>["segments"][number];
14
8
  /** The props of a plain `DateField`, without the calendar. */
15
9
  export type FieldProps = {
16
10
  /** The field's visible label, above it. Without one, name the field with `aria-label`. */
17
11
  label?: ReactNode;
18
- /** A muted line under the field that says more; an error replaces it. */
12
+ /** A muted line under the field that says more; it stays while an error shows under it. */
19
13
  hint?: ReactNode;
20
14
  /**
21
- * Marks the field invalid and shows this in red with `role="alert"`, in place of the hint and of
15
+ * Marks the field invalid and shows this in red under the hint, announced politely, in place of
22
16
  * the built-in message (an impossible date, or one outside min/max). Like `Field`'s `error`.
23
17
  */
24
18
  error?: ReactNode;
25
19
  /**
26
20
  * The field's height and text, on the same scale as an `Input`: `sm` is `text-sm`, `md` `text-base`,
27
21
  * `lg` `text-lg`, one step down under an `AppShell density="compact"`, and never under 16px on touch.
22
+ * `{ base: "md", md: "lg" }` changes size at the `md` breakpoint (48rem), in CSS, as an `Input`'s does.
28
23
  * @default md
29
24
  */
30
- size?: Size;
25
+ size?: Size | ResponsiveSize;
31
26
  /** Disables the field: no typing, no calendar. */
32
27
  disabled?: boolean | undefined;
33
28
  /** Marks a date required: the field is `aria-required`, and an empty one is invalid. */
@@ -42,8 +37,15 @@ export type FieldProps = {
42
37
  minValue?: AriaDateFieldProps<CalendarDate>["minValue"];
43
38
  /** The latest date allowed: a later one marks the field invalid with its own message. */
44
39
  maxValue?: AriaDateFieldProps<CalendarDate>["maxValue"];
45
- /** Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string. */
40
+ /** Posts the date in a form as `YYYY-MM-DD` under this key, or an empty string, whatever the `locale`. */
46
41
  name?: AriaDateFieldProps<CalendarDate>["name"];
42
+ /**
43
+ * The locale the field writes its date in, a BCP 47 tag: `en-GB` is DD/MM/YYYY, `en-US`
44
+ * MM/DD/YYYY, `en-ZA` YYYY/MM/DD. It sets the order of the segments, the month names, the
45
+ * calendar's first weekday and the dates in its messages. Without it the field follows the app's
46
+ * own `I18nProvider`, or else the browser's language.
47
+ */
48
+ locale?: string | undefined;
47
49
  } & Passthrough;
48
50
  /** The calendar's dropdown names, with their English defaults. */
49
51
  type CalendarNames = {
@@ -57,6 +59,11 @@ type CalendarNames = {
57
59
  * @default Year
58
60
  */
59
61
  yearLabel?: string | undefined;
62
+ /**
63
+ * The calendar's footer button that empties the field, for an app in another language.
64
+ * @default Clear
65
+ */
66
+ clearLabel?: string | undefined;
60
67
  };
61
68
  export type DateFieldProps = FieldProps & LoadingProps & ({
62
69
  /** Adds a calendar button that opens a month view in a popover; the field is a date picker. */
@@ -67,6 +74,8 @@ export type DateFieldProps = FieldProps & LoadingProps & ({
67
74
  monthLabel?: undefined;
68
75
  /** Only a `calendar` field takes `yearLabel`. */
69
76
  yearLabel?: undefined;
77
+ /** Only a `calendar` field takes `clearLabel`. */
78
+ clearLabel?: undefined;
70
79
  } | ({
71
80
  calendar: true;
72
81
  /** Open the calendar on mount. */
@@ -79,7 +88,10 @@ export declare function fieldFlags(disabled: boolean | undefined, required: bool
79
88
  };
80
89
  /** What the segments show, as the day segment reports it to the field. */
81
90
  export type Read = {
82
- /** The date as `YYYY-MM-DD` once every segment is filled and the day exists, else `""`. */
91
+ /**
92
+ * The date as `YYYY-MM-DD` (`YYYY-MM-DDTHH:mm` with a time) once every segment is filled and the
93
+ * day exists, else `""`.
94
+ */
83
95
  typed: string;
84
96
  /** "February 1990 has 28 days." when the day does not exist. */
85
97
  impossible: string | null;
@@ -103,22 +115,41 @@ export declare function forcedInvalid({ impossible, error, }: {
103
115
  }): {
104
116
  isInvalid?: true;
105
117
  };
106
- /** The hint or the error line: the shared outside of every date field. */
107
- export declare function Notes({ hint, error, impossible, isInvalid, }: {
118
+ /** A field's `minValue` and `maxValue`. */
119
+ export type Bounds = {
120
+ minValue?: DateValue | null | undefined;
121
+ maxValue?: DateValue | null | undefined;
122
+ };
123
+ /** The hint and, under it, the error line: the shared outside of every date field. */
124
+ export declare function Notes({ hint, error, impossible, bounds, time, }: {
108
125
  hint: ReactNode;
109
126
  error: ReactNode;
110
127
  impossible: string | null;
111
- isInvalid: boolean;
128
+ bounds: Bounds;
129
+ time?: boolean;
112
130
  }): ReactElement;
113
- export declare const labelClass = "text-sm font-medium text-slate-700";
131
+ /** The padding table and its `md:` twin, for the data test. */
132
+ export declare const fieldSizeTables: {
133
+ pad: Record<Size, string>;
134
+ padMd: Record<Size, string>;
135
+ };
136
+ /** A date field's padding at `size`. */
137
+ export declare function fieldPad(size: Size | ResponsiveSize): string;
138
+ /** A date field's label look at the type step in force: a `Field`'s. */
139
+ export declare function useLabelClass(): string;
140
+ /** A date field's visible label, with the required mark. */
141
+ export declare function FieldLabel({ label, required, }: {
142
+ label: ReactNode;
143
+ required: boolean | undefined;
144
+ }): ReactElement | null;
114
145
  /** A small icon button inside a date field or calendar, without its box size. */
115
146
  export declare const iconButtonLook = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
116
147
  export declare const iconButtonClass = "inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600 h-7 w-7";
117
148
  /**
118
- * A segmented DD / MM / YYYY date input. Values are `CalendarDate`s; `name` posts it as
119
- * `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
149
+ * A segmented date input, in the order of its `locale` (by default the browser's): DD / MM / YYYY
150
+ * in en-GB. Values are `CalendarDate`s; `name` posts it as `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
120
151
  * same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
121
152
  * drawn and the field is a bone of its height.
122
153
  */
123
- export declare function DateField({ calendar, defaultOpen, monthLabel, yearLabel, loading, loadingLabel, ...field }: DateFieldProps): ReactElement;
154
+ export declare function DateField({ calendar, defaultOpen, monthLabel, yearLabel, clearLabel, loading, loadingLabel, ...field }: DateFieldProps): ReactElement;
124
155
  export {};
package/dist/DateField.js CHANGED
@@ -1,27 +1,37 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CalendarDate as CalendarDateClass, DateFormatter, } from "@internationalized/date";
2
+ import { CalendarDate as CalendarDateClass, } from "@internationalized/date";
3
3
  import { useContext, useEffect } from "react";
4
- import { DateField as AriaDateField, DateFieldStateContext, DateInput, DateSegment, FieldError, I18nProvider, Label, Text, } from "react-aria-components";
4
+ import { DateFieldStateContext, DateSegment, FieldError, Label, Text, useLocale, } from "react-aria-components";
5
5
  import { cx, focusRing } from "./cx.js";
6
6
  import { CalendarDateField } from "./DateFieldCalendar.js";
7
7
  import { toISODate } from "./isoDate.js";
8
- import { definedProps } from "./props.js";
8
+ import { ErrorLine, RequiredMark } from "./Field.js";
9
9
  import { WaitingField } from "./fieldWait.js";
10
10
  import { useLoading } from "./skeleton.js";
11
- import { ShownInput, useShownDate } from "./shownDate.js";
12
- import { controlText, useTypeStep } from "./density.js";
13
- /** Fixed, whatever the browser's locale: DD/MM/YYYY and Monday-first weeks. */
14
- export const LOCALE = "en-GB";
15
- const MONTHS = new DateFormatter(LOCALE, { month: "long", timeZone: "UTC" });
16
- export const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({
17
- month: i + 1,
18
- name: MONTHS.format(new Date(Date.UTC(2000, i, 1))),
19
- }));
11
+ import { useFieldType } from "./density.js";
12
+ import { DATE } from "./shownDate.js";
13
+ import { SegmentedField } from "./SegmentedField.js";
14
+ import { monthNames, shownIn } from "./dateLocale.js";
15
+ import { sizeClass } from "./size.js";
20
16
  /** The react-aria flags for `disabled` and `required`, set only when true. */
21
17
  export function fieldFlags(disabled, required) {
22
18
  return { ...(disabled ? { isDisabled: true } : {}), ...(required ? { isRequired: true } : {}) };
23
19
  }
24
- function readSegments(segments) {
20
+ const twoDigits = (n) => String(n).padStart(2, "0");
21
+ /** `THH:mm` on the 24-hour clock when the segments have a time, else `""`. */
22
+ function clockOf(editable) {
23
+ const hour = editable.find((segment) => segment.type === "hour");
24
+ if (!hour)
25
+ return "";
26
+ const period = editable.find((segment) => segment.type === "dayPeriod");
27
+ const minute = editable.find((segment) => segment.type === "minute")?.value ?? 0;
28
+ // A 12-hour clock shows 12 for midnight and noon; its day period says which half of the day.
29
+ const hours = period
30
+ ? ((hour.value ?? 0) % 12) + (period.value === 1 ? 12 : 0)
31
+ : (hour.value ?? 0) % 24;
32
+ return `T${twoDigits(hours)}:${twoDigits(minute)}`;
33
+ }
34
+ function readSegments(segments, locale) {
25
35
  const editable = segments.filter((segment) => segment.isEditable);
26
36
  const blank = editable.filter((segment) => segment.isPlaceholder).length;
27
37
  const none = { typed: "", impossible: null, partial: blank > 0 && blank < editable.length };
@@ -34,16 +44,17 @@ function readSegments(segments) {
34
44
  const first = new CalendarDateClass(year, month, 1);
35
45
  const days = first.calendar.getDaysInMonth(first);
36
46
  if (day <= days)
37
- return { ...none, typed: toISODate(first.set({ day })) };
47
+ return { ...none, typed: toISODate(first.set({ day })) + clockOf(editable) };
38
48
  return {
39
49
  ...none,
40
- impossible: `${MONTH_OPTIONS[month - 1]?.name ?? ""} ${year} has ${days} days.`,
50
+ impossible: `${monthNames(locale)[month - 1] ?? ""} ${year} has ${days} days.`,
41
51
  };
42
52
  }
43
53
  /** One segment. The day segment also reports what the segments show to the field. */
44
54
  export function FieldSegment({ segment, onRead, }) {
45
55
  const state = useContext(DateFieldStateContext);
46
- const { typed, impossible, partial } = readSegments(state?.segments ?? []);
56
+ const { locale } = useLocale();
57
+ const { typed, impossible, partial } = readSegments(state?.segments ?? [], locale);
47
58
  useEffect(() => onRead?.({ typed, impossible, partial }), [typed, impossible, partial, onRead]);
48
59
  return (_jsx(DateSegment, { segment: segment, className: ({ isFocused, isPlaceholder, type }) => {
49
60
  if (type === "literal")
@@ -68,9 +79,25 @@ export function frameClass({ isInvalid, isFocusWithin, isDisabled, }) {
68
79
  export function forcedInvalid({ impossible, error, }) {
69
80
  return impossible || error ? { isInvalid: true } : {};
70
81
  }
71
- /** The hint or the error line: the shared outside of every date field. */
72
- export function Notes({ hint, error, impossible, isInvalid, }) {
73
- return (_jsxs(_Fragment, { children: [!isInvalid && hint ? (_jsx(Text, { slot: "description", className: "text-xs text-slate-500", children: hint })) : null, _jsx(FieldError, { className: "text-xs text-red-700", children: ({ validationErrors }) => error ? _jsx("span", { role: "alert", children: error }) : (impossible ?? validationErrors.join(" ")) })] }));
82
+ /**
83
+ * React Aria's own message, with an out-of-range one written in the field's locale the way the field
84
+ * shows its dates: React Aria writes those dates in the browser's locale, whatever the field's.
85
+ */
86
+ function builtIn({ validationErrors, validationDetails }, { minValue, maxValue }, locale, time) {
87
+ const what = time ? "date and time" : "date";
88
+ if (validationDetails.rangeUnderflow && minValue) {
89
+ return `The ${what} must be on or after ${shownIn(minValue, locale, time)}.`;
90
+ }
91
+ if (validationDetails.rangeOverflow && maxValue) {
92
+ return `The ${what} must be on or before ${shownIn(maxValue, locale, time)}.`;
93
+ }
94
+ return validationErrors.join(" ");
95
+ }
96
+ /** The hint and, under it, the error line: the shared outside of every date field. */
97
+ export function Notes({ hint, error, impossible, bounds, time = false, }) {
98
+ const { locale } = useLocale();
99
+ const { note } = useFieldType();
100
+ return (_jsxs(_Fragment, { children: [hint ? (_jsx(Text, { slot: "description", className: cx("text-slate-500", note), children: hint })) : null, _jsx(FieldError, { className: "block", children: (validation) => (_jsx(ErrorLine, { error: error || (impossible ?? builtIn(validation, bounds, locale, time)) })) })] }));
74
101
  }
75
102
  /** A `DateField`'s padding, by `size`: the heights of an `Input`. Its type is `controlText`'s, as an `Input`'s. */
76
103
  const FIELD_SIZE = {
@@ -78,34 +105,43 @@ const FIELD_SIZE = {
78
105
  md: "py-2 pl-2.5 pr-2.5",
79
106
  lg: "py-2.5 pl-3 pr-3",
80
107
  };
81
- export const labelClass = "text-sm font-medium text-slate-700";
108
+ /** `FIELD_SIZE` from the `md` breakpoint up, for a responsive size. */
109
+ const FIELD_SIZE_MD = {
110
+ sm: "md:py-1 md:pl-2 md:pr-2",
111
+ md: "md:py-2 md:pl-2.5 md:pr-2.5",
112
+ lg: "md:py-2.5 md:pl-3 md:pr-3",
113
+ };
114
+ /** The padding table and its `md:` twin, for the data test. */
115
+ export const fieldSizeTables = { pad: FIELD_SIZE, padMd: FIELD_SIZE_MD };
116
+ /** A date field's padding at `size`. */
117
+ export function fieldPad(size) {
118
+ return sizeClass(FIELD_SIZE, FIELD_SIZE_MD, size);
119
+ }
120
+ /** A date field's label look at the type step in force: a `Field`'s. */
121
+ export function useLabelClass() {
122
+ return cx(useFieldType().label, "font-medium text-slate-700");
123
+ }
124
+ /** A date field's visible label, with the required mark. */
125
+ export function FieldLabel({ label, required, }) {
126
+ const look = useLabelClass();
127
+ return label ? (_jsxs(Label, { className: look, children: [label, _jsx(RequiredMark, { required: required })] })) : null;
128
+ }
82
129
  /** A small icon button inside a date field or calendar, without its box size. */
83
130
  export const iconButtonLook = `inline-flex shrink-0 items-center justify-center rounded-md text-slate-500 transition hover:bg-slate-100 disabled:opacity-50 ${focusRing}`;
84
131
  export const iconButtonClass = `${iconButtonLook} h-7 w-7`;
85
132
  /**
86
- * A segmented DD / MM / YYYY date input. Values are `CalendarDate`s; `name` posts it as
87
- * `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
133
+ * A segmented date input, in the order of its `locale` (by default the browser's): DD / MM / YYYY
134
+ * in en-GB. Values are `CalendarDate`s; `name` posts it as `YYYY-MM-DD`. `calendar` adds a calendar button that opens a month view in a popover, at the
88
135
  * same height as the plain field; `defaultOpen` opens it on mount. While `loading` the label is
89
136
  * drawn and the field is a bone of its height.
90
137
  */
91
- export function DateField({ calendar, defaultOpen, monthLabel = "Month", yearLabel = "Year", loading, loadingLabel, ...field }) {
138
+ export function DateField({ calendar, defaultOpen, monthLabel = "Month", yearLabel = "Year", clearLabel = "Clear", loading, loadingLabel, ...field }) {
139
+ const labelClass = useLabelClass();
92
140
  if (useLoading(loading).loading) {
93
141
  return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
94
142
  }
95
143
  if (calendar) {
96
- return (_jsx(CalendarDateField, { ...field, labels: { monthLabel, yearLabel }, ...(defaultOpen === undefined ? {} : { defaultOpen }) }));
144
+ return (_jsx(CalendarDateField, { ...field, labels: { monthLabel, yearLabel, clearLabel }, ...(defaultOpen === undefined ? {} : { defaultOpen }) }));
97
145
  }
98
- return _jsx(PlainDateField, { ...field });
99
- }
100
- function PlainDateField({ label, hint, error, disabled, required, value, defaultValue, onChange, name, size = "md", ...rest }) {
101
- const step = useTypeStep();
102
- const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({
103
- value,
104
- defaultValue,
105
- onChange,
106
- minValue: rest.minValue,
107
- maxValue: rest.maxValue,
108
- isRequired: required,
109
- });
110
- return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDateField, { ...definedProps(rest), ...fieldFlags(disabled, required), value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), isReadOnly: leaving, onBlur: onLeft, granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(DateInput, { className: (state) => cx(frameClass(state), FIELD_SIZE[size], controlText(size, step, true)), children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, isInvalid: isInvalid })] })) }) }));
146
+ return _jsx(SegmentedField, { ...field, kind: DATE });
111
147
  }
@@ -1,14 +1,18 @@
1
1
  import { type ReactElement } from "react";
2
2
  import { type CalendarLabels } from "./DateCalendar.js";
3
3
  import { type FieldProps } from "./DateField.js";
4
- import type { Size } from "./size.js";
5
- /** The picker's padding and calendar button, by `size` (its type is `controlText`'s). The button sets the height, so the padding is less than a `DateField`'s. */
6
- export declare const PICKER_SIZE: Record<Size, {
7
- frame: string;
8
- button: string;
9
- }>;
4
+ import { type ResponsiveSize, type Size } from "./size.js";
5
+ /** The picker's tables and their `md:` twins (each `_MD` is its table from the `md` breakpoint up), for the data test. */
6
+ export declare const pickerSizeTables: {
7
+ frame: Record<Size, string>;
8
+ frameMd: Record<Size, string>;
9
+ button: Record<Size, string>;
10
+ buttonMd: Record<Size, string>;
11
+ };
12
+ /** The calendar button's box at `size`. */
13
+ export declare function pickerButton(size: Size | ResponsiveSize): string;
10
14
  /** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
11
- export declare function usePickerFrame(size: Size): string;
15
+ export declare function usePickerFrame(size: Size | ResponsiveSize): string;
12
16
  /**
13
17
  * The modal `<dialog>` a picker sits in, if any, for its popover's `container`: pass `findDialog` as the
14
18
  * picker's `ref`.
@@ -18,7 +22,7 @@ export declare function useDialogContainer(): {
18
22
  findDialog: (el: HTMLDivElement | null) => void;
19
23
  };
20
24
  /** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
21
- export declare function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size, ...rest }: FieldProps & {
25
+ export declare function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, locale, size, ...rest }: FieldProps & {
22
26
  defaultOpen?: boolean;
23
27
  labels: CalendarLabels;
24
28
  }): ReactElement;
@@ -1,21 +1,46 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useCallback, useContext, useState } from "react";
3
- import { Button, DatePicker as AriaDatePicker, DateFieldContext, DateInput, Group, I18nProvider, Label, } from "react-aria-components";
3
+ import { Button, DatePicker as AriaDatePicker, DateFieldContext, DateInput, Group, } from "react-aria-components";
4
4
  import { cx } from "./cx.js";
5
5
  import { CalendarPopover, calendarIcon } from "./DateCalendar.js";
6
- import { FieldSegment, LOCALE, fieldFlags, forcedInvalid, Notes, frameClass, iconButtonLook, labelClass, } from "./DateField.js";
6
+ import { FieldSegment, FieldLabel, fieldFlags, forcedInvalid, Notes, frameClass, iconButtonLook, } from "./DateField.js";
7
+ import { DateLocale } from "./dateLocale.js";
7
8
  import { definedProps } from "./props.js";
8
- import { ShownInput, useShownDate } from "./shownDate.js";
9
+ import { DATE, ShownInput, useShownDate } from "./shownDate.js";
10
+ import { sizeClass } from "./size.js";
9
11
  import { controlText, useTypeStep } from "./density.js";
10
12
  /** The picker's padding and calendar button, by `size` (its type is `controlText`'s). The button sets the height, so the padding is less than a `DateField`'s. */
11
- export const PICKER_SIZE = {
12
- sm: { frame: "py-0.5 pl-2 pr-0.5", button: "h-5 w-5" },
13
- md: { frame: "py-1 pl-2.5 pr-1", button: "h-7 w-7" },
14
- lg: { frame: "py-1.5 pl-3 pr-1.5", button: "h-8 w-8" },
13
+ const PICKER_FRAME = {
14
+ sm: "py-0.5 pl-2 pr-0.5",
15
+ md: "py-1 pl-2.5 pr-1",
16
+ lg: "py-1.5 pl-3 pr-1.5",
15
17
  };
18
+ const PICKER_FRAME_MD = {
19
+ sm: "md:py-0.5 md:pl-2 md:pr-0.5",
20
+ md: "md:py-1 md:pl-2.5 md:pr-1",
21
+ lg: "md:py-1.5 md:pl-3 md:pr-1.5",
22
+ };
23
+ const PICKER_BUTTON = { sm: "h-5 w-5", md: "h-7 w-7", lg: "h-8 w-8" };
24
+ const PICKER_BUTTON_MD = {
25
+ sm: "md:h-5 md:w-5",
26
+ md: "md:h-7 md:w-7",
27
+ lg: "md:h-8 md:w-8",
28
+ };
29
+ /** The picker's tables and their `md:` twins (each `_MD` is its table from the `md` breakpoint up), for the data test. */
30
+ export const pickerSizeTables = {
31
+ frame: PICKER_FRAME,
32
+ frameMd: PICKER_FRAME_MD,
33
+ button: PICKER_BUTTON,
34
+ buttonMd: PICKER_BUTTON_MD,
35
+ };
36
+ /** The calendar button's box at `size`. */
37
+ export function pickerButton(size) {
38
+ return sizeClass(PICKER_BUTTON, PICKER_BUTTON_MD, size);
39
+ }
16
40
  /** The picker's frame at `size`: its gap and padding, and the type of a control at the type step in force. */
17
41
  export function usePickerFrame(size) {
18
- return cx("gap-1", PICKER_SIZE[size].frame, controlText(size, useTypeStep(), true));
42
+ const pad = sizeClass(PICKER_FRAME, PICKER_FRAME_MD, size);
43
+ return cx("gap-1", pad, controlText(size, useTypeStep(), true));
19
44
  }
20
45
  /**
21
46
  * The picker's input, read-only while `leaving`. Only the field: a read-only picker would also
@@ -35,16 +60,10 @@ export function useDialogContainer() {
35
60
  return { container, findDialog };
36
61
  }
37
62
  /** The body of `<DateField calendar>`: the field with a calendar button that opens a month view in a popover. */
38
- export function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, size = "md", ...rest }) {
63
+ export function CalendarDateField({ label, hint, error, disabled, required, labels, value, defaultValue, onChange, name, locale, size = "md", ...rest }) {
39
64
  const frame = usePickerFrame(size);
40
- const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({
41
- value,
42
- defaultValue,
43
- onChange,
44
- minValue: rest.minValue,
45
- maxValue: rest.maxValue,
46
- isRequired: required,
47
- });
65
+ const bounds = { minValue: rest.minValue, maxValue: rest.maxValue };
66
+ const { inner, setInner, shown, impossible, onRead, validate, leaving, onBlurCapture, onLeft } = useShownDate({ value, defaultValue, onChange, ...bounds, isRequired: required }, DATE);
48
67
  const { container, findDialog } = useDialogContainer();
49
- return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDatePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ref: findDialog, value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(PickerInput, { leaving: leaving, onLeft: onLeft, children: _jsx(DateInput, { className: "flex flex-1", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }), _jsx(Button, { className: cx(iconButtonLook, PICKER_SIZE[size].button), children: calendarIcon })] }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, isInvalid: isInvalid }), _jsx(CalendarPopover, { container: container, labels: labels })] })) }) }));
68
+ return (_jsx(DateLocale, { locale: locale, children: _jsx(AriaDatePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ref: findDialog, value: inner, onChange: setInner, validate: validate, ...forcedInvalid({ impossible, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: () => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx("div", { className: "contents", onBlurCapture: onBlurCapture, children: _jsx(PickerInput, { leaving: leaving, onLeft: onLeft, children: _jsx(DateInput, { className: "flex flex-1", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }), _jsx(Button, { className: cx(iconButtonLook, pickerButton(size)), children: calendarIcon })] }), _jsx(ShownInput, { name: name, shown: shown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: impossible, bounds: bounds }), _jsx(CalendarPopover, { container: container, labels: labels })] })) }) }));
50
69
  }
@@ -9,7 +9,7 @@ export type DateRangePreset = {
9
9
  label: string;
10
10
  value: DateRange;
11
11
  };
12
- export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" | "size" | "minValue" | "maxValue" | "required" | "disabled"> & Passthrough & {
12
+ export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" | "size" | "minValue" | "maxValue" | "required" | "disabled" | "locale"> & Passthrough & {
13
13
  /** The range, or `null` for none. Reported only when both days are complete, real and in order. */
14
14
  value?: DateRange | null | undefined;
15
15
  /** The range shown first when the picker holds its own value. */
@@ -37,11 +37,31 @@ export type DateRangePickerProps = Pick<FieldProps, "label" | "hint" | "error" |
37
37
  * @default Year
38
38
  */
39
39
  yearLabel?: string | undefined;
40
+ /**
41
+ * The name of the start date's segments, for a screen reader.
42
+ * @default Start date
43
+ */
44
+ startLabel?: string | undefined;
45
+ /**
46
+ * The name of the end date's segments, for a screen reader.
47
+ * @default End date
48
+ */
49
+ endLabel?: string | undefined;
50
+ /**
51
+ * The word between the two dates.
52
+ * @default to
53
+ */
54
+ toLabel?: string | undefined;
55
+ /**
56
+ * The calendar's footer button that empties the range.
57
+ * @default Clear
58
+ */
59
+ clearLabel?: string | undefined;
40
60
  };
41
61
  /**
42
- * A from and to date in one field: DD/MM/YYYY "to" DD/MM/YYYY and a calendar button that opens one
62
+ * A from and to date in one field, each side in the locale's order, and a calendar button that opens one
43
63
  * Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
44
64
  * above the month. The range is reported only when both sides are complete, real dates within
45
65
  * min/max and the start is on or before the end; otherwise `null`.
46
66
  */
47
- export declare function DateRangePicker({ label, hint, error, disabled, required, monthLabel, yearLabel, value, defaultValue, onChange, startName, endName, presets, defaultOpen, size, ...rest }: DateRangePickerProps): ReactElement;
67
+ export declare function DateRangePicker({ label, hint, error, disabled, required, monthLabel, yearLabel, startLabel, endLabel, toLabel, clearLabel, value, defaultValue, onChange, startName, endName, presets, defaultOpen, locale, size, ...rest }: DateRangePickerProps): ReactElement;
@@ -1,10 +1,11 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
- import { Button, DateFieldContext, DateInput, DateRangePicker as AriaDateRangePicker, Group, I18nProvider, Label, } from "react-aria-components";
3
+ import { Button, DateFieldContext, DateInput, DateRangePicker as AriaDateRangePicker, Group, } from "react-aria-components";
4
4
  import { cx } from "./cx.js";
5
5
  import { RangeCalendarPopover, calendarIcon } from "./DateCalendar.js";
6
- import { FieldSegment, LOCALE, fieldFlags, forcedInvalid, frameClass, iconButtonLook, labelClass, Notes, } from "./DateField.js";
7
- import { PICKER_SIZE, useDialogContainer, usePickerFrame } from "./DateFieldCalendar.js";
6
+ import { FieldSegment, FieldLabel, fieldFlags, forcedInvalid, frameClass, iconButtonLook, Notes, } from "./DateField.js";
7
+ import { DateLocale } from "./dateLocale.js";
8
+ import { pickerButton, useDialogContainer, usePickerFrame } from "./DateFieldCalendar.js";
8
9
  import { definedProps } from "./props.js";
9
10
  import { ShownInput, useShownRange } from "./shownDate.js";
10
11
  /**
@@ -24,21 +25,22 @@ function SideInput({ slot, name, side, onRead, }) {
24
25
  }, children: _jsx(DateInput, { slot: slot, className: "flex", children: (segment) => (_jsx(FieldSegment, { segment: segment, ...(segment.type === "day" ? { onRead } : {}) })) }) }) }));
25
26
  }
26
27
  /**
27
- * A from and to date in one field: DD/MM/YYYY "to" DD/MM/YYYY and a calendar button that opens one
28
+ * A from and to date in one field, each side in the locale's order, and a calendar button that opens one
28
29
  * Monday-first month, where two presses pick the range. `presets` adds the app's ready-made ranges
29
30
  * above the month. The range is reported only when both sides are complete, real dates within
30
31
  * min/max and the start is on or before the end; otherwise `null`.
31
32
  */
32
- export function DateRangePicker({ label, hint, error, disabled, required, monthLabel = "Month", yearLabel = "Year", value, defaultValue, onChange, startName, endName, presets, defaultOpen, size = "md", ...rest }) {
33
+ export function DateRangePicker({ label, hint, error, disabled, required, monthLabel = "Month", yearLabel = "Year", startLabel = "Start date", endLabel = "End date", toLabel = "to", clearLabel = "Clear", value, defaultValue, onChange, startName, endName, presets, defaultOpen, locale, size = "md", ...rest }) {
33
34
  const frame = usePickerFrame(size);
35
+ // `rest` carries the bounds, as `Notes` reads them.
34
36
  const shown = useShownRange({
37
+ ...rest,
35
38
  value,
36
39
  defaultValue,
37
40
  onChange,
38
- minValue: rest.minValue,
39
- maxValue: rest.maxValue,
40
41
  isRequired: required,
42
+ labels: [startLabel, endLabel],
41
43
  });
42
44
  const { container, findDialog } = useDialogContainer();
43
- return (_jsx(I18nProvider, { locale: LOCALE, children: _jsx(AriaDateRangePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ...(defaultOpen === undefined ? {} : { defaultOpen }), ref: findDialog, value: shown.inner, onChange: shown.setInner, validate: shown.validate, ...forcedInvalid({ impossible: shown.problem, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: ({ isInvalid }) => (_jsxs(_Fragment, { children: [label ? _jsx(Label, { className: labelClass, children: label }) : null, _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx(SideInput, { slot: "start", name: "Start date", side: shown.start, onRead: shown.onReadStart }), _jsx("span", { "aria-hidden": "true", className: "px-1 text-slate-500", children: "to" }), _jsx(SideInput, { slot: "end", name: "End date", side: shown.end, onRead: shown.onReadEnd }), _jsx(Button, { className: cx(iconButtonLook, PICKER_SIZE[size].button, "ml-auto"), children: calendarIcon })] }), _jsx(ShownInput, { name: startName, shown: shown.startShown, isDisabled: disabled }), _jsx(ShownInput, { name: endName, shown: shown.endShown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: shown.problem, isInvalid: isInvalid }), _jsx(RangeCalendarPopover, { container: container, presets: presets, labels: { monthLabel, yearLabel } })] })) }) }));
45
+ return (_jsx(DateLocale, { locale: locale, children: _jsx(AriaDateRangePicker, { ...definedProps(rest), ...fieldFlags(disabled, required), ...(defaultOpen === undefined ? {} : { defaultOpen }), ref: findDialog, value: shown.inner, onChange: shown.setInner, validate: shown.validate, ...forcedInvalid({ impossible: shown.problem, error }), granularity: "day", shouldForceLeadingZeros: true, className: "flex flex-col gap-1.5", children: () => (_jsxs(_Fragment, { children: [_jsx(FieldLabel, { label: label, required: required }), _jsxs(Group, { className: (state) => cx(frameClass(state), frame), children: [_jsx(SideInput, { slot: "start", name: startLabel, side: shown.start, onRead: shown.onReadStart }), _jsx("span", { "aria-hidden": "true", className: "px-1 text-slate-500", children: toLabel }), _jsx(SideInput, { slot: "end", name: endLabel, side: shown.end, onRead: shown.onReadEnd }), _jsx(Button, { className: cx(iconButtonLook, pickerButton(size), "ml-auto"), children: calendarIcon })] }), _jsx(ShownInput, { name: startName, shown: shown.startShown, isDisabled: disabled }), _jsx(ShownInput, { name: endName, shown: shown.endShown, isDisabled: disabled }), _jsx(Notes, { hint: hint, error: error, impossible: shown.problem, bounds: rest }), _jsx(RangeCalendarPopover, { container: container, presets: presets, labels: { monthLabel, yearLabel, clearLabel } })] })) }) }));
44
46
  }
@@ -0,0 +1,31 @@
1
+ import type { CalendarDateTime, DateValue } from "@internationalized/date";
2
+ import type { ReactElement } from "react";
3
+ import { type FieldProps } from "./DateField.js";
4
+ import { type LoadingProps } from "./skeleton.js";
5
+ export type DateTimeFieldProps = Omit<FieldProps, "value" | "defaultValue" | "onChange" | "minValue" | "maxValue" | "name"> & LoadingProps & {
6
+ /** The date and time shown, controlled, with `onChange`; `null` is an empty field. */
7
+ value?: CalendarDateTime | null | undefined;
8
+ /** The date and time shown first when the field holds its own value. */
9
+ defaultValue?: CalendarDateTime | null | undefined;
10
+ /**
11
+ * Called with the date and time once every segment is filled, the day exists and it is within
12
+ * `minValue`/`maxValue`, and with `null` when it stops being one.
13
+ */
14
+ onChange?: ((value: CalendarDateTime | null) => void) | undefined;
15
+ /** The earliest date and time the field takes; earlier ones are invalid. */
16
+ minValue?: DateValue | null | undefined;
17
+ /** The latest date and time the field takes; later ones are invalid. */
18
+ maxValue?: DateValue | null | undefined;
19
+ /**
20
+ * Posts the date and time in a form as `YYYY-MM-DDTHH:mm` (24-hour) under this key, or an empty
21
+ * string, whatever the `locale`.
22
+ */
23
+ name?: string | undefined;
24
+ };
25
+ /**
26
+ * A segmented date and time input, to the minute: the date in the order of its `locale` (by default
27
+ * the browser's), then hours and minutes on the clock the locale uses, 24-hour in en-GB and with
28
+ * AM/PM in en-US. Values are `CalendarDateTime`s; `name` posts it as `YYYY-MM-DDTHH:mm`. It has no
29
+ * calendar. While `loading` the label is drawn and the field is a bone of its height.
30
+ */
31
+ export declare function DateTimeField({ loading, loadingLabel, ...field }: DateTimeFieldProps): ReactElement;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useLabelClass } from "./DateField.js";
3
+ import { SegmentedField } from "./SegmentedField.js";
4
+ import { WaitingField } from "./fieldWait.js";
5
+ import { DATE_TIME } from "./shownDate.js";
6
+ import { useLoading } from "./skeleton.js";
7
+ /**
8
+ * A segmented date and time input, to the minute: the date in the order of its `locale` (by default
9
+ * the browser's), then hours and minutes on the clock the locale uses, 24-hour in en-GB and with
10
+ * AM/PM in en-US. Values are `CalendarDateTime`s; `name` posts it as `YYYY-MM-DDTHH:mm`. It has no
11
+ * calendar. While `loading` the label is drawn and the field is a bone of its height.
12
+ */
13
+ export function DateTimeField({ loading, loadingLabel, ...field }) {
14
+ const labelClass = useLabelClass();
15
+ if (useLoading(loading).loading) {
16
+ return (_jsx(WaitingField, { own: loading, loadingLabel: loadingLabel, label: field.label, look: labelClass, size: field.size, attrs: field }));
17
+ }
18
+ return _jsx(SegmentedField, { ...field, kind: DATE_TIME });
19
+ }