@zyncat/ui 0.8.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 (334) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/dist/alert.css +132 -0
  4. package/dist/alert.d.ts +46 -0
  5. package/dist/alert.js +80 -0
  6. package/dist/alert.js.map +1 -0
  7. package/dist/avatar-group.d.ts +24 -0
  8. package/dist/avatar-group.js +23 -0
  9. package/dist/avatar-group.js.map +1 -0
  10. package/dist/avatar.css +200 -0
  11. package/dist/avatar.d.ts +35 -0
  12. package/dist/avatar.js +67 -0
  13. package/dist/avatar.js.map +1 -0
  14. package/dist/badge.css +182 -0
  15. package/dist/badge.d.ts +34 -0
  16. package/dist/badge.js +4 -0
  17. package/dist/badge.js.map +1 -0
  18. package/dist/button.css +269 -0
  19. package/dist/button.d.ts +44 -0
  20. package/dist/button.js +4 -0
  21. package/dist/button.js.map +1 -0
  22. package/dist/checkbox.css +177 -0
  23. package/dist/checkbox.d.ts +35 -0
  24. package/dist/checkbox.js +5 -0
  25. package/dist/checkbox.js.map +1 -0
  26. package/dist/chunk-2ERBBFZS.js +12 -0
  27. package/dist/chunk-2ERBBFZS.js.map +1 -0
  28. package/dist/chunk-2HORSLXJ.js +191 -0
  29. package/dist/chunk-2HORSLXJ.js.map +1 -0
  30. package/dist/chunk-36WVAQKL.js +40 -0
  31. package/dist/chunk-36WVAQKL.js.map +1 -0
  32. package/dist/chunk-3SBCBYB7.js +575 -0
  33. package/dist/chunk-3SBCBYB7.js.map +1 -0
  34. package/dist/chunk-4R2GQO43.js +125 -0
  35. package/dist/chunk-4R2GQO43.js.map +1 -0
  36. package/dist/chunk-64UU4LGU.js +258 -0
  37. package/dist/chunk-64UU4LGU.js.map +1 -0
  38. package/dist/chunk-7SZCJ7WI.js +35 -0
  39. package/dist/chunk-7SZCJ7WI.js.map +1 -0
  40. package/dist/chunk-BIDVNLJO.js +38 -0
  41. package/dist/chunk-BIDVNLJO.js.map +1 -0
  42. package/dist/chunk-CONSWNIV.js +17 -0
  43. package/dist/chunk-CONSWNIV.js.map +1 -0
  44. package/dist/chunk-EQ32F2QJ.js +75 -0
  45. package/dist/chunk-EQ32F2QJ.js.map +1 -0
  46. package/dist/chunk-GY7JOPUQ.js +111 -0
  47. package/dist/chunk-GY7JOPUQ.js.map +1 -0
  48. package/dist/chunk-I4XQ4PV2.js +30 -0
  49. package/dist/chunk-I4XQ4PV2.js.map +1 -0
  50. package/dist/chunk-JSKXZMLH.js +67 -0
  51. package/dist/chunk-JSKXZMLH.js.map +1 -0
  52. package/dist/chunk-L3Q3VDIW.js +295 -0
  53. package/dist/chunk-L3Q3VDIW.js.map +1 -0
  54. package/dist/chunk-LDC3RIYA.js +62 -0
  55. package/dist/chunk-LDC3RIYA.js.map +1 -0
  56. package/dist/chunk-MKIQFK7S.js +43 -0
  57. package/dist/chunk-MKIQFK7S.js.map +1 -0
  58. package/dist/chunk-MMRIQNEN.js +20 -0
  59. package/dist/chunk-MMRIQNEN.js.map +1 -0
  60. package/dist/chunk-MXOPCFWR.js +59 -0
  61. package/dist/chunk-MXOPCFWR.js.map +1 -0
  62. package/dist/chunk-NEF5XAHG.js +17 -0
  63. package/dist/chunk-NEF5XAHG.js.map +1 -0
  64. package/dist/chunk-NNXJCLTV.js +22 -0
  65. package/dist/chunk-NNXJCLTV.js.map +1 -0
  66. package/dist/chunk-O4N2OBTR.js +94 -0
  67. package/dist/chunk-O4N2OBTR.js.map +1 -0
  68. package/dist/chunk-PMECHR3A.js +38 -0
  69. package/dist/chunk-PMECHR3A.js.map +1 -0
  70. package/dist/chunk-QDK66S4G.js +44 -0
  71. package/dist/chunk-QDK66S4G.js.map +1 -0
  72. package/dist/chunk-QGNC7LH5.js +8 -0
  73. package/dist/chunk-QGNC7LH5.js.map +1 -0
  74. package/dist/chunk-QMSJZCK3.js +398 -0
  75. package/dist/chunk-QMSJZCK3.js.map +1 -0
  76. package/dist/chunk-S5ZTZANS.js +57 -0
  77. package/dist/chunk-S5ZTZANS.js.map +1 -0
  78. package/dist/chunk-S7B34VGN.js +14 -0
  79. package/dist/chunk-S7B34VGN.js.map +1 -0
  80. package/dist/chunk-TCUCYFT7.js +25 -0
  81. package/dist/chunk-TCUCYFT7.js.map +1 -0
  82. package/dist/chunk-TYHR4VNM.js +193 -0
  83. package/dist/chunk-TYHR4VNM.js.map +1 -0
  84. package/dist/chunk-U5QQZC3U.js +56 -0
  85. package/dist/chunk-U5QQZC3U.js.map +1 -0
  86. package/dist/chunk-UE63OOVG.js +13 -0
  87. package/dist/chunk-UE63OOVG.js.map +1 -0
  88. package/dist/chunk-VTJTGVZZ.js +22 -0
  89. package/dist/chunk-VTJTGVZZ.js.map +1 -0
  90. package/dist/chunk-W3SHPKSB.js +49 -0
  91. package/dist/chunk-W3SHPKSB.js.map +1 -0
  92. package/dist/chunk-XZAEIQDR.js +188 -0
  93. package/dist/chunk-XZAEIQDR.js.map +1 -0
  94. package/dist/chunk-YGGCQNNU.js +92 -0
  95. package/dist/chunk-YGGCQNNU.js.map +1 -0
  96. package/dist/collapse.css +88 -0
  97. package/dist/collapse.d.ts +46 -0
  98. package/dist/collapse.js +5 -0
  99. package/dist/collapse.js.map +1 -0
  100. package/dist/count-badge.d.ts +13 -0
  101. package/dist/count-badge.js +13 -0
  102. package/dist/count-badge.js.map +1 -0
  103. package/dist/date-field.d.ts +25 -0
  104. package/dist/date-field.js +87 -0
  105. package/dist/date-field.js.map +1 -0
  106. package/dist/date-picker.css +595 -0
  107. package/dist/date-range-field.d.ts +33 -0
  108. package/dist/date-range-field.js +404 -0
  109. package/dist/date-range-field.js.map +1 -0
  110. package/dist/datetime-field.d.ts +29 -0
  111. package/dist/datetime-field.js +155 -0
  112. package/dist/datetime-field.js.map +1 -0
  113. package/dist/dialog.css +180 -0
  114. package/dist/dialog.d.ts +42 -0
  115. package/dist/dialog.js +128 -0
  116. package/dist/dialog.js.map +1 -0
  117. package/dist/dom-props-C0jrllBw.d.ts +5 -0
  118. package/dist/field-chrome-CMPOQSLs.d.ts +28 -0
  119. package/dist/field-shell-Cuda-feL.d.ts +24 -0
  120. package/dist/glide.d.ts +15 -0
  121. package/dist/glide.js +5 -0
  122. package/dist/glide.js.map +1 -0
  123. package/dist/icon.css +33 -0
  124. package/dist/input.css +333 -0
  125. package/dist/mcp.js +359 -0
  126. package/dist/motion-devtools.css +265 -0
  127. package/dist/motion-devtools.d.ts +51 -0
  128. package/dist/motion-devtools.js +354 -0
  129. package/dist/motion-devtools.js.map +1 -0
  130. package/dist/motion-scale-Canq4stZ.d.ts +18 -0
  131. package/dist/motion-tokens.d.ts +28 -0
  132. package/dist/motion-tokens.js +3 -0
  133. package/dist/motion-tokens.js.map +1 -0
  134. package/dist/multi-select.d.ts +44 -0
  135. package/dist/multi-select.js +109 -0
  136. package/dist/multi-select.js.map +1 -0
  137. package/dist/number-field.d.ts +36 -0
  138. package/dist/number-field.js +112 -0
  139. package/dist/number-field.js.map +1 -0
  140. package/dist/odometer.css +62 -0
  141. package/dist/otp-field.d.ts +31 -0
  142. package/dist/otp-field.js +98 -0
  143. package/dist/otp-field.js.map +1 -0
  144. package/dist/overlay.css +23 -0
  145. package/dist/pagination.css +43 -0
  146. package/dist/pagination.d.ts +29 -0
  147. package/dist/pagination.js +107 -0
  148. package/dist/pagination.js.map +1 -0
  149. package/dist/popover.css +69 -0
  150. package/dist/popover.d.ts +35 -0
  151. package/dist/popover.js +15 -0
  152. package/dist/popover.js.map +1 -0
  153. package/dist/radio-group.css +300 -0
  154. package/dist/radio-group.d.ts +52 -0
  155. package/dist/radio-group.js +115 -0
  156. package/dist/radio-group.js.map +1 -0
  157. package/dist/select.css +416 -0
  158. package/dist/select.d.ts +49 -0
  159. package/dist/select.js +99 -0
  160. package/dist/select.js.map +1 -0
  161. package/dist/sheet.css +26 -0
  162. package/dist/sheet.d.ts +31 -0
  163. package/dist/sheet.js +14 -0
  164. package/dist/sheet.js.map +1 -0
  165. package/dist/status-badge.d.ts +19 -0
  166. package/dist/status-badge.js +72 -0
  167. package/dist/status-badge.js.map +1 -0
  168. package/dist/table.css +348 -0
  169. package/dist/table.d.ts +75 -0
  170. package/dist/table.js +262 -0
  171. package/dist/table.js.map +1 -0
  172. package/dist/tabs.css +208 -0
  173. package/dist/tabs.d.ts +71 -0
  174. package/dist/tabs.js +181 -0
  175. package/dist/tabs.js.map +1 -0
  176. package/dist/tag.css +248 -0
  177. package/dist/tag.d.ts +52 -0
  178. package/dist/tag.js +72 -0
  179. package/dist/tag.js.map +1 -0
  180. package/dist/text-field.d.ts +28 -0
  181. package/dist/text-field.js +69 -0
  182. package/dist/text-field.js.map +1 -0
  183. package/dist/textarea.css +219 -0
  184. package/dist/textarea.d.ts +38 -0
  185. package/dist/textarea.js +144 -0
  186. package/dist/textarea.js.map +1 -0
  187. package/dist/time-field.d.ts +28 -0
  188. package/dist/time-field.js +66 -0
  189. package/dist/time-field.js.map +1 -0
  190. package/dist/timing-7JA_zQHP.d.ts +27 -0
  191. package/dist/toast-store.d.ts +86 -0
  192. package/dist/toast-store.js +3 -0
  193. package/dist/toast-store.js.map +1 -0
  194. package/dist/toast.css +257 -0
  195. package/dist/toast.d.ts +12 -0
  196. package/dist/toast.js +310 -0
  197. package/dist/toast.js.map +1 -0
  198. package/dist/toggle-tag.d.ts +34 -0
  199. package/dist/toggle-tag.js +57 -0
  200. package/dist/toggle-tag.js.map +1 -0
  201. package/dist/toggle.css +152 -0
  202. package/dist/toggle.d.ts +31 -0
  203. package/dist/toggle.js +75 -0
  204. package/dist/toggle.js.map +1 -0
  205. package/dist/tooltip.css +86 -0
  206. package/dist/tooltip.d.ts +30 -0
  207. package/dist/tooltip.js +268 -0
  208. package/dist/tooltip.js.map +1 -0
  209. package/dist/types-SGMShK7R.d.ts +22 -0
  210. package/llms.txt +196 -0
  211. package/next.d.mts +7 -0
  212. package/next.mjs +59 -0
  213. package/package.json +257 -0
  214. package/src/components/composites/alert/Alert.tsx +141 -0
  215. package/src/components/composites/alert/alert.css +132 -0
  216. package/src/components/composites/date-picker/DateField.tsx +80 -0
  217. package/src/components/composites/date-picker/DateRangeField.tsx +110 -0
  218. package/src/components/composites/date-picker/DateTimeField.tsx +162 -0
  219. package/src/components/composites/date-picker/TimeField.tsx +78 -0
  220. package/src/components/composites/date-picker/calendar-panel.tsx +216 -0
  221. package/src/components/composites/date-picker/date-picker.css +595 -0
  222. package/src/components/composites/date-picker/date-utils.ts +56 -0
  223. package/src/components/composites/date-picker/field-shell.tsx +85 -0
  224. package/src/components/composites/date-picker/range-panel.tsx +363 -0
  225. package/src/components/composites/date-picker/time-core.tsx +290 -0
  226. package/src/components/composites/date-picker/use-day-focus.ts +35 -0
  227. package/src/components/composites/dialog/Dialog.tsx +198 -0
  228. package/src/components/composites/dialog/dialog.css +180 -0
  229. package/src/components/composites/pagination/Pagination.tsx +131 -0
  230. package/src/components/composites/pagination/pagination.css +43 -0
  231. package/src/components/composites/popover/Popover.tsx +141 -0
  232. package/src/components/composites/popover/popover.css +69 -0
  233. package/src/components/composites/select/MultiSelect.tsx +133 -0
  234. package/src/components/composites/select/Select.tsx +122 -0
  235. package/src/components/composites/select/core/index.ts +4 -0
  236. package/src/components/composites/select/core/menu.tsx +100 -0
  237. package/src/components/composites/select/core/panel.tsx +154 -0
  238. package/src/components/composites/select/core/trigger.tsx +74 -0
  239. package/src/components/composites/select/core/types.ts +39 -0
  240. package/src/components/composites/select/core/use-listbox.ts +182 -0
  241. package/src/components/composites/select/select.css +416 -0
  242. package/src/components/composites/sheet/Sheet.tsx +135 -0
  243. package/src/components/composites/sheet/sheet.css +26 -0
  244. package/src/components/composites/sheet/use-sheet-drag.ts +126 -0
  245. package/src/components/composites/table/Table.tsx +377 -0
  246. package/src/components/composites/table/table.css +348 -0
  247. package/src/components/composites/tabs/Tabs.tsx +278 -0
  248. package/src/components/composites/tabs/tabs.css +208 -0
  249. package/src/components/composites/toast/Toast.tsx +380 -0
  250. package/src/components/composites/toast/toast-store.ts +295 -0
  251. package/src/components/composites/toast/toast.css +257 -0
  252. package/src/components/composites/tooltip/Tooltip.tsx +110 -0
  253. package/src/components/composites/tooltip/tooltip-host.tsx +184 -0
  254. package/src/components/composites/tooltip/tooltip-store.ts +81 -0
  255. package/src/components/composites/tooltip/tooltip.css +86 -0
  256. package/src/components/dev/MotionDevtools.tsx +200 -0
  257. package/src/components/dev/motion-devtools.css +265 -0
  258. package/src/components/dev/slowmo-engine.ts +230 -0
  259. package/src/components/internal/glass/glass.css +100 -0
  260. package/src/components/internal/glass/glint.ts +9 -0
  261. package/src/components/internal/hooks/use-controllable.ts +21 -0
  262. package/src/components/internal/hooks/use-scroll-edges.ts +46 -0
  263. package/src/components/internal/icon/Icon.tsx +66 -0
  264. package/src/components/internal/icon/IconSlot.tsx +10 -0
  265. package/src/components/internal/icon/icon.css +33 -0
  266. package/src/components/internal/overlay/focus.ts +68 -0
  267. package/src/components/internal/overlay/layer.tsx +149 -0
  268. package/src/components/internal/overlay/modal.tsx +141 -0
  269. package/src/components/internal/overlay/overlay.css +23 -0
  270. package/src/components/internal/overlay/position.ts +103 -0
  271. package/src/components/internal/utils/cx.ts +3 -0
  272. package/src/components/internal/utils/token-px.ts +8 -0
  273. package/src/components/primitives/avatar/Avatar.tsx +120 -0
  274. package/src/components/primitives/avatar/AvatarGroup.tsx +56 -0
  275. package/src/components/primitives/avatar/avatar.css +200 -0
  276. package/src/components/primitives/badge/Badge.tsx +75 -0
  277. package/src/components/primitives/badge/CountBadge.tsx +20 -0
  278. package/src/components/primitives/badge/StatusBadge.tsx +111 -0
  279. package/src/components/primitives/badge/badge.css +182 -0
  280. package/src/components/primitives/badge/odometer.css +62 -0
  281. package/src/components/primitives/badge/odometer.tsx +36 -0
  282. package/src/components/primitives/button/Button.tsx +102 -0
  283. package/src/components/primitives/button/button.css +269 -0
  284. package/src/components/primitives/checkbox/Checkbox.tsx +76 -0
  285. package/src/components/primitives/checkbox/check-glyph.tsx +28 -0
  286. package/src/components/primitives/checkbox/checkbox.css +177 -0
  287. package/src/components/primitives/collapse/Collapse.tsx +86 -0
  288. package/src/components/primitives/collapse/collapse.css +88 -0
  289. package/src/components/primitives/collapse/collapse.typecheck.tsx +29 -0
  290. package/src/components/primitives/input/NumberField.tsx +139 -0
  291. package/src/components/primitives/input/OtpField.tsx +134 -0
  292. package/src/components/primitives/input/TextField.tsx +110 -0
  293. package/src/components/primitives/input/field-chrome.tsx +83 -0
  294. package/src/components/primitives/input/input.css +333 -0
  295. package/src/components/primitives/radio-group/RadioGroup.tsx +183 -0
  296. package/src/components/primitives/radio-group/radio-group.css +300 -0
  297. package/src/components/primitives/tag/Tag.tsx +143 -0
  298. package/src/components/primitives/tag/ToggleTag.tsx +97 -0
  299. package/src/components/primitives/tag/tag.css +248 -0
  300. package/src/components/primitives/textarea/Textarea.tsx +190 -0
  301. package/src/components/primitives/textarea/textarea.css +219 -0
  302. package/src/components/primitives/toggle/Toggle.tsx +105 -0
  303. package/src/components/primitives/toggle/toggle.css +152 -0
  304. package/src/css.d.ts +1 -0
  305. package/src/dom-props.ts +1 -0
  306. package/src/engine/animate.ts +141 -0
  307. package/src/engine/drag.ts +53 -0
  308. package/src/engine/ease.ts +155 -0
  309. package/src/engine/flip.ts +59 -0
  310. package/src/engine/index.ts +13 -0
  311. package/src/mcp/server.ts +420 -0
  312. package/src/motion/element.tsx +53 -0
  313. package/src/motion/flip.tsx +87 -0
  314. package/src/motion/glide.tsx +47 -0
  315. package/src/motion/motion-timing.ts +33 -0
  316. package/src/motion/presence-context.ts +18 -0
  317. package/src/motion/presence.tsx +91 -0
  318. package/src/motion/timing.ts +49 -0
  319. package/src/motion/use-motion.ts +64 -0
  320. package/src/styles.css +26 -0
  321. package/src/tokens/avatar.css +20 -0
  322. package/src/tokens/color.css +58 -0
  323. package/src/tokens/elevation.css +22 -0
  324. package/src/tokens/fonts.css +3 -0
  325. package/src/tokens/glass.css +20 -0
  326. package/src/tokens/icons.css +7 -0
  327. package/src/tokens/layers.css +6 -0
  328. package/src/tokens/motion-scale.ts +17 -0
  329. package/src/tokens/motion-tokens.ts +92 -0
  330. package/src/tokens/motion.css +49 -0
  331. package/src/tokens/radius.css +11 -0
  332. package/src/tokens/semantic.css +65 -0
  333. package/src/tokens/spacing.css +26 -0
  334. package/src/tokens/typography.css +52 -0
