@mrpelz/uikit-ish 7.8.0 → 7.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/dist/components/accordion/main.d.ts +12 -0
  2. package/dist/components/accordion/main.d.ts.map +1 -0
  3. package/dist/components/accordion/main.js +20 -0
  4. package/dist/components/accordion/main.js.map +1 -0
  5. package/dist/components/accordion/style.css +23 -0
  6. package/dist/components/action-sheet/main.d.ts +22 -16
  7. package/dist/components/action-sheet/main.d.ts.map +1 -1
  8. package/dist/components/action-sheet/main.js +89 -19
  9. package/dist/components/action-sheet/main.js.map +1 -1
  10. package/dist/components/action-sheet/props.d.ts +17 -5
  11. package/dist/components/action-sheet/props.d.ts.map +1 -1
  12. package/dist/components/action-sheet/style.css +24 -0
  13. package/dist/components/activity-view/main.d.ts +15 -4
  14. package/dist/components/activity-view/main.d.ts.map +1 -1
  15. package/dist/components/activity-view/main.js +27 -14
  16. package/dist/components/activity-view/main.js.map +1 -1
  17. package/dist/components/activity-view/props.d.ts +2 -10
  18. package/dist/components/activity-view/props.d.ts.map +1 -1
  19. package/dist/components/activity-view/style.css +29 -67
  20. package/dist/components/alert/main.d.ts +8 -7
  21. package/dist/components/alert/main.d.ts.map +1 -1
  22. package/dist/components/alert/main.js +32 -19
  23. package/dist/components/alert/main.js.map +1 -1
  24. package/dist/components/alert/props.d.ts +13 -2
  25. package/dist/components/alert/props.d.ts.map +1 -1
  26. package/dist/components/alert/style.css +36 -50
  27. package/dist/components/avatar/main.d.ts +5 -3
  28. package/dist/components/avatar/main.d.ts.map +1 -1
  29. package/dist/components/avatar/main.js +10 -8
  30. package/dist/components/avatar/main.js.map +1 -1
  31. package/dist/components/avatar/props.d.ts +4 -0
  32. package/dist/components/avatar/props.d.ts.map +1 -1
  33. package/dist/components/avatar/style.css +1 -7
  34. package/dist/components/badge/main.d.ts +3 -3
  35. package/dist/components/badge/main.d.ts.map +1 -1
  36. package/dist/components/badge/main.js +9 -9
  37. package/dist/components/badge/main.js.map +1 -1
  38. package/dist/components/badge/props.d.ts +4 -3
  39. package/dist/components/badge/props.d.ts.map +1 -1
  40. package/dist/components/badge/style.css +10 -4
  41. package/dist/components/button/main.d.ts.map +1 -1
  42. package/dist/components/button/main.js +15 -15
  43. package/dist/components/button/main.js.map +1 -1
  44. package/dist/components/button/props.d.ts +8 -8
  45. package/dist/components/button/props.d.ts.map +1 -1
  46. package/dist/components/button/style.css +37 -55
  47. package/dist/components/checkbox/main.d.ts.map +1 -1
  48. package/dist/components/checkbox/main.js +5 -7
  49. package/dist/components/checkbox/main.js.map +1 -1
  50. package/dist/components/checkbox/style.css +5 -8
  51. package/dist/components/collapsible/main.d.ts +9 -0
  52. package/dist/components/collapsible/main.d.ts.map +1 -0
  53. package/dist/components/collapsible/main.js +19 -0
  54. package/dist/components/collapsible/main.js.map +1 -0
  55. package/dist/components/collapsible/style.css +23 -0
  56. package/dist/components/color-picker/main.d.ts +27 -4
  57. package/dist/components/color-picker/main.d.ts.map +1 -1
  58. package/dist/components/color-picker/main.js +292 -110
  59. package/dist/components/color-picker/main.js.map +1 -1
  60. package/dist/components/color-picker/props.d.ts +64 -15
  61. package/dist/components/color-picker/props.d.ts.map +1 -1
  62. package/dist/components/color-picker/style.css +133 -65
  63. package/dist/components/contextual-menu/main.d.ts +11 -7
  64. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  65. package/dist/components/contextual-menu/main.js +207 -202
  66. package/dist/components/contextual-menu/main.js.map +1 -1
  67. package/dist/components/contextual-menu/props.d.ts +21 -34
  68. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  69. package/dist/components/contextual-menu/style.css +63 -34
  70. package/dist/components/date-picker/handle.d.ts +41 -0
  71. package/dist/components/date-picker/handle.d.ts.map +1 -0
  72. package/dist/components/date-picker/handle.js +47 -0
  73. package/dist/components/date-picker/handle.js.map +1 -0
  74. package/dist/components/date-picker/main.d.ts +31 -49
  75. package/dist/components/date-picker/main.d.ts.map +1 -1
  76. package/dist/components/date-picker/main.js +373 -178
  77. package/dist/components/date-picker/main.js.map +1 -1
  78. package/dist/components/date-picker/pager.d.ts +24 -0
  79. package/dist/components/date-picker/pager.d.ts.map +1 -0
  80. package/dist/components/date-picker/pager.js +307 -0
  81. package/dist/components/date-picker/pager.js.map +1 -0
  82. package/dist/components/date-picker/props.d.ts +98 -27
  83. package/dist/components/date-picker/props.d.ts.map +1 -1
  84. package/dist/components/date-picker/style.css +110 -118
  85. package/dist/components/drawer/main.d.ts +31 -0
  86. package/dist/components/drawer/main.d.ts.map +1 -0
  87. package/dist/components/drawer/main.js +119 -0
  88. package/dist/components/drawer/main.js.map +1 -0
  89. package/dist/components/drawer/props.d.ts +39 -0
  90. package/dist/components/drawer/props.d.ts.map +1 -0
  91. package/dist/components/drawer/props.js +2 -0
  92. package/dist/components/drawer/props.js.map +1 -0
  93. package/dist/components/drawer/style.css +135 -0
  94. package/dist/components/edit-menu/main.d.ts +7 -7
  95. package/dist/components/edit-menu/main.d.ts.map +1 -1
  96. package/dist/components/edit-menu/main.js +57 -40
  97. package/dist/components/edit-menu/main.js.map +1 -1
  98. package/dist/components/edit-menu/props.d.ts +14 -1
  99. package/dist/components/edit-menu/props.d.ts.map +1 -1
  100. package/dist/components/edit-menu/style.css +15 -8
  101. package/dist/components/form/main.d.ts +8 -0
  102. package/dist/components/form/main.d.ts.map +1 -1
  103. package/dist/components/form/main.js +18 -5
  104. package/dist/components/form/main.js.map +1 -1
  105. package/dist/components/form/props.d.ts +1 -2
  106. package/dist/components/form/props.d.ts.map +1 -1
  107. package/dist/components/glass/main.d.ts +1 -1
  108. package/dist/components/glass/main.js +4 -4
  109. package/dist/components/glass/main.js.map +1 -1
  110. package/dist/components/glass/props.d.ts +5 -5
  111. package/dist/components/glass/props.d.ts.map +1 -1
  112. package/dist/components/glass/style.css +176 -161
  113. package/dist/components/header/main.d.ts +5 -4
  114. package/dist/components/header/main.d.ts.map +1 -1
  115. package/dist/components/header/main.js +64 -34
  116. package/dist/components/header/main.js.map +1 -1
  117. package/dist/components/header/props.d.ts +2 -3
  118. package/dist/components/header/props.d.ts.map +1 -1
  119. package/dist/components/header/style.css +46 -65
  120. package/dist/components/index.d.ts +27 -23
  121. package/dist/components/index.d.ts.map +1 -1
  122. package/dist/components/index.js +17 -13
  123. package/dist/components/index.js.map +1 -1
  124. package/dist/components/layout/main.d.ts +2 -2
  125. package/dist/components/layout/main.d.ts.map +1 -1
  126. package/dist/components/layout/main.js +63 -167
  127. package/dist/components/layout/main.js.map +1 -1
  128. package/dist/components/layout/props.d.ts +2 -20
  129. package/dist/components/layout/props.d.ts.map +1 -1
  130. package/dist/components/layout/style.css +20 -91
  131. package/dist/components/list/main.d.ts +58 -10
  132. package/dist/components/list/main.d.ts.map +1 -1
  133. package/dist/components/list/main.js +1022 -465
  134. package/dist/components/list/main.js.map +1 -1
  135. package/dist/components/list/props.d.ts +211 -21
  136. package/dist/components/list/props.d.ts.map +1 -1
  137. package/dist/components/list/reorder.d.ts +146 -0
  138. package/dist/components/list/reorder.d.ts.map +1 -0
  139. package/dist/components/list/reorder.js +819 -0
  140. package/dist/components/list/reorder.js.map +1 -0
  141. package/dist/components/list/select.d.ts +6 -0
  142. package/dist/components/list/select.d.ts.map +1 -0
  143. package/dist/components/list/select.js +141 -0
  144. package/dist/components/list/select.js.map +1 -0
  145. package/dist/components/list/style.css +492 -507
  146. package/dist/components/list/swipe-actions-handle.d.ts +40 -0
  147. package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
  148. package/dist/components/list/swipe-actions-handle.js +51 -0
  149. package/dist/components/list/swipe-actions-handle.js.map +1 -0
  150. package/dist/components/menu/main.d.ts +102 -32
  151. package/dist/components/menu/main.d.ts.map +1 -1
  152. package/dist/components/menu/main.js +510 -99
  153. package/dist/components/menu/main.js.map +1 -1
  154. package/dist/components/menu/props.d.ts +5 -5
  155. package/dist/components/menu/props.d.ts.map +1 -1
  156. package/dist/components/menu/style.css +35 -43
  157. package/dist/components/navigation/main.d.ts +14 -2
  158. package/dist/components/navigation/main.d.ts.map +1 -1
  159. package/dist/components/navigation/main.js +437 -119
  160. package/dist/components/navigation/main.js.map +1 -1
  161. package/dist/components/navigation/props.d.ts +53 -3
  162. package/dist/components/navigation/props.d.ts.map +1 -1
  163. package/dist/components/navigation/style.css +56 -9
  164. package/dist/components/page/main.d.ts.map +1 -1
  165. package/dist/components/page/main.js +13 -8
  166. package/dist/components/page/main.js.map +1 -1
  167. package/dist/components/page/props.d.ts +8 -0
  168. package/dist/components/page/props.d.ts.map +1 -1
  169. package/dist/components/page/style.css +39 -4
  170. package/dist/components/page-control/main.d.ts +2 -2
  171. package/dist/components/page-control/main.d.ts.map +1 -1
  172. package/dist/components/page-control/main.js +66 -32
  173. package/dist/components/page-control/main.js.map +1 -1
  174. package/dist/components/page-control/props.d.ts +10 -2
  175. package/dist/components/page-control/props.d.ts.map +1 -1
  176. package/dist/components/page-control/style.css +7 -2
  177. package/dist/components/popover/main.d.ts +11 -6
  178. package/dist/components/popover/main.d.ts.map +1 -1
  179. package/dist/components/popover/main.js +63 -38
  180. package/dist/components/popover/main.js.map +1 -1
  181. package/dist/components/popover/props.d.ts +7 -6
  182. package/dist/components/popover/props.d.ts.map +1 -1
  183. package/dist/components/popover/style.css +54 -4
  184. package/dist/components/progress/main.d.ts +2 -3
  185. package/dist/components/progress/main.d.ts.map +1 -1
  186. package/dist/components/progress/main.js +148 -29
  187. package/dist/components/progress/main.js.map +1 -1
  188. package/dist/components/progress/props.d.ts +43 -9
  189. package/dist/components/progress/props.d.ts.map +1 -1
  190. package/dist/components/progress/style.css +82 -50
  191. package/dist/components/roll/main.d.ts +1 -1
  192. package/dist/components/roll/main.d.ts.map +1 -1
  193. package/dist/components/roll/main.js +90 -34
  194. package/dist/components/roll/main.js.map +1 -1
  195. package/dist/components/roll/props.d.ts +25 -8
  196. package/dist/components/roll/props.d.ts.map +1 -1
  197. package/dist/components/roll/style.css +12 -24
  198. package/dist/components/segmented/main.d.ts.map +1 -1
  199. package/dist/components/segmented/main.js +47 -30
  200. package/dist/components/segmented/main.js.map +1 -1
  201. package/dist/components/segmented/style.css +16 -23
  202. package/dist/components/sheet/main.d.ts +25 -15
  203. package/dist/components/sheet/main.d.ts.map +1 -1
  204. package/dist/components/sheet/main.js +66 -78
  205. package/dist/components/sheet/main.js.map +1 -1
  206. package/dist/components/sheet/props.d.ts +37 -3
  207. package/dist/components/sheet/props.d.ts.map +1 -1
  208. package/dist/components/sheet/style.css +183 -45
  209. package/dist/components/sidebar/main.d.ts.map +1 -1
  210. package/dist/components/sidebar/main.js +9 -13
  211. package/dist/components/sidebar/main.js.map +1 -1
  212. package/dist/components/sidebar/style.css +20 -14
  213. package/dist/components/slider/main.d.ts.map +1 -1
  214. package/dist/components/slider/main.js +23 -22
  215. package/dist/components/slider/main.js.map +1 -1
  216. package/dist/components/slider/props.d.ts +1 -2
  217. package/dist/components/slider/props.d.ts.map +1 -1
  218. package/dist/components/slider/style.css +27 -53
  219. package/dist/components/stepper/main.d.ts +4 -6
  220. package/dist/components/stepper/main.d.ts.map +1 -1
  221. package/dist/components/stepper/main.js +29 -25
  222. package/dist/components/stepper/main.js.map +1 -1
  223. package/dist/components/stepper/style.css +12 -16
  224. package/dist/components/switch/main.d.ts.map +1 -1
  225. package/dist/components/switch/main.js +40 -28
  226. package/dist/components/switch/main.js.map +1 -1
  227. package/dist/components/switch/props.d.ts +7 -5
  228. package/dist/components/switch/props.d.ts.map +1 -1
  229. package/dist/components/switch/style.css +40 -17
  230. package/dist/components/symbol/main.d.ts +2 -2
  231. package/dist/components/symbol/main.d.ts.map +1 -1
  232. package/dist/components/symbol/main.js +36 -28
  233. package/dist/components/symbol/main.js.map +1 -1
  234. package/dist/components/symbol/props.d.ts +39 -4
  235. package/dist/components/symbol/props.d.ts.map +1 -1
  236. package/dist/components/symbol/style.css +26 -5
  237. package/dist/components/tab-bar/main.d.ts +2 -2
  238. package/dist/components/tab-bar/main.d.ts.map +1 -1
  239. package/dist/components/tab-bar/main.js +133 -101
  240. package/dist/components/tab-bar/main.js.map +1 -1
  241. package/dist/components/tab-bar/props.d.ts +6 -6
  242. package/dist/components/tab-bar/props.d.ts.map +1 -1
  243. package/dist/components/tab-bar/style.css +113 -99
  244. package/dist/components/text-field/main.d.ts +3 -2
  245. package/dist/components/text-field/main.d.ts.map +1 -1
  246. package/dist/components/text-field/main.js +29 -30
  247. package/dist/components/text-field/main.js.map +1 -1
  248. package/dist/components/text-field/props.d.ts +23 -1
  249. package/dist/components/text-field/props.d.ts.map +1 -1
  250. package/dist/components/text-field/style.css +122 -82
  251. package/dist/components/toolbar/main.js +27 -27
  252. package/dist/components/toolbar/main.js.map +1 -1
  253. package/dist/components/toolbar/props.d.ts +10 -4
  254. package/dist/components/toolbar/props.d.ts.map +1 -1
  255. package/dist/components/toolbar/style.css +39 -33
  256. package/dist/components/tooltip/main.d.ts +10 -9
  257. package/dist/components/tooltip/main.d.ts.map +1 -1
  258. package/dist/components/tooltip/main.js +39 -10
  259. package/dist/components/tooltip/main.js.map +1 -1
  260. package/dist/components/tooltip/props.d.ts +2 -0
  261. package/dist/components/tooltip/props.d.ts.map +1 -1
  262. package/dist/components/tooltip/style.css +16 -16
  263. package/dist/components/typography/main.d.ts +2 -2
  264. package/dist/components/typography/main.d.ts.map +1 -1
  265. package/dist/components/typography/main.js +24 -16
  266. package/dist/components/typography/main.js.map +1 -1
  267. package/dist/components/typography/props.d.ts +11 -18
  268. package/dist/components/typography/props.d.ts.map +1 -1
  269. package/dist/components/typography/style.css +503 -623
  270. package/dist/components/utils/main.d.ts +78 -8
  271. package/dist/components/utils/main.d.ts.map +1 -1
  272. package/dist/components/utils/main.js +235 -16
  273. package/dist/components/utils/main.js.map +1 -1
  274. package/dist/components/utils/props.d.ts +27 -4
  275. package/dist/components/utils/props.d.ts.map +1 -1
  276. package/dist/components/utils/style.css +31 -18
  277. package/dist/components/viewport/edge-effect.d.ts +10 -0
  278. package/dist/components/viewport/edge-effect.d.ts.map +1 -0
  279. package/dist/components/viewport/edge-effect.js +100 -0
  280. package/dist/components/viewport/edge-effect.js.map +1 -0
  281. package/dist/components/viewport/edge.d.ts +39 -0
  282. package/dist/components/viewport/edge.d.ts.map +1 -0
  283. package/dist/components/viewport/edge.js +151 -0
  284. package/dist/components/viewport/edge.js.map +1 -0
  285. package/dist/components/viewport/input.d.ts +39 -0
  286. package/dist/components/viewport/input.d.ts.map +1 -0
  287. package/dist/components/viewport/input.js +280 -0
  288. package/dist/components/viewport/input.js.map +1 -0
  289. package/dist/components/viewport/main.d.ts +47 -9
  290. package/dist/components/viewport/main.d.ts.map +1 -1
  291. package/dist/components/viewport/main.js +745 -86
  292. package/dist/components/viewport/main.js.map +1 -1
  293. package/dist/components/viewport/padding.d.ts +78 -0
  294. package/dist/components/viewport/padding.d.ts.map +1 -0
  295. package/dist/components/viewport/padding.js +321 -0
  296. package/dist/components/viewport/padding.js.map +1 -0
  297. package/dist/components/viewport/props.d.ts +220 -11
  298. package/dist/components/viewport/props.d.ts.map +1 -1
  299. package/dist/components/viewport/style.css +377 -6
  300. package/dist/main.d.ts +0 -1
  301. package/dist/main.d.ts.map +1 -1
  302. package/dist/main.js.map +1 -1
  303. package/dist/styles.css +318 -302
  304. package/dist/styles.d.ts +2 -1
  305. package/dist/styles.d.ts.map +1 -1
  306. package/dist/styles.js +2 -1
  307. package/dist/styles.js.map +1 -1
  308. package/package.json +8 -16
