@mrpelz/uikit-ish 7.8.0 → 7.9.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 (272) 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 -15
  7. package/dist/components/action-sheet/main.d.ts.map +1 -1
  8. package/dist/components/action-sheet/main.js +86 -16
  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 +15 -0
  13. package/dist/components/activity-view/main.d.ts +14 -3
  14. package/dist/components/activity-view/main.d.ts.map +1 -1
  15. package/dist/components/activity-view/main.js +19 -4
  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 +8 -46
  20. package/dist/components/alert/main.d.ts +6 -4
  21. package/dist/components/alert/main.d.ts.map +1 -1
  22. package/dist/components/alert/main.js +20 -4
  23. package/dist/components/alert/main.js.map +1 -1
  24. package/dist/components/alert/props.d.ts +12 -1
  25. package/dist/components/alert/props.d.ts.map +1 -1
  26. package/dist/components/alert/style.css +13 -27
  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 +3 -0
  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 +0 -6
  34. package/dist/components/badge/main.d.ts +2 -2
  35. package/dist/components/badge/main.d.ts.map +1 -1
  36. package/dist/components/badge/main.js +5 -5
  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 +3 -2
  41. package/dist/components/button/main.d.ts.map +1 -1
  42. package/dist/components/button/main.js +6 -6
  43. package/dist/components/button/main.js.map +1 -1
  44. package/dist/components/button/style.css +11 -27
  45. package/dist/components/checkbox/style.css +2 -5
  46. package/dist/components/collapsible/main.d.ts +9 -0
  47. package/dist/components/collapsible/main.d.ts.map +1 -0
  48. package/dist/components/collapsible/main.js +19 -0
  49. package/dist/components/collapsible/main.js.map +1 -0
  50. package/dist/components/collapsible/style.css +23 -0
  51. package/dist/components/color-picker/main.d.ts +1 -1
  52. package/dist/components/color-picker/main.d.ts.map +1 -1
  53. package/dist/components/color-picker/main.js +40 -33
  54. package/dist/components/color-picker/main.js.map +1 -1
  55. package/dist/components/color-picker/props.d.ts +21 -7
  56. package/dist/components/color-picker/props.d.ts.map +1 -1
  57. package/dist/components/color-picker/style.css +9 -27
  58. package/dist/components/contextual-menu/main.d.ts +11 -7
  59. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  60. package/dist/components/contextual-menu/main.js +99 -47
  61. package/dist/components/contextual-menu/main.js.map +1 -1
  62. package/dist/components/contextual-menu/props.d.ts +17 -7
  63. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  64. package/dist/components/contextual-menu/style.css +11 -8
  65. package/dist/components/date-picker/handle.d.ts +41 -0
  66. package/dist/components/date-picker/handle.d.ts.map +1 -0
  67. package/dist/components/date-picker/handle.js +47 -0
  68. package/dist/components/date-picker/handle.js.map +1 -0
  69. package/dist/components/date-picker/main.d.ts +31 -49
  70. package/dist/components/date-picker/main.d.ts.map +1 -1
  71. package/dist/components/date-picker/main.js +300 -139
  72. package/dist/components/date-picker/main.js.map +1 -1
  73. package/dist/components/date-picker/pager.d.ts +24 -0
  74. package/dist/components/date-picker/pager.d.ts.map +1 -0
  75. package/dist/components/date-picker/pager.js +307 -0
  76. package/dist/components/date-picker/pager.js.map +1 -0
  77. package/dist/components/date-picker/props.d.ts +93 -22
  78. package/dist/components/date-picker/props.d.ts.map +1 -1
  79. package/dist/components/date-picker/style.css +59 -71
  80. package/dist/components/drawer/main.d.ts +31 -0
  81. package/dist/components/drawer/main.d.ts.map +1 -0
  82. package/dist/components/drawer/main.js +74 -0
  83. package/dist/components/drawer/main.js.map +1 -0
  84. package/dist/components/drawer/props.d.ts +39 -0
  85. package/dist/components/drawer/props.d.ts.map +1 -0
  86. package/dist/components/drawer/props.js +2 -0
  87. package/dist/components/drawer/props.js.map +1 -0
  88. package/dist/components/drawer/style.css +135 -0
  89. package/dist/components/edit-menu/main.d.ts +7 -7
  90. package/dist/components/edit-menu/main.d.ts.map +1 -1
  91. package/dist/components/edit-menu/main.js +31 -23
  92. package/dist/components/edit-menu/main.js.map +1 -1
  93. package/dist/components/edit-menu/props.d.ts +13 -0
  94. package/dist/components/edit-menu/props.d.ts.map +1 -1
  95. package/dist/components/edit-menu/style.css +5 -7
  96. package/dist/components/form/main.d.ts +8 -0
  97. package/dist/components/form/main.d.ts.map +1 -1
  98. package/dist/components/form/main.js +15 -2
  99. package/dist/components/form/main.js.map +1 -1
  100. package/dist/components/form/props.d.ts +1 -2
  101. package/dist/components/form/props.d.ts.map +1 -1
  102. package/dist/components/glass/style.css +19 -4
  103. package/dist/components/header/main.d.ts +5 -4
  104. package/dist/components/header/main.d.ts.map +1 -1
  105. package/dist/components/header/main.js +56 -27
  106. package/dist/components/header/main.js.map +1 -1
  107. package/dist/components/header/props.d.ts +2 -3
  108. package/dist/components/header/props.d.ts.map +1 -1
  109. package/dist/components/header/style.css +62 -42
  110. package/dist/components/index.d.ts +26 -22
  111. package/dist/components/index.d.ts.map +1 -1
  112. package/dist/components/index.js +17 -13
  113. package/dist/components/index.js.map +1 -1
  114. package/dist/components/layout/main.d.ts +2 -2
  115. package/dist/components/layout/main.d.ts.map +1 -1
  116. package/dist/components/layout/main.js +59 -163
  117. package/dist/components/layout/main.js.map +1 -1
  118. package/dist/components/layout/props.d.ts +2 -20
  119. package/dist/components/layout/props.d.ts.map +1 -1
  120. package/dist/components/layout/style.css +18 -89
  121. package/dist/components/list/main.d.ts +49 -9
  122. package/dist/components/list/main.d.ts.map +1 -1
  123. package/dist/components/list/main.js +769 -208
  124. package/dist/components/list/main.js.map +1 -1
  125. package/dist/components/list/props.d.ts +165 -8
  126. package/dist/components/list/props.d.ts.map +1 -1
  127. package/dist/components/list/style.css +308 -371
  128. package/dist/components/list/swipe-actions-handle.d.ts +40 -0
  129. package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
  130. package/dist/components/list/swipe-actions-handle.js +51 -0
  131. package/dist/components/list/swipe-actions-handle.js.map +1 -0
  132. package/dist/components/menu/main.d.ts +31 -8
  133. package/dist/components/menu/main.d.ts.map +1 -1
  134. package/dist/components/menu/main.js +175 -39
  135. package/dist/components/menu/main.js.map +1 -1
  136. package/dist/components/menu/props.d.ts +2 -1
  137. package/dist/components/menu/props.d.ts.map +1 -1
  138. package/dist/components/menu/style.css +10 -32
  139. package/dist/components/navigation/main.d.ts +11 -2
  140. package/dist/components/navigation/main.d.ts.map +1 -1
  141. package/dist/components/navigation/main.js +186 -98
  142. package/dist/components/navigation/main.js.map +1 -1
  143. package/dist/components/navigation/props.d.ts +20 -3
  144. package/dist/components/navigation/props.d.ts.map +1 -1
  145. package/dist/components/navigation/style.css +24 -7
  146. package/dist/components/page/main.d.ts.map +1 -1
  147. package/dist/components/page/main.js +2 -2
  148. package/dist/components/page/main.js.map +1 -1
  149. package/dist/components/page/props.d.ts +8 -0
  150. package/dist/components/page/props.d.ts.map +1 -1
  151. package/dist/components/page/style.css +39 -1
  152. package/dist/components/page-control/main.d.ts +1 -1
  153. package/dist/components/page-control/main.d.ts.map +1 -1
  154. package/dist/components/page-control/main.js +59 -25
  155. package/dist/components/page-control/main.js.map +1 -1
  156. package/dist/components/page-control/props.d.ts +10 -2
  157. package/dist/components/page-control/props.d.ts.map +1 -1
  158. package/dist/components/page-control/style.css +5 -0
  159. package/dist/components/popover/main.d.ts +11 -6
  160. package/dist/components/popover/main.d.ts.map +1 -1
  161. package/dist/components/popover/main.js +53 -31
  162. package/dist/components/popover/main.js.map +1 -1
  163. package/dist/components/popover/props.d.ts +7 -6
  164. package/dist/components/popover/props.d.ts.map +1 -1
  165. package/dist/components/popover/style.css +45 -4
  166. package/dist/components/progress/main.d.ts +1 -1
  167. package/dist/components/progress/main.d.ts.map +1 -1
  168. package/dist/components/progress/main.js +108 -15
  169. package/dist/components/progress/main.js.map +1 -1
  170. package/dist/components/progress/props.d.ts +25 -5
  171. package/dist/components/progress/props.d.ts.map +1 -1
  172. package/dist/components/progress/style.css +67 -35
  173. package/dist/components/roll/main.d.ts +1 -1
  174. package/dist/components/roll/main.d.ts.map +1 -1
  175. package/dist/components/roll/main.js +81 -25
  176. package/dist/components/roll/main.js.map +1 -1
  177. package/dist/components/roll/props.d.ts +24 -7
  178. package/dist/components/roll/props.d.ts.map +1 -1
  179. package/dist/components/roll/style.css +1 -13
  180. package/dist/components/segmented/main.js +3 -3
  181. package/dist/components/segmented/main.js.map +1 -1
  182. package/dist/components/segmented/style.css +2 -14
  183. package/dist/components/sheet/main.d.ts +25 -15
  184. package/dist/components/sheet/main.d.ts.map +1 -1
  185. package/dist/components/sheet/main.js +57 -73
  186. package/dist/components/sheet/main.js.map +1 -1
  187. package/dist/components/sheet/props.d.ts +36 -2
  188. package/dist/components/sheet/props.d.ts.map +1 -1
  189. package/dist/components/sheet/style.css +176 -44
  190. package/dist/components/sidebar/style.css +13 -7
  191. package/dist/components/slider/main.d.ts.map +1 -1
  192. package/dist/components/slider/main.js +6 -5
  193. package/dist/components/slider/main.js.map +1 -1
  194. package/dist/components/slider/style.css +2 -28
  195. package/dist/components/stepper/main.d.ts +4 -6
  196. package/dist/components/stepper/main.d.ts.map +1 -1
  197. package/dist/components/stepper/main.js +17 -11
  198. package/dist/components/stepper/main.js.map +1 -1
  199. package/dist/components/stepper/style.css +4 -8
  200. package/dist/components/switch/main.d.ts.map +1 -1
  201. package/dist/components/switch/main.js +16 -11
  202. package/dist/components/switch/main.js.map +1 -1
  203. package/dist/components/switch/props.d.ts +2 -2
  204. package/dist/components/switch/props.d.ts.map +1 -1
  205. package/dist/components/switch/style.css +28 -1
  206. package/dist/components/symbol/main.d.ts +2 -2
  207. package/dist/components/symbol/main.d.ts.map +1 -1
  208. package/dist/components/symbol/main.js +34 -27
  209. package/dist/components/symbol/main.js.map +1 -1
  210. package/dist/components/symbol/props.d.ts +39 -4
  211. package/dist/components/symbol/props.d.ts.map +1 -1
  212. package/dist/components/symbol/style.css +25 -4
  213. package/dist/components/tab-bar/main.d.ts.map +1 -1
  214. package/dist/components/tab-bar/main.js +59 -46
  215. package/dist/components/tab-bar/main.js.map +1 -1
  216. package/dist/components/tab-bar/props.d.ts +3 -3
  217. package/dist/components/tab-bar/props.d.ts.map +1 -1
  218. package/dist/components/tab-bar/style.css +24 -46
  219. package/dist/components/text-field/main.d.ts.map +1 -1
  220. package/dist/components/text-field/main.js +9 -8
  221. package/dist/components/text-field/main.js.map +1 -1
  222. package/dist/components/text-field/props.d.ts +8 -1
  223. package/dist/components/text-field/props.d.ts.map +1 -1
  224. package/dist/components/text-field/style.css +21 -55
  225. package/dist/components/toolbar/main.d.ts.map +1 -1
  226. package/dist/components/toolbar/main.js +11 -9
  227. package/dist/components/toolbar/main.js.map +1 -1
  228. package/dist/components/toolbar/style.css +28 -22
  229. package/dist/components/tooltip/main.d.ts +10 -9
  230. package/dist/components/tooltip/main.d.ts.map +1 -1
  231. package/dist/components/tooltip/main.js +35 -6
  232. package/dist/components/tooltip/main.js.map +1 -1
  233. package/dist/components/tooltip/props.d.ts +2 -0
  234. package/dist/components/tooltip/props.d.ts.map +1 -1
  235. package/dist/components/tooltip/style.css +11 -11
  236. package/dist/components/typography/main.d.ts.map +1 -1
  237. package/dist/components/typography/main.js +16 -6
  238. package/dist/components/typography/main.js.map +1 -1
  239. package/dist/components/typography/props.d.ts +2 -9
  240. package/dist/components/typography/props.d.ts.map +1 -1
  241. package/dist/components/typography/style.css +0 -120
  242. package/dist/components/utils/main.d.ts +34 -5
  243. package/dist/components/utils/main.d.ts.map +1 -1
  244. package/dist/components/utils/main.js +81 -12
  245. package/dist/components/utils/main.js.map +1 -1
  246. package/dist/components/utils/props.d.ts +4 -2
  247. package/dist/components/utils/props.d.ts.map +1 -1
  248. package/dist/components/utils/style.css +29 -16
  249. package/dist/components/viewport/input.d.ts +23 -0
  250. package/dist/components/viewport/input.d.ts.map +1 -0
  251. package/dist/components/viewport/input.js +95 -0
  252. package/dist/components/viewport/input.js.map +1 -0
  253. package/dist/components/viewport/main.d.ts +42 -9
  254. package/dist/components/viewport/main.d.ts.map +1 -1
  255. package/dist/components/viewport/main.js +488 -66
  256. package/dist/components/viewport/main.js.map +1 -1
  257. package/dist/components/viewport/padding.d.ts +50 -0
  258. package/dist/components/viewport/padding.d.ts.map +1 -0
  259. package/dist/components/viewport/padding.js +226 -0
  260. package/dist/components/viewport/padding.js.map +1 -0
  261. package/dist/components/viewport/props.d.ts +155 -7
  262. package/dist/components/viewport/props.d.ts.map +1 -1
  263. package/dist/components/viewport/style.css +172 -6
  264. package/dist/main.d.ts +0 -1
  265. package/dist/main.d.ts.map +1 -1
  266. package/dist/main.js.map +1 -1
  267. package/dist/styles.css +35 -2
  268. package/dist/styles.d.ts +2 -1
  269. package/dist/styles.d.ts.map +1 -1
  270. package/dist/styles.js +2 -1
  271. package/dist/styles.js.map +1 -1
  272. package/package.json +6 -13