@@ -0,0 +1,290 @@
1
+ 'use client';
2
+
3
+ import './date-picker.css';
4
+ import { useEffect, useRef, useState, type ClipboardEvent, type KeyboardEvent, type RefObject } from 'react';
5
+ import { cx } from '../../internal/utils/cx';
6
+ import { pad } from './date-utils';
7
+
8
+ type Meridiem = 'AM' | 'PM';
9
+ type Segment = 'h' | 'm';
10
+ interface Pending {
11
+ seg: Segment;
12
+ d: number;
13
+ }
14
+
15
+ export interface TimeSegmentsProps {
16
+ value?: string | null;
17
+ onCommit?: (value: string) => void;
18
+ format?: '24h' | '12h';
19
+ minuteStep?: number;
20
+ min?: string | null;
21
+ max?: string | null;
22
+ disabled?: boolean;
23
+ ariaLabel?: string;
24
+ className?: string;
25
+ }
26
+
27
+ export const disp12 = (h24: number): number => ((h24 + 11) % 12) + 1;
28
+ const tsgToH24 = (d12: number, mer: Meridiem): number => (d12 % 12) + (mer === 'PM' ? 12 : 0);
29
+
30
+ function tsgFeed(pend: number | null, d: number, hi: number): { val: number; done: boolean } {
31
+ if (pend != null) {
32
+ const n = pend * 10 + d;
33
+ if (n <= hi) return { val: n, done: true };
34
+ }
35
+ return { val: d, done: d * 10 > hi };
36
+ }
37
+
38
+ export function TimeSegments({
39
+ value = null,
40
+ onCommit,
41
+ format = '24h',
42
+ minuteStep = 5,
43
+ min = null,
44
+ max = null,
45
+ disabled = false,
46
+ ariaLabel = 'Time',
47
+ className = '',
48
+ }: TimeSegmentsProps) {
49
+ const is12 = format === '12h';
50
+ const seed = value ? value.split(':').map(Number) : [null, null];
51
+
52
+ const [h, setHState] = useState<number | null>(seed[0]);
53
+ const [m, setMState] = useState<number | null>(seed[1]);
54
+ const [mer, setMer] = useState<Meridiem>(seed[0] != null && seed[0] >= 12 ? 'PM' : 'AM');
55
+ const [pend, setPendState] = useState<Pending | null>(null);
56
+
57
+ const hLive = useRef<number | null>(seed[0]);
58
+ const mLive = useRef<number | null>(seed[1]);
59
+ const pendLive = useRef<Pending | null>(null);
60
+ const setH = (v: number | null) => {
61
+ hLive.current = v;
62
+ setHState(v);
63
+ };
64
+ const setM = (v: number | null) => {
65
+ mLive.current = v;
66
+ setMState(v);
67
+ };
68
+ const setPend = (v: Pending | null) => {
69
+ pendLive.current = v;
70
+ setPendState(v);
71
+ };
72
+
73
+ const hRef = useRef<HTMLSpanElement>(null);
74
+ const mRef = useRef<HTMLSpanElement>(null);
75
+ const merRef = useRef<HTMLSpanElement>(null);
76
+ const lastRef = useRef<string | null>(value || null);
77
+
78
+ useEffect(() => {
79
+ if ((value || null) === lastRef.current) return;
80
+ lastRef.current = value || null;
81
+ const p = value ? value.split(':').map(Number) : [null, null];
82
+ setH(p[0]);
83
+ setM(p[1]);
84
+ if (p[0] != null) setMer(p[0] >= 12 ? 'PM' : 'AM');
85
+ setPend(null);
86
+ }, [value]);
87
+
88
+ function tryCommit(nh: number | null, nm: number | null) {
89
+ if (nh == null || nm == null) return;
90
+ let t = pad(nh) + ':' + pad(nm);
91
+ if (min && t < min) t = min;
92
+ if (max && t > max) t = max;
93
+ const p = t.split(':').map(Number);
94
+ if (p[0] !== nh) {
95
+ setH(p[0]);
96
+ setMer(p[0] >= 12 ? 'PM' : 'AM');
97
+ setPend(null);
98
+ }
99
+ if (p[1] !== nm) setM(p[1]);
100
+ if (t === lastRef.current) return;
101
+ lastRef.current = t;
102
+ if (onCommit) onCommit(t);
103
+ }
104
+
105
+ const focusSeg = (r: RefObject<HTMLSpanElement | null>) => {
106
+ if (r.current) r.current.focus();
107
+ };
108
+
109
+ function onHKey(e: KeyboardEvent<HTMLSpanElement>) {
110
+ const k = e.key;
111
+ if (/^[0-9]$/.test(k)) {
112
+ const pd = pend && pend.seg === 'h' ? pend.d : null;
113
+ const r = tsgFeed(pd, +k, is12 ? 12 : 23);
114
+ const nh = is12 ? tsgToH24(r.val === 0 ? 12 : r.val, mer) : r.val;
115
+ setH(nh);
116
+ if (!is12) setMer(nh >= 12 ? 'PM' : 'AM');
117
+ setPend(r.done ? null : { seg: 'h', d: r.val });
118
+ if (r.done) {
119
+ focusSeg(mRef);
120
+ tryCommit(nh, mLive.current);
121
+ }
122
+ } else if (k === 'ArrowUp' || k === 'ArrowDown') {
123
+ const dir = k === 'ArrowUp' ? 1 : -1;
124
+ const nh = h == null ? new Date().getHours() : (h + dir + 24) % 24;
125
+ setH(nh);
126
+ setMer(nh >= 12 ? 'PM' : 'AM');
127
+ setPend(null);
128
+ tryCommit(nh, mLive.current);
129
+ } else if (k === 'Backspace' || k === 'Delete') {
130
+ setH(null);
131
+ setPend(null);
132
+ } else if (k === 'ArrowRight' || k === ':' || k === ';') {
133
+ focusSeg(mRef);
134
+ } else if (k === 'Tab') {
135
+ return;
136
+ } else if (k.length === 1 && !e.metaKey && !e.ctrlKey) {
137
+ } else return;
138
+ e.preventDefault();
139
+ }
140
+
141
+ function onMKey(e: KeyboardEvent<HTMLSpanElement>) {
142
+ const k = e.key;
143
+ if (/^[0-9]$/.test(k)) {
144
+ const pd = pend && pend.seg === 'm' ? pend.d : null;
145
+ const r = tsgFeed(pd, +k, 59);
146
+ setM(r.val);
147
+ setPend(r.done ? null : { seg: 'm', d: r.val });
148
+ if (r.done) {
149
+ if (is12) focusSeg(merRef);
150
+ tryCommit(hLive.current, r.val);
151
+ }
152
+ } else if (k === 'ArrowUp' || k === 'ArrowDown') {
153
+ const dir = k === 'ArrowUp' ? 1 : -1;
154
+ let nm;
155
+ if (m == null) {
156
+ nm = (Math.round(new Date().getMinutes() / minuteStep) * minuteStep) % 60;
157
+ } else {
158
+ const next =
159
+ dir > 0 ? (Math.floor(m / minuteStep) + 1) * minuteStep : (Math.ceil(m / minuteStep) - 1) * minuteStep;
160
+ nm = ((next % 60) + 60) % 60;
161
+ }
162
+ setM(nm);
163
+ setPend(null);
164
+ tryCommit(hLive.current, nm);
165
+ } else if (k === 'Backspace' || k === 'Delete') {
166
+ if (m == null && !(pend && pend.seg === 'm')) {
167
+ focusSeg(hRef);
168
+ } else {
169
+ setM(null);
170
+ setPend(null);
171
+ }
172
+ } else if (k === 'ArrowLeft') {
173
+ focusSeg(hRef);
174
+ } else if (k === 'ArrowRight' && is12) {
175
+ focusSeg(merRef);
176
+ } else if (k === 'Tab') {
177
+ return;
178
+ } else if (k.length === 1 && !e.metaKey && !e.ctrlKey) {
179
+ } else return;
180
+ e.preventDefault();
181
+ }
182
+
183
+ function setMeridiem(next: Meridiem) {
184
+ setMer(next);
185
+ if (h != null) {
186
+ const nh = tsgToH24(disp12(h), next);
187
+ setH(nh);
188
+ tryCommit(nh, mLive.current);
189
+ }
190
+ }
191
+ function onMerKey(e: KeyboardEvent<HTMLSpanElement>) {
192
+ const k = e.key;
193
+ if (k === 'a' || k === 'A') setMeridiem('AM');
194
+ else if (k === 'p' || k === 'P') setMeridiem('PM');
195
+ else if (k === 'ArrowUp' || k === 'ArrowDown') setMeridiem(mer === 'AM' ? 'PM' : 'AM');
196
+ else if (k === 'ArrowLeft') focusSeg(mRef);
197
+ else if (k === 'Tab') {
198
+ return;
199
+ } else if (k.length === 1 && !e.metaKey && !e.ctrlKey) {
200
+ } else return;
201
+ e.preventDefault();
202
+ }
203
+
204
+ function onPaste(e: ClipboardEvent<HTMLDivElement>) {
205
+ if (disabled) return;
206
+ const txt = (e.clipboardData.getData('text') || '').trim();
207
+ const mt = txt.match(/^(\d{1,2})[:h.\s]?(\d{2})?\s*([ap])\.?m?\.?$/i) || txt.match(/^(\d{1,2})[:h.\s]?(\d{2})?$/);
208
+ if (!mt) return;
209
+ e.preventDefault();
210
+ let hh = +mt[1];
211
+ const mm = mt[2] != null ? +mt[2] : 0;
212
+ if (mt[3]) hh = tsgToH24(hh, /^p/i.test(mt[3]) ? 'PM' : 'AM');
213
+ if (hh > 23 || mm > 59) return;
214
+ setH(hh);
215
+ setM(mm);
216
+ setMer(hh >= 12 ? 'PM' : 'AM');
217
+ setPend(null);
218
+ tryCommit(hh, mm);
219
+ }
220
+
221
+ const onSegBlur = (seg: Segment) => () => {
222
+ if (pendLive.current && pendLive.current.seg === seg) {
223
+ setPend(null);
224
+ tryCommit(hLive.current, mLive.current);
225
+ }
226
+ };
227
+
228
+ const hText = pend && pend.seg === 'h' ? pad(pend.d) : h == null ? '--' : pad(is12 ? disp12(h) : h);
229
+ const mText = pend && pend.seg === 'm' ? pad(pend.d) : m == null ? '--' : pad(m);
230
+
231
+ const segCls = (empty: boolean): string => 'tsg__seg' + (empty ? ' is-empty' : '');
232
+ const tab = disabled ? -1 : 0;
233
+
234
+ return (
235
+ <div
236
+ className={cx('tsg', disabled && 'is-disabled', className)}
237
+ role="group"
238
+ aria-label={ariaLabel}
239
+ aria-disabled={disabled || undefined}
240
+ onPaste={onPaste}
241
+ >
242
+ <span
243
+ ref={hRef}
244
+ className={segCls(h == null && !(pend && pend.seg === 'h'))}
245
+ role="spinbutton"
246
+ tabIndex={tab}
247
+ aria-label="Hours"
248
+ aria-valuemin={is12 ? 1 : 0}
249
+ aria-valuemax={is12 ? 12 : 23}
250
+ aria-valuenow={h == null ? undefined : is12 ? disp12(h) : h}
251
+ aria-valuetext={h == null ? 'Empty' : hText}
252
+ onKeyDown={disabled ? undefined : onHKey}
253
+ onBlur={onSegBlur('h')}
254
+ >
255
+ {hText}
256
+ </span>
257
+ <span className="tsg__sep" aria-hidden="true">
258
+ :
259
+ </span>
260
+ <span
261
+ ref={mRef}
262
+ className={segCls(m == null && !(pend && pend.seg === 'm'))}
263
+ role="spinbutton"
264
+ tabIndex={tab}
265
+ aria-label="Minutes"
266
+ aria-valuemin={0}
267
+ aria-valuemax={59}
268
+ aria-valuenow={m == null ? undefined : m}
269
+ aria-valuetext={m == null ? 'Empty' : mText}
270
+ onKeyDown={disabled ? undefined : onMKey}
271
+ onBlur={onSegBlur('m')}
272
+ >
273
+ {mText}
274
+ </span>
275
+ {is12 ? (
276
+ <span
277
+ ref={merRef}
278
+ className="tsg__seg tsg__seg--mer"
279
+ role="spinbutton"
280
+ tabIndex={tab}
281
+ aria-label="AM or PM"
282
+ aria-valuetext={mer}
283
+ onKeyDown={disabled ? undefined : onMerKey}
284
+ >
285
+ {mer}
286
+ </span>
287
+ ) : null}
288
+ </div>
289
+ );
290
+ }
@@ -0,0 +1,35 @@
1
+ 'use client';
2
+
3
+ import { useEffect, useRef, type RefObject } from 'react';
4
+
5
+ export function useDayFocus(
6
+ daysRef: RefObject<HTMLDivElement | null>,
7
+ focusKey: string,
8
+ viewDep?: number,
9
+ seedSelector?: string,
10
+ ): () => void {
11
+ const pending = useRef(false);
12
+
13
+ useEffect(() => {
14
+ const el = daysRef.current;
15
+ if (!el) return;
16
+ const btn =
17
+ (seedSelector && el.querySelector(seedSelector)) ||
18
+ el.querySelector('[data-key="' + focusKey + '"]:not(:disabled)') ||
19
+ el.querySelector('.dtp__day:not(:disabled)');
20
+ if (btn) (btn as HTMLElement).focus({ preventScroll: true });
21
+ // eslint-disable-next-line react-hooks/exhaustive-deps
22
+ }, []);
23
+
24
+ useEffect(() => {
25
+ if (!pending.current || !daysRef.current) return;
26
+ pending.current = false;
27
+ const btn = daysRef.current.querySelector('[data-key="' + focusKey + '"]');
28
+ if (btn) (btn as HTMLElement).focus({ preventScroll: true });
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [focusKey, viewDep]);
31
+
32
+ return () => {
33
+ pending.current = true;
34
+ };
35
+ }
@@ -0,0 +1,198 @@
1
+ 'use client';
2
+
3
+ import './dialog.css';
4
+ import { Fragment, useId, useRef, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
5
+ import { Presence } from '../../../motion/presence';
6
+ import { resolveMotionTiming } from '../../../motion/motion-timing';
7
+ import type { DisableableAnimation } from '../../../motion/timing';
8
+ import { useControllable } from '../../internal/hooks/use-controllable';
9
+ import { ovCloneTrigger, OverlayPortal } from '../../internal/overlay/layer';
10
+ import { ModalShell } from '../../internal/overlay/modal';
11
+ import { Icon } from '../../internal/icon/Icon';
12
+ import { IconSlot } from '../../internal/icon/IconSlot';
13
+ import { useScrollEdges } from '../../internal/hooks/use-scroll-edges';
14
+ import type { DataAttributes } from '../../../dom-props';
15
+ import { cx } from '../../internal/utils/cx';
16
+
17
+ const DIALOG_TIMING = {
18
+ open: { duration: 'slow', ease: 'entrance' },
19
+ close: { duration: 'base', ease: 'standard' },
20
+ } as const;
21
+
22
+ export interface DialogProps {
23
+ /** Controlled open state. Omit for uncontrolled (use defaultOpen + trigger). */
24
+ open?: boolean;
25
+ /** Initial open state when uncontrolled. @default false */
26
+ defaultOpen?: boolean;
27
+ /** Fires whenever the open state changes. Pair with `open` for controlled use. */
28
+ onOpenChange?: (open: boolean) => void;
29
+ /** Optional element cloned to open the dialog on click (uncontrolled ergonomics). */
30
+ trigger?: ReactElement | null;
31
+ /** Header title - rendered as the `<h2>` and wired to `aria-labelledby`. */
32
+ title?: ReactNode;
33
+ /** Subtext under the title - wired to `aria-describedby`. @default null */
34
+ description?: ReactNode;
35
+ /** Panel width. @default 'md' */
36
+ size?: 'sm' | 'md' | 'lg';
37
+ /** 'danger' tints the header icon badge + is the convention for destructive confirms. */
38
+ tone?: 'default' | 'danger';
39
+ /** Your own icon node for the header badge (alert dialogs). */
40
+ icon?: ReactNode;
41
+ /** Close button + backdrop/Esc dismissal. Default true. */
42
+ dismissible?: boolean;
43
+ /** Action row - a node, or a render fn `(close) => node` so uncontrolled dialogs can dismiss. */
44
+ footer?: ReactNode | ((close: () => void) => ReactNode);
45
+ /** Dialog body - scrolls when tall; its scroll edges flag the header lift + footer divider. */
46
+ children?: ReactNode;
47
+ /** Base id for the panel; drives the trigger's `aria-controls` and the title/desc aria ids.
48
+ * Auto-generated when omitted. */
49
+ id?: string;
50
+ /** Standard attributes (className, style, data-*, ...) forwarded to the dialog `<section>`. */
51
+ htmlProps?: HTMLAttributes<HTMLElement> & DataAttributes;
52
+ /** Open/close timing - motion tokens only, or `null` to disable. @default open 'slow'/'entrance', close 'base'/'standard' */
53
+ animation?: DisableableAnimation;
54
+ }
55
+
56
+ interface DialogSurfaceProps {
57
+ panelId: string;
58
+ size: 'sm' | 'md' | 'lg';
59
+ tone: 'default' | 'danger';
60
+ icon: ReactNode;
61
+ title: ReactNode;
62
+ description: ReactNode;
63
+ dismissible: boolean;
64
+ footerContent: ReactNode;
65
+ requestClose: () => void;
66
+ htmlProps?: HTMLAttributes<HTMLElement> & DataAttributes;
67
+ children?: ReactNode;
68
+ }
69
+
70
+ function DialogSurface({
71
+ panelId,
72
+ size,
73
+ tone,
74
+ icon,
75
+ title,
76
+ description,
77
+ dismissible,
78
+ footerContent,
79
+ requestClose,
80
+ htmlProps,
81
+ children,
82
+ }: DialogSurfaceProps) {
83
+ const bodyRef = useRef<HTMLDivElement>(null);
84
+ const titleId = panelId + '-title';
85
+ const descId = panelId + '-desc';
86
+
87
+ useScrollEdges(bodyRef, (edges, el) => {
88
+ el.toggleAttribute('data-scroll-top', edges.top);
89
+ el.toggleAttribute('data-scroll-bottom', edges.bottom);
90
+ });
91
+
92
+ return (
93
+ <section
94
+ {...htmlProps}
95
+ className={cx('dialog', htmlProps?.className)}
96
+ role="dialog"
97
+ aria-modal="true"
98
+ data-size={size === 'md' ? undefined : size}
99
+ data-tone={tone === 'default' ? undefined : tone}
100
+ aria-labelledby={title ? titleId : undefined}
101
+ aria-describedby={description ? descId : undefined}
102
+ >
103
+ <header className="dialog__header">
104
+ {icon && (
105
+ <span className="dialog__icon">
106
+ <IconSlot size="md">{icon}</IconSlot>
107
+ </span>
108
+ )}
109
+ <div className="dialog__heading">
110
+ {title && (
111
+ <h2 className="dialog__title" id={titleId}>
112
+ {title}
113
+ </h2>
114
+ )}
115
+ {description && (
116
+ <p className="dialog__desc" id={descId}>
117
+ {description}
118
+ </p>
119
+ )}
120
+ </div>
121
+ {dismissible && (
122
+ <button type="button" className="dialog__close" aria-label="Close dialog" onClick={requestClose}>
123
+ <Icon name="x" size="sm" weight="bold" />
124
+ </button>
125
+ )}
126
+ </header>
127
+
128
+ <div className="dialog__body" ref={bodyRef}>
129
+ {children}
130
+ </div>
131
+
132
+ {footerContent && <footer className="dialog__footer">{footerContent}</footer>}
133
+ </section>
134
+ );
135
+ }
136
+
137
+ export function Dialog({
138
+ open: controlledOpen,
139
+ defaultOpen = false,
140
+ onOpenChange,
141
+ trigger = null,
142
+ title,
143
+ description = null,
144
+ size = 'md',
145
+ tone = 'default',
146
+ icon = null,
147
+ dismissible = true,
148
+ footer = null,
149
+ children,
150
+ id,
151
+ htmlProps,
152
+ animation,
153
+ }: DialogProps) {
154
+ const autoId = useId();
155
+ const panelId = id || 'dialog-' + autoId;
156
+ const [open, setOpen] = useControllable(controlledOpen, defaultOpen, onOpenChange);
157
+ const triggerRef = useRef<HTMLElement>(null);
158
+ const close = () => setOpen(false);
159
+
160
+ const timings = resolveMotionTiming(animation, DIALOG_TIMING);
161
+
162
+ return (
163
+ <Fragment>
164
+ {ovCloneTrigger(trigger, { open, onPress: () => setOpen(true), panelId, haspopup: 'dialog', triggerRef })}
165
+ <OverlayPortal>
166
+ <Presence>
167
+ {open && (
168
+ <ModalShell
169
+ key="dialog"
170
+ animate={{ y: [6, 0], scale: [0.98, 1], opacity: [0, 1], timing: timings.open }}
171
+ exit={{ y: [6], scale: [0.98], opacity: [0], timing: timings.close }}
172
+ layerClass="overlay-layer--dialog"
173
+ panelClass="overlay-panel--dialog"
174
+ panelId={panelId}
175
+ dismissible={dismissible}
176
+ requestClose={close}
177
+ >
178
+ <DialogSurface
179
+ panelId={panelId}
180
+ size={size}
181
+ tone={tone}
182
+ icon={icon}
183
+ title={title}
184
+ description={description}
185
+ dismissible={dismissible}
186
+ footerContent={typeof footer === 'function' ? footer(close) : footer}
187
+ requestClose={close}
188
+ htmlProps={htmlProps}
189
+ >
190
+ {children}
191
+ </DialogSurface>
192
+ </ModalShell>
193
+ )}
194
+ </Presence>
195
+ </OverlayPortal>
196
+ </Fragment>
197
+ );
198
+ }
@@ -0,0 +1,180 @@
1
+ /* dialog.css - the styled dialog surface (the modal shell owns modality + motion). */
2
+
3
+ /* Modal placement - the shell layer centers the panel with breathing room. */
4
+ .overlay-layer--dialog {
5
+ place-items: center;
6
+ padding: var(--space-6);
7
+ }
8
+ .overlay-panel--dialog {
9
+ max-width: 100%;
10
+ max-height: 100%;
11
+ }
12
+
13
+ /* The panel - flex column so the body scrolls between a pinned header + footer; padding lives on the parts. */
14
+ .dialog {
15
+ --dialog-w: 32rem;
16
+ position: relative;
17
+ margin: 0;
18
+ display: flex;
19
+ flex-direction: column;
20
+ min-height: 0;
21
+ width: var(--dialog-w);
22
+ max-width: 100%;
23
+ max-height: min(85dvh, 44rem);
24
+ padding: 0;
25
+ overflow: hidden;
26
+ background: var(--bg-surface);
27
+ border: var(--border-hairline) solid var(--border-default);
28
+ border-radius: var(--radius-xl);
29
+ box-shadow: var(--shadow-xl);
30
+ color: var(--text-body);
31
+ font-family: var(--font-sans);
32
+ }
33
+
34
+ .dialog[data-size='sm'] {
35
+ --dialog-w: 25rem;
36
+ }
37
+ .dialog[data-size='lg'] {
38
+ --dialog-w: 40rem;
39
+ }
40
+
41
+ /* Header - icon - heading - close; flex-start keeps a tall heading top-aligned with the badge. */
42
+ .dialog__header {
43
+ flex: 0 0 auto;
44
+ display: flex;
45
+ align-items: flex-start;
46
+ gap: var(--space-3);
47
+ padding: var(--space-5) var(--space-5) var(--space-4);
48
+ transition:
49
+ border-color var(--duration-base) var(--ease-standard),
50
+ box-shadow var(--duration-base) var(--ease-standard);
51
+ border-bottom: var(--border-hairline) solid transparent;
52
+ }
53
+ /* divider + faint lift appears only once the body is scrolled under it */
54
+ .dialog:has(.dialog__body[data-scroll-top]) .dialog__header {
55
+ border-bottom-color: var(--border-subtle);
56
+ box-shadow: var(--shadow-xs);
57
+ }
58
+
59
+ .dialog__icon {
60
+ flex: 0 0 auto;
61
+ display: grid;
62
+ place-items: center;
63
+ width: 2.25rem;
64
+ height: 2.25rem;
65
+ border-radius: var(--radius-md);
66
+ background: var(--accent-subtle);
67
+ color: var(--text-accent);
68
+ font-size: var(--icon-md);
69
+ }
70
+ .dialog[data-tone='danger'] .dialog__icon {
71
+ background: var(--danger-subtle);
72
+ color: var(--danger-text);
73
+ }
74
+
75
+ .dialog__heading {
76
+ flex: 1 1 auto;
77
+ min-width: 0;
78
+ display: flex;
79
+ flex-direction: column;
80
+ gap: var(--space-1);
81
+ /* nudge text to optical-center against the 36px icon badge when present */
82
+ padding-top: var(--space-px);
83
+ }
84
+ .dialog__title {
85
+ margin: 0;
86
+ color: var(--text-strong);
87
+ font: var(--weight-semibold) var(--size-heading)/var(--leading-heading) var(--font-sans);
88
+ letter-spacing: var(--tracking-tight);
89
+ text-wrap: pretty;
90
+ }
91
+ .dialog__desc {
92
+ margin: 0;
93
+ color: var(--text-muted);
94
+ font: var(--type-body);
95
+ text-wrap: pretty;
96
+ }
97
+
98
+ /* close - a quiet ghost icon button; the hit box is bigger than the glyph */
99
+ .dialog__close {
100
+ flex: 0 0 auto;
101
+ appearance: none;
102
+ margin: calc(var(--space-1) * -1) calc(var(--space-1) * -1) 0 0;
103
+ display: grid;
104
+ place-items: center;
105
+ width: 1.75rem;
106
+ height: 1.75rem;
107
+ padding: 0;
108
+ border: none;
109
+ border-radius: var(--radius-md);
110
+ background: transparent;
111
+ color: var(--text-subtle);
112
+ cursor: pointer;
113
+ font-size: var(--icon-sm);
114
+ transition: var(--transition-control);
115
+ }
116
+ .dialog__close:hover {
117
+ background: var(--neutral-wash);
118
+ color: var(--text-strong);
119
+ }
120
+ .dialog__close:active {
121
+ background: var(--bg-muted);
122
+ }
123
+ .dialog__close:focus-visible {
124
+ outline: none;
125
+ color: var(--text-strong);
126
+ box-shadow: var(--ring-accent);
127
+ }
128
+
129
+ /* Body - the scroll region; min-height:0 lets it shrink so header/footer stay pinned. */
130
+ .dialog__body {
131
+ flex: 1 1 auto;
132
+ min-height: 0;
133
+ overflow-y: auto;
134
+ overscroll-behavior: contain;
135
+ padding: 0 var(--space-5) var(--space-5);
136
+ color: var(--text-body);
137
+ font: var(--type-body);
138
+ }
139
+ .dialog:has(.dialog__icon) .dialog__body {
140
+ padding-left: calc(var(--space-5) + 2.25rem + var(--space-3));
141
+ }
142
+ .dialog:has(.dialog__footer) .dialog__body {
143
+ padding-bottom: var(--space-4);
144
+ }
145
+ .dialog__body > :first-child {
146
+ margin-top: 0;
147
+ }
148
+ .dialog__body > :last-child {
149
+ margin-bottom: 0;
150
+ }
151
+
152
+ .dialog__body {
153
+ scrollbar-width: thin;
154
+ scrollbar-color: var(--border-strong) transparent;
155
+ }
156
+ .dialog__body::-webkit-scrollbar {
157
+ width: 10px;
158
+ }
159
+ .dialog__body::-webkit-scrollbar-thumb {
160
+ background: var(--border-strong);
161
+ border-radius: var(--radius-full);
162
+ border: 3px solid var(--bg-surface);
163
+ background-clip: padding-box;
164
+ }
165
+
166
+ /* Footer - right-aligned actions; gains a top divider only when the body scrolls under it. */
167
+ .dialog__footer {
168
+ flex: 0 0 auto;
169
+ display: flex;
170
+ align-items: center;
171
+ justify-content: flex-end;
172
+ gap: var(--space-2);
173
+ flex-wrap: wrap;
174
+ padding: var(--space-4) var(--space-5) var(--space-5);
175
+ border-top: var(--border-hairline) solid transparent;
176
+ transition: border-color var(--duration-base) var(--ease-standard);
177
+ }
178
+ .dialog:has(.dialog__body[data-scroll-bottom]) .dialog__footer {
179
+ border-top-color: var(--border-subtle);
180
+ }