@@ -5,43 +5,48 @@ import '../popover/style.css';
5
5
  import '../roll/style.css';
6
6
  import '../typography/style.css';
7
7
  import './style.css';
8
- import { forwardRef, Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from 'react';
8
+ import { Field as BaseField } from '@base-ui/react/field';
9
+ import { forwardRef, Fragment, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
9
10
  import { Button } from '../button/main.js';
11
+ import { List, useCollapsible, useExpandedOpen } from '../list/main.js';
10
12
  import { Popover } from '../popover/main.js';
11
13
  import { Roll } from '../roll/main.js';
12
14
  import { cn } from '../utils/main.js';
13
- // Source: Apple iOS 26 Figma (“Date and time - Collapsed”: State=Default/
14
- // Selected; “Date and time - Pickers”: Style=Inline/Compact; light and dark
15
- // appearance), with Figma colors mapped to UIKit semantic colors: the
16
- // collapsed buttons `tertiarySystemFill`, text `label` (selected: the tint),
17
- // weekdays `tertiaryLabel`, today and the arrows in the tint, the selected
18
- // day on the tint at 12%, the separator `separator`. Ranges follow
19
- // Framework7 (`calendar-ios.less`): their ends on the tint, the days between
20
- // on the tint at 12%.
15
+ import { createHandle } from './handle.js';
16
+ import { useMonthPager } from './pager.js';
17
+ // Collapsed buttons (default and selected) and pickers (inline and
18
+ // compact), light and dark, in the semantic colors: the collapsed buttons
19
+ // `tertiarySystemFill`, text `label` (selected: the tint), weekdays
20
+ // `tertiaryLabel`, today and the arrows in the tint, the selected day on the
21
+ // tint at 12%, the separator `separator`. Ranges follow Framework7
22
+ // (`calendar-ios.less`): their ends on the tint, the days between on the
23
+ // tint at 12%.
21
24
  //
22
- // A date picker (UIKit `UIDatePicker`): `mode` picks a date, a time or both;
23
- // `pickerStyle` shows them `compact` (collapsed buttons, opening the
24
- // calendar or the time in a popover, a Base UI `Popover`) or `inline` (the
25
- // calendar in place). Names, numerals, the hour cycle and the week's first
26
- // day follow the locale (`Intl`). With `range`, two days are picked: a start
27
- // and an end (Framework7 `rangePicker`; UIKit: none), highlighted with the
28
- // days between.
25
+ // A date picker: `mode` picks a date, a time or both; `pickerStyle` shows
26
+ // them `compact` (collapsed buttons, opening the calendar or the time in a
27
+ // popover, a Base UI `Popover`) or `inline` (the calendar in place). Names,
28
+ // numerals, the hour cycle and the week's first day follow the locale
29
+ // (`Intl`). With `range`, two days are picked: a start and an end
30
+ // (Framework7 `rangePicker`), highlighted with the days between.
29
31
  //
30
32
  // The calendar is a group of day buttons (one tabbable): arrow keys move by
31
33
  // a day or week, Page Up/Down by a month, Home/End to the week's ends. Its
32
- // title opens a month and year roll (see `Roll`) over the days (as iOS's),
33
- // the time's button a roll of hours and minutes (both editable: pressing the
34
- // selected row, or typing, enters a number), as the compact time's popover.
34
+ // title opens a month and year roll (see `Roll`) over the days, the time's
35
+ // button a roll of hours and minutes (both editable: pressing the selected
36
+ // row, or typing, enters a number), as the compact time's popover.
35
37
  //
36
- // Deviations:
37
- // - The rolls take the days' place (iOS: the month and year roll does; the
38
- // time's opens in a popover).
39
- // - The popover is `Popover`'s (the menus' glass, see there; Figma: the
40
- // “Regular” material, blur 50px), its corners 13px, as Figma's.
41
- // - The calendar's width (Figma: 370px) is a minimum: 7 × 44px days, 16px
42
- // from the sides.
43
- // - The collapsed buttons are capsules (or, `buttonShape`, Figma's 6px
44
- // corners).
38
+ // Also:
39
+ // - The rolls take the days' place (the time's too).
40
+ // - The popover is `Popover`'s (the menus' glass, see there), its corners
41
+ // 13px.
42
+ // - The calendar's width is a minimum: 7 × 44px days, 16px from the sides.
43
+ // - The collapsed buttons are capsules (or, `buttonShape`, 6px corners).
44
+ // What swiping the days does (see `swipe`): a range dragged only picking
45
+ // one.
46
+ const swipeOf = (swipe, isRange) => {
47
+ const value = swipe ?? (isRange ? 'date-range' : 'month');
48
+ return value === 'date-range' && !isRange ? 'ignore' : value;
49
+ };
45
50
  // Dates (local time).
46
51
  const startOfDay = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
47
52
  const startOfMonth = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
@@ -127,15 +132,20 @@ const rangePlace = (day, range) => {
127
132
  return 'middle';
128
133
  return undefined;
129
134
  };
135
+ /**
136
+ * How long (ms) after a month settled (a swipe's scroll ending) the
137
+ * calendar's height changes (see `CalendarPanel`).
138
+ */
139
+ const resizeDelay = 200;
130
140
  /** Controlled or uncontrolled state (as Base UI's components). */
131
141
  const useControlled = (value, defaultValue) => {
132
142
  const [state, setState] = useState(defaultValue);
133
143
  return [value === undefined ? state : value, setState];
134
144
  };
135
145
  const CollapsedButton = forwardRef(({ className, shape, ...props }, ref) => (_jsx(Button.Root, { ref: ref, shape: shape === 'roundedRectangle' ? 'roundedRectangle' : 'capsule', type: "button", variant: "bordered-secondary", ...props, className: cn('uikit-date-picker-collapsed-button', className), "data-date-picker-part": "collapsed-button" })));
136
- // Figma “Time”: a 52px row, the title (Body) and the time.
146
+ // A time row: a 52px row, the title (Body) and the time.
137
147
  const TimeRow = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, className: cn('uikit-date-picker-time-row', className), "data-date-picker-part": "time-row", ...props })));