@@ -5,11 +5,15 @@ 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';
15
+ import { createHandle } from './handle.js';
16
+ import { useMonthPager } from './pager.js';
13
17
  // Source: Apple iOS 26 Figma (“Date and time - Collapsed”: State=Default/
14
18
  // Selected; “Date and time - Pickers”: Style=Inline/Compact; light and dark
15
19
  // appearance), with Figma colors mapped to UIKit semantic colors: the
@@ -42,6 +46,12 @@ import { cn } from '../utils/main.js';
42
46
  // from the sides.
43
47
  // - The collapsed buttons are capsules (or, `buttonShape`, Figma's 6px
44
48
  // corners).
49
+ // What swiping the days does (see `swipe`): a range dragged only picking
50
+ // one.
51
+ const swipeOf = (swipe, isRange) => {
52
+ const value = swipe ?? (isRange ? 'date-range' : 'month');
53
+ return value === 'date-range' && !isRange ? 'ignore' : value;
54
+ };
45
55
  // Dates (local time).
46
56
  const startOfDay = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
47
57
  const startOfMonth = (date) => new Date(date.getFullYear(), date.getMonth(), 1);
@@ -135,7 +145,7 @@ const useControlled = (value, defaultValue) => {
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
146
  // Figma “Time”: 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,32 @@ 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, as
201
+ // UIKit's).
202
+ const set = (hour, minute, { event }) => {
203
+ let next = at(hour, minute);
204
+ if (min !== undefined && next < min)
205
+ next = new Date(min);
206
+ if (max !== undefined && next > max)
207
+ next = new Date(max);
208
+ onChange(next, { event, reason: 'time' });
185
209
  };
186
- const period = (_jsxs(Roll.Column, { "aria-label": "AM/PM", value: pm ? 'pm' : 'am', onValueChange: (next) => {
187
- if ((next === 'pm') === pm)
210
+ // A shown hour's (of the shown period, with 12 hours), as 0–23.
211
+ const hourOf = (hour) => twelve ? (hour % 12) + (isPm ? 12 : 0) : hour;
212
+ const period = (_jsxs(Roll.Column, { "aria-label": "AM/PM", value: isPm ? 'pm' : 'am', onValueChange: (next, details) => {
213
+ if ((next === 'pm') === isPm)
188
214
  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] }));
215
+ set((hours + 12) % 24, date.getMinutes(), details);
216
+ }, 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] })] }));
217
+ return (_jsxs(Roll.Root, { children: [twelve && periodFirst ? period : null, _jsx(Roll.Column, { editable: true, align: "end", "aria-label": "Hours", value: shownHour, onValueChange: (next, details) => {
218
+ set(hourOf(Number(next)), date.getMinutes(), details);
219
+ }, 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
220
  };
196
221
  const clampMonth = (month, min, max) => {
197
222
  if (min && month < startOfMonth(min))
@@ -238,14 +263,16 @@ const useCalendarValue = (props) => {
238
263
  setDraggedFrom,
239
264
  setValue,
240
265
  single,
266
+ // (Either.)
267
+ value: range ?? single,
241
268
  };
242
269
  };
243
270
  /** The footer's state and actions (see `CalendarFooter`). */
244
271
  const footerOf = ({ time, ...footer }) => {
245
272
  if (!time)
246
273
  return { ...footer, disabled: false };
247
- const { disabled, shape, ...rest } = time;
248
- return { ...footer, buttonShape: shape, disabled, time: rest };
274
+ const { disabled: isDisabled, shape, ...rest } = time;
275
+ return { ...footer, buttonShape: shape, disabled: isDisabled, time: rest };
249
276
  };
250
277
  /** A day's button's date (see `CalendarPanel`). */
251
278
  const dayOf = (target) => {
@@ -281,17 +308,39 @@ const rangeReach = (fixed, selectable, hasDisabledDays, isRangeDisabled) => {
281
308
  };
282
309
  /** A range from two days, in either order. */
283
310
  const between = (a, b) => a <= b ? { end: b, start: a } : { end: a, start: b };
311
+ const twoDigits = (value) => String(value).padStart(2, '0');
312
+ const isoDate = (date) => `${String(date.getFullYear())}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())}`;
313
+ const isoTime = (date) => `${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}`;
314
+ /**
315
+ * A value as a form submits it (an input's formats; a range's interval, or
316
+ * nothing until its end is picked).
317
+ */
318
+ const formValueOf = (value, mode = 'date') => {
319
+ if (!value)
320
+ return '';
321
+ if (!(value instanceof Date)) {
322
+ return value.end ? `${isoDate(value.start)}/${isoDate(value.end)}` : '';
323
+ }
324
+ if (mode === 'time')
325
+ return isoTime(value);
326
+ if (mode === 'dateAndTime')
327
+ return `${isoDate(value)}T${isoTime(value)}`;
328
+ return isoDate(value);
329
+ };
330
+ /**
331
+ * Its value's hidden control (Base UI's field control): submitted by its
332
+ * `name`, or, in a Base UI `Field`, as the field's.
333
+ */
334
+ const FormValue = ({ form, mode, name, isOmitted = false, value }) => isOmitted ? null : (_jsx(BaseField.Control, { form: form, name: name, type: "hidden", value: formValueOf(value, mode) }));
284
335
  /** The calendar (Figma “Style=Inline”), with an optional time row. */
285
336
  const CalendarPanel = (props) => {
286
337
  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);
338
+ const { dragged, draggedFrom, range, setDragged, setDraggedFrom, setValue, single, value, } = useCalendarValue(props);
288
339
  const today = startOfDay(new Date());
289
340
  const [month, setMonth] = useState(() => startOfMonth(range?.start ?? single ?? today));
290
341
  const [focused, setFocused] = useState(() => clampDay(startOfDay(range?.start ?? single ?? today), min, max));
291
342
  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);
343
+ const swipes = swipeOf(props.swipe, Boolean(props.range));
295
344
  const pagesRef = useRef(null);
296
345
  const daysRef = useRef(null);
297
346
  const focusNext = useRef(undefined);
@@ -340,60 +389,68 @@ const CalendarPanel = (props) => {
340
389
  focusNext.current = undefined;
341
390
  day.focus();
342
391
  });
343
- // Months of more or fewer weeks: the days' height transitions.
392
+ // The strip as high as the shown month's days (its neighbours' clipped),
393
+ // as they're laid out (not while hidden, e.g. in a closed row: none).
344
394
  useLayoutEffect(() => {
345
395
  const { current: days } = daysRef;
346
- if (!days)
396
+ const { current: pages } = pagesRef;
397
+ if (!days || !pages)
398
+ return undefined;
399
+ const fit = () => {
400
+ if (days.offsetHeight === 0)
401
+ return;
402
+ height.current = days.offsetHeight;
403
+ pages.style.height = `${String(days.offsetHeight)}px`;
404
+ };
405
+ fit();
406
+ const observer = new ResizeObserver(fit);
407
+ observer.observe(days);
408
+ return () => observer.disconnect();
409
+ }, [month]);
410
+ // The months side by side, scrolled sideways (see pager.ts): turned to,
411
+ // by scrolling, its day focused.
412
+ const isPreviousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
413
+ const isNextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
414
+ const pager = useMonthPager({
415
+ // A month's neighbour, not beyond the limits (as the arrows').
416
+ beside: (shown, step) => {
417
+ const at = startOfMonth(addMonths(shown, step));
418
+ const last = addDays(startOfMonth(addMonths(at, 1)), -1);
419
+ if (min && last < startOfDay(min))
420
+ return undefined;
421
+ if (max && at > startOfDay(max))
422
+ return undefined;
423
+ return at;
424
+ },
425
+ isDraggable: swipes === 'month',
426
+ isInstant: rolled !== undefined,
427
+ month,
428
+ onTurn: (next, isScrolled) => {
429
+ setMonth(next);
430
+ if (isScrolled)
431
+ setFocused(clampDay(next, min, max));
432
+ },
433
+ pagesRef,
434
+ });
435
+ const { goTo } = pager;
436
+ // Months of more or fewer weeks: once settled on one (not while
437
+ // scrolled: a native touch drag would falter), the strip's height
438
+ // transitioning (between heights laid out).
439
+ useLayoutEffect(() => {
440
+ const { current: days } = daysRef;
441
+ const { current: pages } = pagesRef;
442
+ if (!days || !pages)
347
443
  return;
348
444
  const next = days.offsetHeight;
349
445
  const previous = height.current;
446
+ if (next === 0)
447
+ return;
350
448
  height.current = next;
449
+ pages.style.height = `${String(next)}px`;
351
450
  if (previous === undefined || previous === next)
352
451
  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'));
452
+ pages.animate([{ height: `${String(previous)}px` }, { height: `${String(next)}px` }], { duration: 300, easing: 'ease' });
359
453
  }, [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
- };
370
- useLayoutEffect(() => {
371
- const { current: days } = daysRef;
372
- const { current: pages } = pagesRef;
373
- const { current: page } = leavingRef;
374
- if (!leaving || !days || !pages || !page)
375
- 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);
391
- return () => {
392
- for (const animation of animations)
393
- animation.cancel();
394
- pages.style.removeProperty('overflow');
395
- };
396
- }, [leaving]);
397
454
  // Moved by keyboard: on past disabled days (in the direction moved), to
398
455
  // one that can be focused.
399
456
  const moveTo = (date) => {
@@ -411,42 +468,42 @@ const CalendarPanel = (props) => {
411
468
  goTo(target);
412
469
  focusNext.current = target;
413
470
  };
414
- const changeTime = (date) => {
471
+ const changeTime = (date, details) => {
415
472
  setValue(date);
416
473
  if (!props.range)
417
- props.onValueChange?.(date);
474
+ props.onValueChange?.(date, details);
418
475
  };
419
- const commitRange = (next) => {
476
+ const commitRange = (next, details) => {
420
477
  if (!props.range)
421
478
  return;
422
479
  setValue(next);
423
- props.onValueChange?.(next);
480
+ props.onValueChange?.(next, details);
424
481
  };
425
- const select = (date, withTime = false) => {
482
+ const select = (date, hasTime, details) => {
426
483
  setFocused(startOfDay(date));
427
484
  if (props.range) {
428
485
  // A new range, or its end (before its start: the other way round; out
429
486
  // of the start's reach, a new range).
430
487
  commitRange(!range || range.end || !reachable(date)
431
488
  ? { end: null, start: date }
432
- : between(range.start, date));
489
+ : between(range.start, date), details);
433
490
  return;
434
491
  }
435
492
  // Keeps the time of an earlier value (unless taking the date's).
436
493
  const next = new Date(date);
437
- if (single && !withTime) {
494
+ if (single && !hasTime) {
438
495
  next.setHours(single.getHours(), single.getMinutes(), 0, 0);
439
496
  }
440
497
  setValue(next);
441
- props.onValueChange?.(next);
498
+ props.onValueChange?.(next, details);
442
499
  };
443
500
  const onKeyDown = (event) => {
444
- const rtl = getComputedStyle(event.currentTarget).direction === 'rtl';
501
+ const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
445
502
  const column = (focused.getDay() - weekStart + 7) % 7;
446
503
  const moves = {
447
504
  ArrowDown: () => addDays(focused, 7),
448
- ArrowLeft: () => addDays(focused, rtl ? 1 : -1),
449
- ArrowRight: () => addDays(focused, rtl ? -1 : 1),
505
+ ArrowLeft: () => addDays(focused, isRightToLeft ? 1 : -1),
506
+ ArrowRight: () => addDays(focused, isRightToLeft ? -1 : 1),
450
507
  ArrowUp: () => addDays(focused, -7),
451
508
  End: () => addDays(focused, 6 - column),
452
509
  Home: () => addDays(focused, -column),
@@ -462,7 +519,7 @@ const CalendarPanel = (props) => {
462
519
  // Ranges are also dragged into existence: from the day pressed to the day
463
520
  // under the pointer, picked on release (taps pick start and end).
464
521
  const onPointerDown = (event) => {
465
- if (!props.range || event.button !== 0)
522
+ if (swipes !== 'date-range' || event.button !== 0)
466
523
  return;
467
524
  const from = dayOf(event.target);
468
525
  if (!from || !enabled(from))
@@ -470,7 +527,7 @@ const CalendarPanel = (props) => {
470
527
  drag.current = {
471
528
  edge: 0,
472
529
  from,
473
- moved: false,
530
+ isMoved: false,
474
531
  reachable: reachOf(from),
475
532
  x: event.clientX,
476
533
  y: event.clientY,
@@ -503,15 +560,17 @@ const CalendarPanel = (props) => {
503
560
  dragging.timer = setTimeout(step, 500);
504
561
  };
505
562
  const onPointerMove = (event) => {
563
+ if (swipes !== 'date-range')
564
+ return;
506
565
  const { current: dragging } = drag;
507
566
  if (!dragging)
508
567
  return;
509
- if (!dragging.moved) {
568
+ if (!dragging.isMoved) {
510
569
  if (Math.hypot(event.clientX - dragging.x, event.clientY - dragging.y) < 6) {
511
570
  return;
512
571
  }
513
572
  // Moves beyond the days are its own, too (the edges, see turnPage).
514
- dragging.moved = true;
573
+ dragging.isMoved = true;
515
574
  event.currentTarget.setPointerCapture(event.pointerId);
516
575
  setDraggedFrom(dragging.from);
517
576
  setDragged(between(dragging.from, dragging.from));
@@ -520,28 +579,34 @@ const CalendarPanel = (props) => {
520
579
  // days, or beyond their inline end): on to the next month; before its
521
580
  // first: back.
522
581
  const { bottom, left, right, top } = event.currentTarget.getBoundingClientRect();
523
- const rtl = getComputedStyle(event.currentTarget).direction === 'rtl';
582
+ const isRightToLeft = getComputedStyle(event.currentTarget).direction === 'rtl';
524
583
  const under = document.elementFromPoint(event.clientX, event.clientY);
525
584
  const outside = under instanceof Element
526
585
  ? under.closest('[data-outside]')?.dataset.outside
527
586
  : 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));
587
+ const isBeyondEnd = isRightToLeft
588
+ ? event.clientX < left
589
+ : event.clientX > right;
590
+ const isBeyondStart = isRightToLeft
591
+ ? event.clientX > right
592
+ : event.clientX < left;
593
+ const isAfter = event.clientY > bottom || isBeyondEnd || outside === 'after';
594
+ const isBefore = event.clientY < top || isBeyondStart || outside === 'before';
595
+ turnPage(Number(isAfter) - Number(isBefore));
533
596
  const over = dayOf(under);
534
597
  if (!over || !selectable(over) || !dragging.reachable(over))
535
598
  return;
536
599
  setDragged(between(dragging.from, over));
537
600
  setFocused(over);
538
601
  };
539
- const onPointerEnd = () => {
602
+ const onPointerEnd = (event) => {
603
+ if (swipes !== 'date-range')
604
+ return;
540
605
  const { current: dragging } = drag;
541
606
  clearTimeout(dragging?.timer);
542
607
  drag.current = undefined;
543
608
  setDraggedFrom(null);
544
- if (!dragging?.moved || !dragged) {
609
+ if (!dragging?.isMoved || !dragged) {
545
610
  setDragged(null);
546
611
  return;
547
612
  }
@@ -551,14 +616,12 @@ const CalendarPanel = (props) => {
551
616
  suppressClick.current = false;
552
617
  });
553
618
  setDragged(null);
554
- commitRange(dragged);
619
+ commitRange(dragged, { event, reason: 'drag' });
555
620
  };
556
621
  const showMonth = (next) => {
557
622
  goTo(next);
558
623
  setFocused(clampDay(next, min, max));
559
624
  };
560
- const previousDisabled = Boolean(min && addDays(startOfMonth(month), -1) < startOfDay(min));
561
- const nextDisabled = Boolean(max && startOfMonth(addMonths(month, 1)) > startOfDay(max));
562
625
  const toggle = (roll) => {
563
626
  const next = rolled === roll ? undefined : roll;
564
627
  setRolled(next);
@@ -569,7 +632,7 @@ const CalendarPanel = (props) => {
569
632
  // A day of the grid of `shown` (the month, or the one sliding out, not
570
633
  // `interactive`): another month's is blank, or grayed out (see
571
634
  // `showAdjacentMonths`); either is marked `data-outside`, for drags.
572
- const cell = (day, shown, interactive) => {
635
+ const cell = (day, shown, isInteractive) => {
573
636
  const outsideOf = day < shown ? 'before' : 'after';
574
637
  const outside = day.getMonth() === shown.getMonth() ? undefined : outsideOf;
575
638
  if (outside && !showAdjacentMonths) {
@@ -577,21 +640,24 @@ const CalendarPanel = (props) => {
577
640
  }
578
641
  // Not the adjacent months' days (nor their weekdays, see below).
579
642
  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
- ? () => {
643
+ 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
644
+ ? (event) => {
582
645
  // Another month's day: shows its month (not selected).
583
646
  if (outside) {
584
647
  showMonth(day);
585
648
  return;
586
649
  }
587
- select(day);
650
+ select(day, false, { event, reason: 'day-press' });
588
651
  }
589
652
  : 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
653
  };
591
654
  const footerContent = props.footer?.(footerOf({
592
- select: (date, withTime) => {
655
+ select: (date, hasTime = false) => {
593
656
  goTo(date);
594
- select(withTime ? date : startOfDay(date), withTime);
657
+ select(hasTime ? date : startOfDay(date), hasTime, {
658
+ event: new Event('select'),
659
+ reason: 'footer',
660
+ });
595
661
  },
596
662
  show: (date) => {
597
663
  goTo(date);
@@ -606,19 +672,21 @@ const CalendarPanel = (props) => {
606
672
  },
607
673
  value: range ?? single,
608
674
  }));
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] }))] }));
675
+ // A neighbour's page (see pager.ts): its days, not interactive.
676
+ const neighbour = (shown) => (_jsx("div", { inert: true, "aria-hidden": "true", className: "uikit-date-picker-weeks", "data-date-picker-part": "weeks", children: monthWeeks(shown, weekStart)
677
+ .flat()
678
+ .map((day) => cell(day, shown, false)) }, shown.getTime()));
679
+ 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", { 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) => {
680
+ if (!suppressClick.current)
681
+ return;
682
+ suppressClick.current = false;
683
+ event.stopPropagation();
684
+ }, onFocus: (event) => {
685
+ // The day focused (e.g. pressed): keys move on from it.
686
+ const day = dayOf(event.target);
687
+ if (day && !isSameDay(day, focused))
688
+ setFocused(day);
689
+ }, 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
690
  };
623
691
  /** A footer row (see `CalendarProps` `footer`): Figma “Time”'s, 52px. */
624
692
  const CalendarRow = TimeRow;
@@ -640,11 +708,14 @@ const Calendar = (props) => _jsx(CalendarPanel, { ...props });
640
708
  /** The calendar's props, of the picker's (its value, and its changes). */
641
709
  const calendarPropsOf = (props, change, value) => {
642
710
  const shared = {
711
+ // (The picker renders its own.)
712
+ formControl: false,
643
713
  firstDayOfWeek: props.firstDayOfWeek,
644
714
  highlighted: props.highlighted,
645
715
  highlightedWeekdays: props.highlightedWeekdays,
646
716
  isDateDisabled: props.isDateDisabled,
647
717
  showAdjacentMonths: props.showAdjacentMonths,
718
+ swipe: props.swipe,
648
719
  hourCycle: props.hourCycle,
649
720
  locale: props.locale,
650
721
  max: props.max,
@@ -664,9 +735,9 @@ const calendarPropsOf = (props, change, value) => {
664
735
  const usePickerValue = (props) => {
665
736
  const [value, setValue] = useControlled(props.value, props.defaultValue ?? null);
666
737
  // Only changed to the kind of value it has (a date or a range).
667
- const change = (next) => {
738
+ const change = (next, details) => {
668
739
  setValue(next);
669
- props.onValueChange?.(next);
740
+ props.onValueChange?.(next, details);
670
741
  };
671
742
  return {
672
743
  change,
@@ -677,18 +748,18 @@ const usePickerValue = (props) => {
677
748
  /** The open picker of the compact style, and its changes. */
678
749
  const usePickerOpen = (props) => {
679
750
  const [open, setOpen] = useControlled(props.open, props.defaultOpen ?? null);
680
- const change = (next) => {
751
+ const change = (next, details) => {
681
752
  setOpen(next);
682
- props.onOpenChange?.(next);
753
+ props.onOpenChange?.(next, details);
683
754
  };
684
755
  return [open, change];
685
756
  };
686
757
  /** The picker's default footer, with a time. */
687
758
  const defaultFooter = (calendar) => (_jsx(CalendarTimeRow, { calendar: calendar }));
688
759
  /** The compact style's time: its button, the roll in a popover. */
689
- const TimePopover = ({ align, disabled, label, onOpenChange, open, shape, ...props }) => {
760
+ const TimePopover = ({ align, isDisabled, label, onOpenChange, isOpen, shape, ...props }) => {
690
761
  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",
762
+ 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
763
  // The popup (not the first column: focused while the popup
693
764
  // opens, Chrome scrolls it off its selection).
694
765
  initialFocus: popupRef, children: _jsx("div", { className: "uikit-date-picker-time-popup", "data-date-picker-part": "time-popup", children: _jsx(TimeRoll, { ...props }) }) }) }) })] }));
@@ -707,32 +778,86 @@ const dateLabelOf = (format, range, single) => {
707
778
  * time, from the time's too, with the time's roll shown (as iOS's; one
708
779
  * popover for both).
709
780
  */
710
- const CalendarPopover = ({ align, children, dateLabel, disabled, onOpenChange, open, shape, timeLabel, }) => {
781
+ const CalendarPopover = ({ align, children, dateLabel, isDisabled, onOpenChange, open, shape, timeLabel, }) => {
711
782
  const dateTriggerId = useId();
712
783
  const timeTriggerId = useId();
713
784
  const collapsedRef = useRef(null);
714
785
  const hasTime = timeLabel !== undefined;
715
786
  // The time's button is the open one while the time's roll shows (however
716
787
  // it was opened, or shown), the date's otherwise.
717
- const [timeShown, setTimeShown] = useState(open === 'time');
788
+ const [isTimeShown, setIsTimeShown] = useState(open === 'time');
718
789
  const [openBefore, setOpenBefore] = useState(open);
719
790
  if (open !== openBefore) {
720
791
  setOpenBefore(open);
721
- setTimeShown(open === 'time');
792
+ setIsTimeShown(open === 'time');
722
793
  }
723
794
  // 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 }) => {
795
+ 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
796
  const trigger = event.target instanceof Element
726
797
  ? event.target.closest('[data-date-picker-trigger]')
727
798
  : null;
728
799
  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') }) }) })] }) }));
800
+ onOpenChange(isOpen ? picker : null, { event, reason });
801
+ }, 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
802
  };
732
803
  /** 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 }))] }));
804
+ const ToggleButtons = ({ dateLabel, isDisabled, onOpenChange, open, shape, timeLabel }) => {
805
+ const toggle = (picker, event) => onOpenChange(open === picker ? null : picker, {
806
+ event,
807
+ reason: 'trigger-press',
808
+ });
809
+ // Disabled while open (`isDisabled`, or from around it: e.g. a disabled
810
+ // fieldset's): closed (with a handle, its rows).
811
+ const ref = useRef(null);
812
+ useLayoutEffect(() => {
813
+ if (open === null)
814
+ return;
815
+ const button = ref.current?.querySelector('button');
816
+ if (!isDisabled && !button?.matches(':disabled'))
817
+ return;
818
+ onOpenChange(null, { event: new Event('disable'), reason: 'none' });
819
+ });
820
+ 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 }))] }));
821
+ };
822
+ /**
823
+ * A picker in collapsible list rows (see `List.CollapsiblePanel`): closed
824
+ * with them. With a handle, in a collapsible (e.g. a `List.AccordionItem`,
825
+ * with its row and `Expandable`): open with it, opening it, closed with it
826
+ * (e.g. another item opening).
827
+ */
828
+ const useListSync = (handle, open, changeOpen) => {
829
+ const isShown = useExpandedOpen();
830
+ const collapsible = useCollapsible();
831
+ const item = handle ? collapsible : undefined;
832
+ const isPickerOpen = open !== null;
833
+ const syncRef = useRef({
834
+ close: () => undefined,
835
+ toggleItem: () => undefined,
836
+ });
837
+ useLayoutEffect(() => {
838
+ syncRef.current = {
839
+ close: () => {
840
+ if (open === null)
841
+ return;
842
+ changeOpen(null, { event: new Event('close'), reason: 'none' });
843
+ },
844
+ toggleItem: () => {
845
+ if (!item || item.isOpen === isPickerOpen)
846
+ return;
847
+ item.setOpen(isPickerOpen, {
848
+ event: new Event('toggle'),
849
+ reason: 'none',
850
+ });
851
+ },
852
+ };
853
+ });
854
+ useEffect(() => {
855
+ if (isShown === false || item?.isOpen === false)
856
+ syncRef.current.close();
857
+ }, [isShown, item?.isOpen]);
858
+ useEffect(() => {
859
+ syncRef.current.toggleItem();
860
+ }, [isPickerOpen]);
736
861
  };
737
862
  /**
738
863
  * A date picker (UIKit `UIDatePicker`): a date, a time or both (`mode`), or
@@ -740,7 +865,7 @@ const ToggleButtons = ({ dateLabel, disabled, onOpenChange, open, shape, timeLab
740
865
  * time in a popover (or toggling `open`, without `popover`), or the
741
866
  * calendar in place (`pickerStyle`).
742
867
  */
743
- const DatePicker = (props) => {
868
+ const Root = (props) => {
744
869
  const { buttonShape, disabled = false, hourCycle, locale, mode = 'date', pickerStyle = 'compact', popover = true, } = props;
745
870
  const { change, range, single } = usePickerValue(props);
746
871
  const [open, changeOpen] = usePickerOpen(props);
@@ -751,20 +876,56 @@ const DatePicker = (props) => {
751
876
  const hasDate = props.range || mode !== 'time';
752
877
  const hasTime = !props.range && mode !== 'date';
753
878
  const calendarProps = calendarPropsOf(props, change, range ?? single);
879
+ useListSync(props.handle, open, changeOpen);
880
+ // With a handle: its pickers, for its `Expandable`.
881
+ const { handle } = props;
882
+ useLayoutEffect(() => {
883
+ handle?.publish({
884
+ calendar: hasDate ? _jsx(CalendarPanel, { ...calendarProps }) : undefined,
885
+ open,
886
+ time: hasTime ? (_jsx(TimeRoll, { hourCycle: hourCycle, locale: locale, max: props.max, min: props.min, value: single, onValueChange: change })) : undefined,
887
+ });
888
+ });
889
+ useLayoutEffect(() => () => handle?.publish(undefined), [handle]);
754
890
  // With a time, by default the Time row below.
755
891
  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();
892
+ // Its value's hidden control (see `name`), beside what it shows.
893
+ const formValue = (_jsx(FormValue, { form: props.form, mode: props.range ? 'date' : mode, name: props.name, value: range ?? single }));
894
+ if (pickerStyle === 'inline' && hasDate) {
895
+ return (_jsxs(_Fragment, { children: [calendar(), formValue] }));
896
+ }
758
897
  const dateLabel = dateLabelOf(formats.date, range, single);
759
898
  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 }));
899
+ // Without popovers: buttons toggling `open` (for the app to show them,
900
+ // or, with a handle, its `Expandable`).
901
+ if (!popover || props.handle) {
902
+ return (_jsxs(_Fragment, { children: [_jsx(ToggleButtons, { dateLabel: hasDate ? dateLabel : undefined, isDisabled: disabled, open: open, shape: buttonShape, timeLabel: hasTime ? timeLabel : undefined, onOpenChange: changeOpen }), formValue] }));
763
903
  }
764
904
  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 }) }));
905
+ 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
906
  }
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) }));
907
+ 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] }));
908
+ };
909
+ /**
910
+ * A date picker's pickers in place (see `Root` `handle`): its calendar and
911
+ * time roll, each in collapsible list rows (`List.CollapsiblePanel`),
912
+ * opened by its buttons; placed after the picker's row (as iOS's
913
+ * Calendar). In an `List.AccordionItem` (with its row), one of its items.
914
+ */
915
+ const Expandable = ({ handle, }) => {
916
+ const { calendar, open, time } = useSyncExternalStore(handle.subscribe, handle.getSnapshot);
917
+ 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 }) }) }) }))] }));
918
+ };
919
+ export { DatePickerHandle, useCreateDatePickerHandle } from './handle.js';
920
+ export const DatePicker = {
921
+ Root,
922
+ Expandable,
923
+ createHandle,
924
+ Calendar,
925
+ CalendarRow,
926
+ CalendarButton,
927
+ CalendarTimeRow,
928
+ CalendarMessage,
929
+ TimeRoll,
768
930
  };
769
- export { Calendar, CalendarButton, CalendarMessage, CalendarRow, CalendarTimeRow, DatePicker, TimeRoll, };
770
931
  //# sourceMappingURL=main.js.map