138
- const Chevron = ({ next }) => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "20", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2.4", viewBox: "0 0 12 20", width: "12", children: _jsx("path", { d: next ? 'M3 2l7 8-7 8' : 'M9 2l-7 8 7 8' }) }));
148
+ const Chevron = ({ isNext }) => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "20", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2.4", viewBox: "0 0 12 20", width: "12", children: _jsx("path", { d: isNext ? 'M3 2l7 8-7 8' : 'M9 2l-7 8 7 8' }) }));
139
149
  const Disclosure = () => (_jsx("svg", { "aria-hidden": "true", fill: "none", height: "0.75em", stroke: "currentcolor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 8 14", width: "0.43em", children: _jsx("path", { d: "M1.5 1.5L6.5 7l-5 5.5" }) }));
140
150
  /** The locale's hour cycle, and whether the day period comes first. */
141
151
  const timeFormat = (locale, cycle) => {
@@ -146,24 +156,33 @@ const timeFormat = (locale, cycle) => {
146
156
  });
147
157
  const { hourCycle = 'h23' } = format.resolvedOptions();
148
158
  const parts = format.formatToParts(new Date(2000, 0, 1, 21, 41));
149
- const periodFirst = parts.findIndex(({ type }) => type === 'dayPeriod') <
159
+ const isPeriodFirst = parts.findIndex(({ type }) => type === 'dayPeriod') <
150
160
  parts.findIndex(({ type }) => type === 'hour');
151
161
  const period = (hour) => format
152
162
  .formatToParts(new Date(2000, 0, 1, hour))
153
163
  .find(({ type }) => type === 'dayPeriod')?.value ?? '';
154
164
  return {
155
165
  hourCycle,
156
- periodFirst: periodFirst && parts.some(({ type }) => type === 'dayPeriod'),
166
+ periodFirst: isPeriodFirst && parts.some(({ type }) => type === 'dayPeriod'),
157
167
  periods: [period(9), period(21)],
158
168
  twelve: hourCycle === 'h11' || hourCycle === 'h12',
159
169
  };
160
170
  };
161
171
  /**
162
172
  * The time as a roll: hours, minutes and (12 hours) the day period, the
163
- * numbers editable (e.g. in an expandable list row, see `DatePicker`).
173
+ * numbers editable (e.g. in an expandable list row, see `DatePicker.Root`).
164
174
  */
165
- const TimeRoll = ({ hourCycle: cycle, locale, onValueChange: onChange, value, }) => {
175
+ const TimeRoll = ({ hourCycle: cycle, locale, max, min, onValueChange: onChange, value, }) => {
166
176
  const date = value ?? new Date();
177
+ // Its day at a time, and whether that's beyond the limits.
178
+ const at = (hour, minute) => {
179
+ const next = new Date(date);
180
+ next.setHours(hour, minute, 0, 0);
181
+ return next;
182
+ };
183
+ const isBeyond = (time) => (min !== undefined && time < min) || (max !== undefined && time > max);
184
+ // Some of the hours' minutes (from, to) within the limits.
185
+ const isWithin = (from, to) => (min === undefined || to >= min) && (max === undefined || from <= max);
167
186
  const { hourCycle, periodFirst, periods, twelve } = useMemo(() => timeFormat(locale, cycle), [cycle, locale]);
168
187
  const numbers = useMemo(() => ({
169
188
  hour: new Intl.NumberFormat(locale, {
@@ -172,26 +191,31 @@ const TimeRoll = ({ hourCycle: cycle, locale, onValueChange: onChange, value, })
172
191
  minute: new Intl.NumberFormat(locale, { minimumIntegerDigits: 2 }),
173
192
  }), [locale, twelve]);
174
193
  const hours = date.getHours();
175
- const pm = hours >= 12;
194
+ const isPm = hours >= 12;
176
195
  const hourValues = twelve
177
196
  ? Array.from({ length: 12 }, (_, index) => hourCycle === 'h12' ? index + 1 : index)
178
197
  : Array.from({ length: 24 }, (_, index) => index);
179
198
  const twelveHour = hourCycle === 'h12' ? hours % 12 || 12 : hours % 12;
180
199
  const shownHour = twelve ? twelveHour : hours;
181
- const set = (hour, minute) => {
182
- const next = new Date(date);
183
- next.setHours(hour, minute, 0, 0);
184
- onChange(next);
200
+ // Beyond the limits: the nearest within them (the roll moving back).
201
+ const set = (hour, minute, { event }) => {
202
+ let next = at(hour, minute);
203
+ if (min !== undefined && next < min)
204
+ next = new Date(min);
205
+ if (max !== undefined && next > max)
206
+ next = new Date(max);
207
+ onChange(next, { event, reason: 'time' });
185
208
  };
186
- const period = (_jsxs(Roll.Column, { "aria-label": "AM/PM", value: pm ? 'pm' : 'am', onValueChange: (next) => {
187
- if ((next === 'pm') === pm)
209
+ // A shown hour's (of the shown period, with 12 hours), as 0–23.
210
+ const hourOf = (hour) => twelve ? (hour % 12) + (isPm ? 12 : 0) : hour;
211
+ const period = (_jsxs(Roll.Column, { "aria-label": "AM/PM", value: isPm ? 'pm' : 'am', onValueChange: (next, details) => {
212
+ if ((next === 'pm') === isPm)
188
213
  return;
189
- set((hours + 12) % 24, date.getMinutes());
190
- }, children: [_jsx(Roll.Item, { value: "am", children: periods[0] }), _jsx(Roll.Item, { value: "pm", children: periods[1] })] }));
191
- return (_jsxs(Roll.Root, { children: [twelve && periodFirst ? period : null, _jsx(Roll.Column, { editable: true, align: "end", "aria-label": "Hours", value: shownHour, onValueChange: (next) => {
192
- const hour = Number(next);
193
- set(twelve ? (hour % 12) + (pm ? 12 : 0) : hour, date.getMinutes());
194
- }, children: hourValues.map((hour) => (_jsx(Roll.Item, { value: hour, children: numbers.hour.format(hour) }, hour))) }), _jsx(Roll.Column, { editable: true, align: "start", "aria-label": "Minutes", value: date.getMinutes(), onValueChange: (next) => set(hours, Number(next)), children: Array.from({ length: 60 }, (_, minute) => (_jsx(Roll.Item, { value: minute, children: numbers.minute.format(minute) }, minute))) }), twelve && !periodFirst ? period : null] }));
214
+ set((hours + 12) % 24, date.getMinutes(), details);
215
+ }, children: [_jsx(Roll.Item, { disabled: !isWithin(at(0, 0), at(11, 59)), value: "am", children: periods[0] }), _jsx(Roll.Item, { disabled: !isWithin(at(12, 0), at(23, 59)), value: "pm", children: periods[1] })] }));
216
+ return (_jsxs(Roll.Root, { children: [twelve && periodFirst ? period : null, _jsx(Roll.Column, { editable: true, align: "end", "aria-label": "Hours", value: shownHour, onValueChange: (next, details) => {
217
+ set(hourOf(Number(next)), date.getMinutes(), details);
218
+ }, children: hourValues.map((hour) => (_jsx(Roll.Item, { disabled: !isWithin(at(hourOf(hour), 0), at(hourOf(hour), 59)), value: hour, children: numbers.hour.format(hour) }, hour))) }), _jsx(Roll.Column, { editable: true, align: "start", "aria-label": "Minutes", value: date.getMinutes(), onValueChange: (next, details) => set(hours, Number(next), details), children: Array.from({ length: 60 }, (_, minute) => (_jsx(Roll.Item, { disabled: isBeyond(at(hours, minute)), value: minute, children: numbers.minute.format(minute) }, minute))) }), twelve && !periodFirst ? period : null] }));
195
219
  };
196
220
  const clampMonth = (month, min, max) => {
197
221
  if (min && month < startOfMonth(min))
@@ -238,14 +262,16 @@ const useCalendarValue = (props) => {
238
262
  setDraggedFrom,
239
263
  setValue,
240
264
  single,
265
+ // (Either.)
266
+ value: range ?? single,
241
267
  };
242
268
  };
243
269
  /** The footer's state and actions (see `CalendarFooter`). */
244
270
  const footerOf = ({ time, ...footer }) => {
245
271
  if (!time)
246
272
  return { ...footer, disabled: false };
247
- const { disabled, shape, ...rest } = time;
248
- return { ...footer, buttonShape: shape, disabled, time: rest };
273
+ const { disabled: isDisabled, shape, ...rest } = time;
274
+ return { ...footer, buttonShape: shape, disabled: isDisabled, time: rest };
249
275
  };
250
276
  /** A day's button's date (see `CalendarPanel`). */
251
277
  const dayOf = (target) => {
@@ -281,17 +307,39 @@ const rangeReach = (fixed, selectable, hasDisabledDays, isRangeDisabled) => {
281
307
  };
282
308
  /** A range from two days, in either order. */
283
309
  const between = (a, b) => a <= b ? { end: b, start: a } : { end: a, start: b };
284
- /** The calendar (Figma “Style=Inline”), with an optional time row. */
310
+ const twoDigits = (value) => String(value).padStart(2, '0');
311
+ const isoDate = (date) => `${String(date.getFullYear())}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())}`;
312
+ const isoTime = (date) => `${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}`;
313
+ /**
314
+ * A value as a form submits it (an input's formats; a range's interval, or
315
+ * nothing until its end is picked).
316
+ */
317
+ const formValueOf = (value, mode = 'date') => {
318
+ if (!value)
319
+ return '';
320
+ if (!(value instanceof Date)) {
321
+ return value.end ? `${isoDate(value.start)}/${isoDate(value.end)}` : '';
322
+ }
323
+ if (mode === 'time')
324
+ return isoTime(value);
325
+ if (mode === 'dateAndTime')
326
+ return `${isoDate(value)}T${isoTime(value)}`;
327
+ return isoDate(value);
328
+ };
329
+ /**
330
+ * Its value's hidden control (Base UI's field control): submitted by its
331
+ * `name`, or, in a Base UI `Field`, as the field's.
332
+ */
333
+ const FormValue = ({ form, mode, name, isOmitted = false, value }) => isOmitted ? null : (_jsx(BaseField.Control, { form: form, name: name, type: "hidden", value: formValueOf(value, mode) }));
334
+ /** The calendar (inline), with an optional time row. */
285
335
  const CalendarPanel = (props) => {
286
336
  const { firstDayOfWeek: weekStartProp, highlighted, highlightedWeekdays = [], hourCycle, isDateDisabled, label, locale, max, min, showAdjacentMonths, time, } = props;
287
- const { dragged, draggedFrom, range, setDragged, setDraggedFrom, setValue, single, } = useCalendarValue(props);
337
+ const { dragged, draggedFrom, range, setDragged, setDraggedFrom, setValue, single, value, } = useCalendarValue(props);
288
338
  const today = startOfDay(new Date());
289
339
  const [month, setMonth] = useState(() => startOfMonth(range?.start ?? single ?? today));
290
340
  const [focused, setFocused] = useState(() => clampDay(startOfDay(range?.start ?? single ?? today), min, max));
291
341
  const [rolled, setRolled] = useState(props.initialRoll);
292
- // The month slid out while another slides in (see below).
293
- const [leaving, setLeaving] = useState(undefined);
294
- const leavingRef = useRef(null);
342
+ const swipes = swipeOf(props.swipe, Boolean(props.range));
295
343
  const pagesRef = useRef(null);
296
344
  const daysRef = useRef(null);
297
345
  const focusNext = useRef(undefined);
@@ -302,7 +350,10 @@ const CalendarPanel = (props) => {
302
350
  monthRef.current = month;
303
351
  });
304
352
  const suppressClick = useRef(false);
305
- const height = useRef(undefined);
353
+ // The body's height, and its transition running (see below).
354
+ const bodyRef = useRef(null);
355
+ const bodyHeight = useRef(undefined);
356
+ const transition = useRef(undefined);
306
357
  const titleId = useId();
307
358
  const rollId = useId();
308
359
  const formats = useMemo(() => ({
@@ -340,60 +391,101 @@ const CalendarPanel = (props) => {
340
391
  focusNext.current = undefined;
341
392
  day.focus();
342
393
  });
343
- // Months of more or fewer weeks: the days' height transitions.
344
- useLayoutEffect(() => {
345
- const { current: days } = daysRef;
346
- if (!days)
347
- return;
348
- const next = days.offsetHeight;
349
- const previous = height.current;
350
- height.current = next;
351
- if (previous === undefined || previous === next)
352
- return;
353
- // Clipped meanwhile (not at rest: it'd clip the focus rings).
354
- days.style.overflow = 'clip';
355
- const animation = days.animate([{ height: `${String(previous)}px` }, { height: `${String(next)}px` }], { duration: 300, easing: 'ease' });
356
- animation.finished
357
- .then(() => days.style.removeProperty('overflow'))
358
- .catch(() => days.style.removeProperty('overflow'));
359
- }, [month, weekStart]);
360
- // Months slide in from the side they're in (next: the inline end), the
361
- // previous one sliding out (as iOS's).
362
- const goTo = (next) => {
363
- const target = startOfMonth(next);
364
- const direction = Math.sign(target.getTime() - month.getTime());
365
- if (direction === 0)
366
- return;
367
- setLeaving({ direction, month });
368
- setMonth(target);
369
- };
394
+ // The strip as high as the shown month's days (its neighbours' clipped),
395
+ // as they're laid out (not while hidden, e.g. in a closed row: none).
396
+ // Months of more or fewer weeks: the strip resized at once, the body
397
+ // around it transitioning (its content clipped meanwhile), a moment after
398
+ // the month settled (`resizeDelay`: resized as a swipe settled, it
399
+ // faltered). Under a roll, kept as it was (no shifts mid-roll):
400
+ // transitioning once the roll closes, at once.
401
+ const isRolled = rolled !== undefined;
402
+ const wasRolled = useRef(isRolled);
370
403
  useLayoutEffect(() => {
371
404
  const { current: days } = daysRef;
372
405
  const { current: pages } = pagesRef;
373
- const { current: page } = leavingRef;
374
- if (!leaving || !days || !pages || !page)
406
+ const { current: body } = bodyRef;
407
+ const isClosing = wasRolled.current && !isRolled;
408
+ wasRolled.current = isRolled;
409
+ if (!days || !pages || !body || isRolled)
375
410
  return undefined;
376
- const rtl = getComputedStyle(pages).direction === 'rtl' ? -1 : 1;
377
- const shift = (fraction) => `translateX(${String(fraction * leaving.direction * rtl * 100)}%)`;
378
- const options = { duration: 300, easing: 'ease' };
379
- pages.style.overflow = 'clip';
380
- const animations = [
381
- days.animate([{ transform: shift(1) }, { transform: 'none' }], options),
382
- page.animate([{ transform: 'none' }, { transform: shift(-1) }], options),
383
- ];
384
- const [incoming] = animations;
385
- incoming?.finished
386
- .then(() => {
387
- pages.style.removeProperty('overflow');
388
- setLeaving(undefined);
389
- })
390
- .catch(() => undefined);
411
+ let isPending = false;
412
+ const fit = () => {
413
+ if (days.offsetHeight === 0)
414
+ return false;
415
+ pages.style.height = `${String(days.offsetHeight)}px`;
416
+ return true;
417
+ };
418
+ const resize = () => {
419
+ isPending = false;
420
+ if (!fit())
421
+ return;
422
+ const next = body.offsetHeight;
423
+ const previous = bodyHeight.current;
424
+ bodyHeight.current = next;
425
+ if (previous === undefined || previous === next)
426
+ return;
427
+ transition.current?.cancel();
428
+ body.style.overflow = 'clip';
429
+ const animation = body.animate([{ height: `${String(previous)}px` }, { height: `${String(next)}px` }], { duration: 300, easing: 'ease' });
430
+ transition.current = animation;
431
+ const done = () => {
432
+ if (transition.current === animation) {
433
+ body.style.removeProperty('overflow');
434
+ }
435
+ };
436
+ animation.addEventListener('finish', done);
437
+ animation.addEventListener('cancel', done);
438
+ };
439
+ let timer;
440
+ if (bodyHeight.current === undefined || isClosing) {
441
+ resize();
442
+ }
443
+ else {
444
+ isPending = true;
445
+ timer = setTimeout(resize, resizeDelay);
446
+ }
447
+ // Resized otherwise (e.g. the text size): at once, the body's height
448
+ // as it is (not mid-transition: its own then).
449
+ const observer = new ResizeObserver(() => {
450
+ if (isPending)
451
+ return;
452
+ fit();
453
+ if (transition.current?.playState === 'running')
454
+ return;
455
+ bodyHeight.current = body.offsetHeight;
456
+ });
457
+ observer.observe(days);
391
458
  return () => {
392
- for (const animation of animations)
393
- animation.cancel();
394
- pages.style.removeProperty('overflow');
459
+ clearTimeout(timer);
460
+ observer.disconnect();
395
461
  };
396
- }, [leaving]);
462
+ }, [isRolled, month, weekStart]);
463
+ // The months side by side, scrolled sideways (see pager.ts): turned to,
464
+ // by scrolling, its day focused.
465
+ const isPreviousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
466
+ const isNextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
467
+ const pager = useMonthPager({
468
+ // A month's neighbour, not beyond the limits (as the arrows').
469
+ beside: (shown, step) => {
470
+ const at = startOfMonth(addMonths(shown, step));
471
+ const last = addDays(startOfMonth(addMonths(at, 1)), -1);
472
+ if (min && last < startOfDay(min))
473
+ return undefined;
474
+ if (max && at > startOfDay(max))
475
+ return undefined;
476
+ return at;
477
+ },
478
+ isDraggable: swipes === 'month',
479
+ isInstant: rolled !== undefined,
480
+ month,
481
+ onTurn: (next, isScrolled) => {
482
+ setMonth(next);
483
+ if (isScrolled)
484
+ setFocused(clampDay(next, min, max));
485
+ },
486
+ pagesRef,
487
+ });
488
+ const { goTo } = pager;
397
489
  // Moved by keyboard: on past disabled days (in the direction moved), to
398
490
  // one that can be focused.
399
491
  const moveTo = (date) => {
@@ -411,42 +503,42 @@ const CalendarPanel = (props) => {
411
503
  goTo(target);
412
504
  focusNext.current = target;
413
505
  };
414
- const changeTime = (date) => {
506
+ const changeTime = (date, details) => {
415
507
  setValue(date);
416
508
  if (!props.range)
417
- props.onValueChange?.(date);
509
+ props.onValueChange?.(date, details);
418
510
  };
419
- const commitRange = (next) => {
511
+ const commitRange = (next, details) => {
420
512
  if (!props.range)
421
513
  return;
422
514
  setValue(next);
423
- props.onValueChange?.(next);
515
+ props.onValueChange?.(next, details);
424
516
  };
425
- const select = (date, withTime = false) => {
517
+ const select = (date, hasTime, details) => {
426
518
  setFocused(startOfDay(date));
427
519
  if (props.range) {
428
520
  // A new range, or its end (before its start: the other way round; out
429
521
  // of the start's reach, a new range).
430
522
  commitRange(!range || range.end || !reachable(date)
431
523
  ? { end: null, start: date }
432
- : between(range.start, date));
524
+ : between(range.start, date), details);
433
525
  return;
434
526
  }
435
527
  // Keeps the time of an earlier value (unless taking the date's).
436
528
  const next = new Date(date);
437
- if (single && !withTime) {
529
+ if (single && !hasTime) {
438
530
  next.setHours(single.getHours(), single.getMinutes(), 0, 0);
439
531
  }
440
532
  setValue(next);
441
- props.onValueChange?.(next);
533
+ props.onValueChange?.(next, details);
442
534
  };
443
535
  const onKeyDown = (event) => {
444
- const rtl = getComputedStyle(event.currentTarget).direction === 'rtl';
536
+ const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
445
537
  const column = (focused.getDay() - weekStart + 7) % 7;
446
538
  const moves = {
447
539
  ArrowDown: () => addDays(focused, 7),
448
- ArrowLeft: () => addDays(focused, rtl ? 1 : -1),
449
- ArrowRight: () => addDays(focused, rtl ? -1 : 1),
540
+ ArrowLeft: () => addDays(focused, isRightToLeft ? 1 : -1),
541
+ ArrowRight: () => addDays(focused, isRightToLeft ? -1 : 1),
450
542
  ArrowUp: () => addDays(focused, -7),
451
543
  End: () => addDays(focused, 6 - column),
452
544
  Home: () => addDays(focused, -column),
@@ -462,7 +554,7 @@ const CalendarPanel = (props) => {
462
554
  // Ranges are also dragged into existence: from the day pressed to the day
463
555
  // under the pointer, picked on release (taps pick start and end).
464
556
  const onPointerDown = (event) => {
465
- if (!props.range || event.button !== 0)
557
+ if (swipes !== 'date-range' || event.button !== 0)
466
558
  return;
467
559
  const from = dayOf(event.target);
468
560
  if (!from || !enabled(from))
@@ -470,7 +562,7 @@ const CalendarPanel = (props) => {
470
562
  drag.current = {
471
563
  edge: 0,
472
564
  from,
473
- moved: false,
565
+ isMoved: false,
474
566
  reachable: reachOf(from),
475
567
  x: event.clientX,
476
568
  y: event.clientY,
@@ -503,15 +595,17 @@ const CalendarPanel = (props) => {
503
595
  dragging.timer = setTimeout(step, 500);
504
596
  };
505
597
  const onPointerMove = (event) => {
598
+ if (swipes !== 'date-range')
599
+ return;
506
600
  const { current: dragging } = drag;
507
601
  if (!dragging)
508
602
  return;
509
- if (!dragging.moved) {
603
+ if (!dragging.isMoved) {
510
604
  if (Math.hypot(event.clientX - dragging.x, event.clientY - dragging.y) < 6) {
511
605
  return;
512
606
  }
513
607
  // Moves beyond the days are its own, too (the edges, see turnPage).
514
- dragging.moved = true;
608
+ dragging.isMoved = true;
515
609
  event.currentTarget.setPointerCapture(event.pointerId);
516
610
  setDraggedFrom(dragging.from);
517
611
  setDragged(between(dragging.from, dragging.from));
@@ -520,28 +614,34 @@ const CalendarPanel = (props) => {
520
614
  // days, or beyond their inline end): on to the next month; before its
521
615
  // first: back.
522
616
  const { bottom, left, right, top } = event.currentTarget.getBoundingClientRect();
523
- const rtl = getComputedStyle(event.currentTarget).direction === 'rtl';
617
+ const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
524
618
  const under = document.elementFromPoint(event.clientX, event.clientY);
525
619
  const outside = under instanceof Element
526
620
  ? under.closest('[data-outside]')?.dataset.outside
527
621
  : undefined;
528
- const beyondEnd = rtl ? event.clientX < left : event.clientX > right;
529
- const beyondStart = rtl ? event.clientX > right : event.clientX < left;
530
- const after = event.clientY > bottom || beyondEnd || outside === 'after';
531
- const before = event.clientY < top || beyondStart || outside === 'before';
532
- turnPage(Number(after) - Number(before));
622
+ const isBeyondEnd = isRightToLeft
623
+ ? event.clientX < left
624
+ : event.clientX > right;
625
+ const isBeyondStart = isRightToLeft
626
+ ? event.clientX > right
627
+ : event.clientX < left;
628
+ const isAfter = event.clientY > bottom || isBeyondEnd || outside === 'after';
629
+ const isBefore = event.clientY < top || isBeyondStart || outside === 'before';
630
+ turnPage(Number(isAfter) - Number(isBefore));
533
631
  const over = dayOf(under);
534
632
  if (!over || !selectable(over) || !dragging.reachable(over))
535
633
  return;
536
634
  setDragged(between(dragging.from, over));
537
635
  setFocused(over);
538
636
  };
539
- const onPointerEnd = () => {
637
+ const onPointerEnd = (event) => {
638
+ if (swipes !== 'date-range')
639
+ return;
540
640
  const { current: dragging } = drag;
541
641
  clearTimeout(dragging?.timer);
542
642
  drag.current = undefined;
543
643
  setDraggedFrom(null);
544
- if (!dragging?.moved || !dragged) {
644
+ if (!dragging?.isMoved || !dragged) {
545
645
  setDragged(null);
546
646
  return;
547
647
  }
@@ -551,14 +651,12 @@ const CalendarPanel = (props) => {
551
651
  suppressClick.current = false;
552
652
  });
553
653
  setDragged(null);
554
- commitRange(dragged);
654
+ commitRange(dragged, { event, reason: 'drag' });
555
655
  };
556
656
  const showMonth = (next) => {
557
657
  goTo(next);
558
658
  setFocused(clampDay(next, min, max));
559
659
  };
560
- const previousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
561
- const nextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
562
660
  const toggle = (roll) => {
563
661
  const next = rolled === roll ? undefined : roll;
564
662
  setRolled(next);
@@ -569,7 +667,7 @@ const CalendarPanel = (props) => {
569
667
  // A day of the grid of `shown` (the month, or the one sliding out, not
570
668
  // `interactive`): another month's is blank, or grayed out (see
571
669
  // `showAdjacentMonths`); either is marked `data-outside`, for drags.
572
- const cell = (day, shown, interactive) => {
670
+ const cell = (day, shown, isInteractive) => {
573
671
  const outsideOf = day < shown ? 'before' : 'after';
574
672
  const outside = day.getMonth() === shown.getMonth() ? undefined : outsideOf;
575
673
  if (outside && !showAdjacentMonths) {
@@ -577,21 +675,24 @@ const CalendarPanel = (props) => {
577
675
  }
578
676
  // Not the adjacent months' days (nor their weekdays, see below).
579
677
  const { attributes, dots } = highlightsOf(outside ? undefined : highlighted?.(day));
580
- return (_jsxs("button", { "aria-current": isSameDay(day, today) ? 'date' : undefined, "aria-label": interactive ? formats.full.format(day) : undefined, "data-date": interactive ? day.getTime() : undefined, ...attributes, className: "uikit-date-picker-day", "data-date-picker-part": "day", "data-outside": outside, "data-range": rangePlace(day, range), disabled: !enabled(day), tabIndex: interactive && !outside && isSameDay(day, focused) ? 0 : -1, type: "button", "aria-pressed": range ? rangePlace(day, range) !== undefined : isSameDay(day, single), "data-weekday-highlighted": (!outside && highlightedWeekdays.includes(day.getDay())) || undefined, onClick: interactive
581
- ? () => {
678
+ return (_jsxs("button", { "aria-current": isSameDay(day, today) ? 'date' : undefined, "aria-label": isInteractive ? formats.full.format(day) : undefined, "data-date": isInteractive ? day.getTime() : undefined, ...attributes, className: "uikit-date-picker-day", "data-date-picker-part": "day", "data-outside": outside, "data-range": rangePlace(day, range), disabled: !enabled(day), tabIndex: isInteractive && !outside && isSameDay(day, focused) ? 0 : -1, type: "button", "aria-pressed": range ? rangePlace(day, range) !== undefined : isSameDay(day, single), "data-weekday-highlighted": (!outside && highlightedWeekdays.includes(day.getDay())) || undefined, onClick: isInteractive
679
+ ? (event) => {
582
680
  // Another month's day: shows its month (not selected).
583
681
  if (outside) {
584
682
  showMonth(day);
585
683
  return;
586
684
  }
587
- select(day);
685
+ select(day, false, { event, reason: 'day-press' });
588
686
  }
589
687
  : undefined, children: [formats.day.format(day), dots.length > 0 ? (_jsx("span", { "data-date-picker-part": "dots", children: dots.map((dot, index) => (_jsx("span", { style: dot ? { backgroundColor: dot } : undefined }, index))) })) : null] }, day.getTime()));
590
688
  };
591
689
  const footerContent = props.footer?.(footerOf({
592
- select: (date, withTime) => {
690
+ select: (date, hasTime = false) => {
593
691
  goTo(date);
594
- select(withTime ? date : startOfDay(date), withTime);
692
+ select(hasTime ? date : startOfDay(date), hasTime, {
693
+ event: new Event('select'),
694
+ reason: 'footer',
695
+ });
595
696
  },
596
697
  show: (date) => {
597
698
  goTo(date);
@@ -606,21 +707,23 @@ const CalendarPanel = (props) => {
606
707
  },
607
708
  value: range ?? single,
608
709
  }));
609
- return (_jsxs("div", { className: "uikit-date-picker-panel", "data-date-picker-part": "calendar", children: [_jsxs("div", { className: "uikit-date-picker-header", "data-date-picker-part": "header", children: [_jsx("h2", { "aria-live": "polite", className: "uikit-date-picker-month-title", "data-date-picker-part": "month-title", id: titleId, children: _jsxs("button", { "aria-controls": rollId, "aria-expanded": rolled === 'monthYear', className: "uikit-date-picker-title-button", "data-date-picker-part": "title-button", type: "button", onClick: () => toggle('monthYear'), children: [formats.month.format(month), _jsx(Disclosure, {})] }) }), _jsxs("div", { className: "uikit-date-picker-arrows", "data-date-picker-part": "arrows", hidden: rolled === 'monthYear', children: [_jsx(Button.Root, { "aria-label": "Previous month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: previousDisabled, shape: "circle", onClick: () => showMonth(addMonths(month, -1)), children: _jsx(Chevron, { next: false }) }), _jsx(Button.Root, { "aria-label": "Next month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: nextDisabled, shape: "circle", onClick: () => showMonth(addMonths(month, 1)), children: _jsx(Chevron, { next: true }) })] })] }), _jsxs("div", { className: "uikit-date-picker-body", "data-date-picker-part": "body", "data-rolled": rolled === undefined ? undefined : '', children: [_jsx("div", { "aria-hidden": "true", className: "uikit-date-picker-weekdays", "data-date-picker-part": "weekdays", children: weekdays.map((day) => (_jsx("abbr", { title: formats.weekdayLong.format(day), "data-weekday-highlighted": highlightedWeekdays.includes(day.getDay()) || undefined, children: formats.weekday.format(day) }, day.getDay()))) }), _jsxs("div", { ref: pagesRef, className: "uikit-date-picker-pages", "data-date-picker-part": "pages", children: [leaving ? (_jsx("div", { ref: leavingRef, inert: true, "aria-hidden": "true", className: "uikit-date-picker-leaving-page", "data-date-picker-part": "leaving-page", children: _jsx("div", { className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", children: monthWeeks(leaving.month, weekStart)
610
- .flat()
611
- .map((day) => cell(day, leaving.month, false)) }) })) : null, _jsx("div", { ref: daysRef, "aria-label": label, "aria-labelledby": label ? undefined : titleId, className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", "data-range-drag": props.range ? '' : undefined, role: "group", onKeyDown: onKeyDown, onPointerCancel: onPointerEnd, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerEnd, onClickCapture: (event) => {
612
- if (!suppressClick.current)
613
- return;
614
- suppressClick.current = false;
615
- event.stopPropagation();
616
- }, onFocus: (event) => {
617
- // The day focused (e.g. pressed): keys move on from it.
618
- const day = dayOf(event.target);
619
- if (day && !isSameDay(day, focused))
620
- setFocused(day);
621
- }, children: weeks.flat().map((day) => cell(day, month, true)) })] }), rolled === undefined ? null : (_jsx("div", { className: "uikit-date-picker-overlay", "data-date-picker-part": "roll", id: rollId, children: rolled === 'monthYear' ? (_jsx(MonthYearRoll, { locale: locale, max: max, min: min, month: month, onChange: showMonth })) : (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, value: single, onValueChange: changeTime })) }))] }), footerContent === null || footerContent === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("div", { className: "uikit-date-picker-separator", "data-date-picker-part": "separator" }), footerContent] }))] }));
710
+ // A neighbour's page (see pager.ts): its days, not interactive.
711
+ const neighbour = (shown) => (_jsx("div", { inert: true, "aria-hidden": "true", className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", children: monthWeeks(shown, weekStart)
712
+ .flat()
713
+ .map((day) => cell(day, shown, false)) }, shown.getTime()));
714
+ return (_jsxs("div", { className: "uikit-date-picker-panel", "data-date-picker-part": "calendar", children: [_jsxs("div", { className: "uikit-date-picker-header", "data-date-picker-part": "header", children: [_jsx("h2", { "aria-live": "polite", className: "uikit-date-picker-month-title", "data-date-picker-part": "month-title", id: titleId, children: _jsxs("button", { "aria-controls": rollId, "aria-expanded": rolled === 'monthYear', className: "uikit-date-picker-title-button", "data-date-picker-part": "title-button", type: "button", onClick: () => toggle('monthYear'), children: [formats.month.format(pager.shown), _jsx(Disclosure, {})] }) }), _jsxs("div", { className: "uikit-date-picker-arrows", "data-date-picker-part": "arrows", hidden: rolled === 'monthYear', children: [_jsx(Button.Root, { "aria-label": "Previous month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: isPreviousDisabled, shape: "circle", onClick: () => showMonth(addMonths(pager.shown, -1)), children: _jsx(Chevron, { isNext: false }) }), _jsx(Button.Root, { "aria-label": "Next month", className: "uikit-date-picker-arrow", "data-date-picker-part": "arrow", disabled: isNextDisabled, shape: "circle", onClick: () => showMonth(addMonths(pager.shown, 1)), children: _jsx(Chevron, { isNext: true }) })] })] }), _jsxs("div", { ref: bodyRef, className: "uikit-date-picker-body", "data-date-picker-part": "body", "data-rolled": rolled === undefined ? undefined : '', children: [_jsx("div", { "aria-hidden": "true", className: "uikit-date-picker-weekdays", "data-date-picker-part": "weekdays", children: weekdays.map((day) => (_jsx("abbr", { title: formats.weekdayLong.format(day), "data-weekday-highlighted": highlightedWeekdays.includes(day.getDay()) || undefined, children: formats.weekday.format(day) }, day.getDay()))) }), _jsx("div", { ref: pagesRef, className: "uikit-date-picker-pages", "data-date-picker-part": "pages", "data-swipe": swipes, children: pager.months.map((shown) => shown.getTime() === month.getTime() ? (_jsx("div", { ref: daysRef, "aria-label": label, "aria-labelledby": label ? undefined : titleId, className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", "data-swipe": swipes, role: "group", onKeyDown: onKeyDown, onPointerCancel: onPointerEnd, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerEnd, onClickCapture: (event) => {
715
+ if (!suppressClick.current)
716
+ return;
717
+ suppressClick.current = false;
718
+ event.stopPropagation();
719
+ }, onFocus: (event) => {
720
+ // The day focused (e.g. pressed): keys move on from it.
721
+ const day = dayOf(event.target);
722
+ if (day && !isSameDay(day, focused))
723
+ setFocused(day);
724
+ }, children: weeks.flat().map((day) => cell(day, month, true)) }, shown.getTime())) : (neighbour(shown))) }), rolled === undefined ? null : (_jsx("div", { className: "uikit-date-picker-overlay", "data-date-picker-part": "roll", id: rollId, children: rolled === 'monthYear' ? (_jsx(MonthYearRoll, { locale: locale, max: max, min: min, month: month, onChange: showMonth })) : (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, max: max, min: min, value: single, onValueChange: changeTime })) }))] }), footerContent === null || footerContent === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("div", { className: "uikit-date-picker-separator", "data-date-picker-part": "separator" }), footerContent] })), _jsx(FormValue, { form: props.form, isOmitted: props.formControl === false, name: props.name, value: value })] }));
622
725
  };
623
- /** A footer row (see `CalendarProps` `footer`): Figma “Time”'s, 52px. */
726
+ /** A footer row (see `CalendarProps` `footer`): a time row's, 52px. */
624
727
  const CalendarRow = TimeRow;
625
728
  /** A footer button (see `CalendarProps` `footer`): a collapsed button. */
626
729
  const CalendarButton = CollapsedButton;
@@ -631,20 +734,23 @@ const CalendarButton = CollapsedButton;
631
734
  */
632
735
  const CalendarMessage = forwardRef(({ className, variant = 'info', ...props }, ref) => (_jsx("p", { ref: ref, "aria-live": "polite", "data-variant": variant, role: variant === 'error' ? 'alert' : undefined, ...props, className: cn('uikit-date-picker-message', className), "data-date-picker-part": "message" })));
633
736
  /**
634
- * The footer's Time row (Figma “Time”): the time's button, showing its
737
+ * The footer's time row: the time's button, showing its
635
738
  * roll; the picker's default footer, with a time.
636
739
  */
637
740
  const CalendarTimeRow = ({ calendar, label = 'Time' }) => calendar.time ? (_jsxs(CalendarRow, { children: [_jsx("span", { "aria-hidden": "true", children: label }), _jsx(CalendarButton, { "aria-controls": calendar.time.controls, "aria-expanded": calendar.time.shown, "aria-label": "Time", disabled: calendar.disabled, shape: calendar.buttonShape, onClick: calendar.time.toggle, children: calendar.time.label })] })) : null;
638
- /** The calendar (Figma “Style=Inline”, without the time). */
741
+ /** The calendar (inline, without the time). */
639
742
  const Calendar = (props) => _jsx(CalendarPanel, { ...props });
640
743
  /** The calendar's props, of the picker's (its value, and its changes). */
641
744
  const calendarPropsOf = (props, change, value) => {
642
745
  const shared = {
746
+ // (The picker renders its own.)
747
+ formControl: false,
643
748
  firstDayOfWeek: props.firstDayOfWeek,
644
749
  highlighted: props.highlighted,
645
750
  highlightedWeekdays: props.highlightedWeekdays,
646
751
  isDateDisabled: props.isDateDisabled,
647
752
  showAdjacentMonths: props.showAdjacentMonths,
753
+ swipe: props.swipe,
648
754
  hourCycle: props.hourCycle,
649
755
  locale: props.locale,
650
756
  max: props.max,
@@ -664,9 +770,9 @@ const calendarPropsOf = (props, change, value) => {
664
770
  const usePickerValue = (props) => {
665
771
  const [value, setValue] = useControlled(props.value, props.defaultValue ?? null);
666
772
  // Only changed to the kind of value it has (a date or a range).
667
- const change = (next) => {
773
+ const change = (next, details) => {
668
774
  setValue(next);
669
- props.onValueChange?.(next);
775
+ props.onValueChange?.(next, details);
670
776
  };
671
777
  return {
672
778
  change,
@@ -677,18 +783,18 @@ const usePickerValue = (props) => {
677
783
  /** The open picker of the compact style, and its changes. */
678
784
  const usePickerOpen = (props) => {
679
785
  const [open, setOpen] = useControlled(props.open, props.defaultOpen ?? null);
680
- const change = (next) => {
786
+ const change = (next, details) => {
681
787
  setOpen(next);
682
- props.onOpenChange?.(next);
788
+ props.onOpenChange?.(next, details);
683
789
  };
684
790
  return [open, change];
685
791
  };
686
792
  /** The picker's default footer, with a time. */
687
793
  const defaultFooter = (calendar) => (_jsx(CalendarTimeRow, { calendar: calendar }));
688
794
  /** The compact style's time: its button, the roll in a popover. */
689
- const TimePopover = ({ align, disabled, label, onOpenChange, open, shape, ...props }) => {
795
+ const TimePopover = ({ align, isDisabled, label, onOpenChange, isOpen, shape, ...props }) => {
690
796
  const popupRef = useRef(null);
691
- return (_jsxs(Popover.Root, { open: open, onOpenChange: onOpenChange, children: [_jsx(Popover.Trigger, { "aria-label": "Time", disabled: disabled, render: _jsx(CollapsedButton, { shape: shape }), children: label }), _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, children: _jsx(Popover.Popup, { ref: popupRef, "aria-label": "Time", className: "uikit-date-picker-popup", "data-date-picker-part": "popup",
797
+ return (_jsxs(Popover.Root, { open: isOpen, onOpenChange: onOpenChange, children: [_jsx(Popover.Trigger, { "aria-label": "Time", disabled: isDisabled, render: _jsx(CollapsedButton, { shape: shape }), children: label }), _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, children: _jsx(Popover.Popup, { ref: popupRef, "aria-label": "Time", className: "uikit-date-picker-popup", "data-date-picker-part": "popup",
692
798
  // The popup (not the first column: focused while the popup
693
799
  // opens, Chrome scrolls it off its selection).
694
800
  initialFocus: popupRef, children: _jsx("div", { className: "uikit-date-picker-time-popup", "data-date-picker-part": "time-popup", children: _jsx(TimeRoll, { ...props }) }) }) }) })] }));
@@ -704,43 +810,97 @@ const dateLabelOf = (format, range, single) => {
704
810
  };
705
811
  /**
706
812
  * The compact style's calendar popover: from the date's button, or, with a
707
- * time, from the time's too, with the time's roll shown (as iOS's; one
708
- * popover for both).
813
+ * time, from the time's too, with the time's roll shown (one popover for
814
+ * both).
709
815
  */
710
- const CalendarPopover = ({ align, children, dateLabel, disabled, onOpenChange, open, shape, timeLabel, }) => {
816
+ const CalendarPopover = ({ align, children, dateLabel, isDisabled, onOpenChange, open, shape, timeLabel, }) => {
711
817
  const dateTriggerId = useId();
712
818
  const timeTriggerId = useId();
713
819
  const collapsedRef = useRef(null);
714
820
  const hasTime = timeLabel !== undefined;
715
821
  // The time's button is the open one while the time's roll shows (however
716
822
  // it was opened, or shown), the date's otherwise.
717
- const [timeShown, setTimeShown] = useState(open === 'time');
823
+ const [isTimeShown, setIsTimeShown] = useState(open === 'time');
718
824
  const [openBefore, setOpenBefore] = useState(open);
719
825
  if (open !== openBefore) {
720
826
  setOpenBefore(open);
721
- setTimeShown(open === 'time');
827
+ setIsTimeShown(open === 'time');
722
828
  }
723
829
  // Positioned at both buttons together, whichever opened it.
724
- return (_jsx("div", { ref: collapsedRef, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: _jsxs(Popover.Root, { open: open === 'date' || (hasTime && open === 'time'), triggerId: hasTime && timeShown ? timeTriggerId : dateTriggerId, onOpenChange: (next, { event }) => {
830
+ return (_jsx("div", { ref: collapsedRef, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: _jsxs(Popover.Root, { open: open === 'date' || (hasTime && open === 'time'), triggerId: hasTime && isTimeShown ? timeTriggerId : dateTriggerId, onOpenChange: (isOpen, { event, reason }) => {
725
831
  const trigger = event.target instanceof Element
726
832
  ? event.target.closest('[data-date-picker-trigger]')
727
833
  : null;
728
834
  const picker = trigger?.dataset.datePickerTrigger === 'time' ? 'time' : 'date';
729
- onOpenChange(next ? picker : null);
730
- }, children: [_jsx(Popover.Trigger, { "data-date-picker-trigger": "date", disabled: disabled, id: dateTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: dateLabel }), hasTime ? (_jsx(Popover.Trigger, { "aria-label": "Time", "data-date-picker-trigger": "time", disabled: disabled, id: timeTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: timeLabel })) : null, _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, anchor: collapsedRef, children: _jsx(Popover.Popup, { "aria-label": hasTime ? 'Date and time' : 'Date', className: "uikit-date-picker-popup", "data-date-picker-part": "popup", children: _jsx(Fragment, { children: children(open === 'time' ? 'time' : undefined, setTimeShown) }, open ?? 'closed') }) }) })] }) }));
835
+ onOpenChange(isOpen ? picker : null, { event, reason });
836
+ }, children: [_jsx(Popover.Trigger, { "data-date-picker-trigger": "date", disabled: isDisabled, id: dateTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: dateLabel }), hasTime ? (_jsx(Popover.Trigger, { "aria-label": "Time", "data-date-picker-trigger": "time", disabled: isDisabled, id: timeTriggerId, render: _jsx(CollapsedButton, { shape: shape }), children: timeLabel })) : null, _jsx(Popover.Portal, { children: _jsx(Popover.Positioner, { align: align, anchor: collapsedRef, children: _jsx(Popover.Popup, { "aria-label": hasTime ? 'Date and time' : 'Date', className: "uikit-date-picker-popup", "data-date-picker-part": "popup", children: _jsx(Fragment, { children: children(open === 'time' ? 'time' : undefined, setIsTimeShown) }, open ?? 'closed') }) }) })] }) }));
731
837
  };
732
838
  /** The compact style's buttons, toggling `open` (without popovers). */
733
- const ToggleButtons = ({ dateLabel, disabled, onOpenChange, open, shape, timeLabel }) => {
734
- const toggle = (picker) => onOpenChange(open === picker ? null : picker);
735
- return (_jsxs("div", { className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: [dateLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'date', disabled: disabled, shape: shape, onClick: () => toggle('date'), children: dateLabel })), timeLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'time', "aria-label": "Time", disabled: disabled, shape: shape, onClick: () => toggle('time'), children: timeLabel }))] }));
839
+ const ToggleButtons = ({ dateLabel, isDisabled, onOpenChange, open, shape, timeLabel }) => {
840
+ const toggle = (picker, event) => onOpenChange(open === picker ? null : picker, {
841
+ event,
842
+ reason: 'trigger-press',
843
+ });
844
+ // Disabled while open (`isDisabled`, or from around it: e.g. a disabled
845
+ // fieldset's): closed (with a handle, its rows).
846
+ const ref = useRef(null);
847
+ useLayoutEffect(() => {
848
+ if (open === null)
849
+ return;
850
+ const button = ref.current?.querySelector('button');
851
+ if (!isDisabled && !button?.matches(':disabled'))
852
+ return;
853
+ onOpenChange(null, { event: new Event('disable'), reason: 'none' });
854
+ });
855
+ return (_jsxs("div", { ref: ref, className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: [dateLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'date', disabled: isDisabled, shape: shape, onClick: (event) => toggle('date', event), children: dateLabel })), timeLabel === undefined ? null : (_jsx(CollapsedButton, { "aria-expanded": open === 'time', "aria-label": "Time", disabled: isDisabled, shape: shape, onClick: (event) => toggle('time', event), children: timeLabel }))] }));
856
+ };
857
+ /**
858
+ * A picker in collapsible list rows (see `List.CollapsiblePanel`): closed
859
+ * with them. With a handle, in a collapsible (e.g. a `List.AccordionItem`,
860
+ * with its row and `Expandable`): open with it, opening it, closed with it
861
+ * (e.g. another item opening).
862
+ */
863
+ const useListSync = (handle, open, changeOpen) => {
864
+ const isShown = useExpandedOpen();
865
+ const collapsible = useCollapsible();
866
+ const item = handle ? collapsible : undefined;
867
+ const isPickerOpen = open !== null;
868
+ const syncRef = useRef({
869
+ close: () => undefined,
870
+ toggleItem: () => undefined,
871
+ });
872
+ useLayoutEffect(() => {
873
+ syncRef.current = {
874
+ close: () => {
875
+ if (open === null)
876
+ return;
877
+ changeOpen(null, { event: new Event('close'), reason: 'none' });
878
+ },
879
+ toggleItem: () => {
880
+ if (!item || item.isOpen === isPickerOpen)
881
+ return;
882
+ item.setOpen(isPickerOpen, {
883
+ event: new Event('toggle'),
884
+ reason: 'none',
885
+ });
886
+ },
887
+ };
888
+ });
889
+ useEffect(() => {
890
+ if (isShown === false || item?.isOpen === false)
891
+ syncRef.current.close();
892
+ }, [isShown, item?.isOpen]);
893
+ useEffect(() => {
894
+ syncRef.current.toggleItem();
895
+ }, [isPickerOpen]);
736
896
  };
737
897
  /**
738
- * A date picker (UIKit `UIDatePicker`): a date, a time or both (`mode`), or
898
+ * A date picker: a date, a time or both (`mode`), or
739
899
  * a range of dates (`range`); collapsed buttons opening the calendar or the
740
900
  * time in a popover (or toggling `open`, without `popover`), or the
741
901
  * calendar in place (`pickerStyle`).
742
902
  */
743
- const DatePicker = (props) => {
903
+ const Root = (props) => {
744
904
  const { buttonShape, disabled = false, hourCycle, locale, mode = 'date', pickerStyle = 'compact', popover = true, } = props;
745
905
  const { change, range, single } = usePickerValue(props);
746
906
  const [open, changeOpen] = usePickerOpen(props);
@@ -751,20 +911,55 @@ const DatePicker = (props) => {
751
911
  const hasDate = props.range || mode !== 'time';
752
912
  const hasTime = !props.range && mode !== 'date';
753
913
  const calendarProps = calendarPropsOf(props, change, range ?? single);
914
+ useListSync(props.handle, open, changeOpen);
915
+ // With a handle: its pickers, for its `Expandable`.
916
+ const { handle } = props;
917
+ useLayoutEffect(() => {
918
+ handle?.publish({
919
+ calendar: hasDate ? _jsx(CalendarPanel, { ...calendarProps }) : undefined,
920
+ open,
921
+ time: hasTime ? (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, max: props.max, min: props.min, value: single, onValueChange: change })) : undefined,
922
+ });
923
+ });
924
+ useLayoutEffect(() => () => handle?.publish(undefined), [handle]);
754
925
  // With a time, by default the Time row below.
755
926
  const calendar = (initialRoll, onTimeShownChange) => (_jsx(CalendarPanel, { ...calendarProps, footer: props.footer ?? (hasTime ? defaultFooter : undefined), initialRoll: initialRoll, time: hasTime ? { disabled, shape: buttonShape } : undefined, onTimeShownChange: onTimeShownChange }));
756
- if (pickerStyle === 'inline' && hasDate)
757
- return calendar();
927
+ // Its value's hidden control (see `name`), beside what it shows.
928
+ const formValue = (_jsx(FormValue, { form: props.form, mode: props.range ? 'date' : mode, name: props.name, value: range ?? single }));
929
+ if (pickerStyle === 'inline' && hasDate) {
930
+ return (_jsxs(_Fragment, { children: [calendar(), formValue] }));
931
+ }
758
932
  const dateLabel = dateLabelOf(formats.date, range, single);
759
933
  const timeLabel = single ? formats.time.format(single) : '–';
760
- // Without popovers: buttons toggling `open` (for the app to show them).
761
- if (!popover) {
762
- return (_jsx(ToggleButtons, { dateLabel: hasDate ? dateLabel : undefined, disabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen }));
934
+ // Without popovers: buttons toggling `open` (for the app to show them,
935
+ // or, with a handle, its `Expandable`).
936
+ if (!popover || props.handle) {
937
+ return (_jsxs(_Fragment, { children: [_jsx(ToggleButtons, { dateLabel: hasDate ? dateLabel : undefined, isDisabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen }), formValue] }));
763
938
  }
764
939
  if (!hasDate) {
765
- return (_jsx("div", { className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: _jsx(TimePopover, { align: props.popoverAlign, disabled: disabled, hourCycle: hourCycle, label: timeLabel, locale: locale, open: open === 'time', shape: buttonShape, value: single, onOpenChange: (next) => changeOpen(next ? 'time' : null), onValueChange: change }) }));
940
+ return (_jsxs("div", { className: "uikit-date-picker-collapsed", "data-date-picker-part": "collapsed", children: [formValue, _jsx(TimePopover, { align: props.popoverAlign, hourCycle: hourCycle, isDisabled: disabled, isOpen: open === 'time', label: timeLabel, locale: locale, max: props.max, min: props.min, shape: buttonShape, value: single, onValueChange: change, onOpenChange: (isOpen, { event, reason }) => changeOpen(isOpen ? 'time' : null, { event, reason }) })] }));
766
941
  }
767
- return (_jsx(CalendarPopover, { align: props.popoverAlign, dateLabel: dateLabel, disabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen, children: (initialRoll, onTimeShownChange) => calendar(initialRoll, onTimeShownChange) }));
942
+ return (_jsxs(_Fragment, { children: [_jsx(CalendarPopover, { align: props.popoverAlign, dateLabel: dateLabel, isDisabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen, children: (initialRoll, onTimeShownChange) => calendar(initialRoll, onTimeShownChange) }), formValue] }));
943
+ };
944
+ /**
945
+ * A date picker's pickers in place (see `Root` `handle`): its calendar and
946
+ * time roll, each in collapsible list rows (`List.CollapsiblePanel`),
947
+ * opened by its buttons; placed after the picker's row. In an `List.AccordionItem` (with its row), one of its items.
948
+ */
949
+ const Expandable = ({ handle, }) => {
950
+ const { calendar, open, time } = useSyncExternalStore(handle.subscribe, handle.getSnapshot);
951
+ return (_jsxs(_Fragment, { children: [calendar === undefined ? null : (_jsx(List.CollapsibleRoot, { open: open === 'date', children: _jsx(List.CollapsiblePanel, { children: _jsx(List.Item, { children: _jsx(List.Span, { children: calendar }) }) }) })), time === undefined ? null : (_jsx(List.CollapsibleRoot, { open: open === 'time', children: _jsx(List.CollapsiblePanel, { children: _jsx(List.Item, { children: _jsx(List.Span, { children: time }) }) }) }))] }));
952
+ };
953
+ export { DatePickerHandle, useCreateDatePickerHandle } from './handle.js';
954
+ export const DatePicker = {
955
+ Root,
956
+ Expandable,
957
+ createHandle,
958
+ Calendar,
959
+ CalendarRow,
960
+ CalendarButton,
961
+ CalendarTimeRow,
962
+ CalendarMessage,
963
+ TimeRoll,
768
964
  };
769
- export { Calendar, CalendarButton, CalendarMessage, CalendarRow, CalendarTimeRow, DatePicker, TimeRoll, };
770
965
  //# sourceMappingURL=main.js.map