@godxjp/ui 20.0.0 → 20.1.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 (250) hide show
  1. package/README.md +8 -2
  2. package/dist/app/theme-axes.d.ts +2 -0
  3. package/dist/app/theme-axes.js +45 -0
  4. package/dist/components/charts/chart-cartesian.d.ts +2 -1
  5. package/dist/components/charts/chart-cartesian.js +52 -3
  6. package/dist/components/charts/chart-category-axis.d.ts +55 -0
  7. package/dist/components/charts/chart-category-axis.js +93 -0
  8. package/dist/components/charts/chart-frame.d.ts +10 -1
  9. package/dist/components/charts/chart-frame.js +19 -3
  10. package/dist/components/charts/compact-bar-trend.d.ts +1 -1
  11. package/dist/components/charts/compact-bar-trend.js +2 -0
  12. package/dist/components/charts/pie-chart.d.ts +1 -1
  13. package/dist/components/charts/pie-chart.js +12 -1
  14. package/dist/components/charts/recharts-peer.d.ts +49 -0
  15. package/dist/components/charts/recharts-peer.js +45 -0
  16. package/dist/components/data-display/card.d.ts +12 -1
  17. package/dist/components/data-display/card.js +22 -4
  18. package/dist/components/data-display/code-block.js +6 -2
  19. package/dist/components/data-display/data-table.d.ts +39 -4
  20. package/dist/components/data-display/data-table.js +802 -270
  21. package/dist/components/data-display/descriptions.d.ts +27 -6
  22. package/dist/components/data-display/descriptions.js +58 -17
  23. package/dist/components/data-display/index.d.ts +2 -0
  24. package/dist/components/data-display/index.js +2 -0
  25. package/dist/components/data-display/list-row.d.ts +10 -1
  26. package/dist/components/data-display/list-row.js +7 -1
  27. package/dist/components/data-display/popover.d.ts +2 -2
  28. package/dist/components/data-display/popover.js +61 -11
  29. package/dist/components/data-display/range-timeline.d.ts +38 -0
  30. package/dist/components/data-display/range-timeline.js +161 -0
  31. package/dist/components/data-display/scroll-area.js +13 -2
  32. package/dist/components/data-display/service-launcher-card.js +10 -10
  33. package/dist/components/data-display/table.d.ts +11 -3
  34. package/dist/components/data-display/table.js +48 -18
  35. package/dist/components/data-display/tree-list.js +4 -9
  36. package/dist/components/data-entry/calendar.d.ts +2 -2
  37. package/dist/components/data-entry/calendar.js +12 -1
  38. package/dist/components/data-entry/cascader.d.ts +1 -1
  39. package/dist/components/data-entry/cascader.js +188 -24
  40. package/dist/components/data-entry/color-picker.d.ts +1 -1
  41. package/dist/components/data-entry/color-picker.js +17 -5
  42. package/dist/components/data-entry/control-appearance.d.ts +64 -0
  43. package/dist/components/data-entry/control-appearance.js +39 -0
  44. package/dist/components/data-entry/control-surface.d.ts +61 -0
  45. package/dist/components/data-entry/control-surface.js +39 -0
  46. package/dist/components/data-entry/date-picker.d.ts +1 -1
  47. package/dist/components/data-entry/date-picker.js +344 -113
  48. package/dist/components/data-entry/date-range-picker.d.ts +1 -1
  49. package/dist/components/data-entry/date-range-picker.js +278 -140
  50. package/dist/components/data-entry/form-field.d.ts +1 -1
  51. package/dist/components/data-entry/form-field.js +39 -4
  52. package/dist/components/data-entry/form.d.ts +4 -0
  53. package/dist/components/data-entry/form.js +4 -2
  54. package/dist/components/data-entry/index.d.ts +7 -3
  55. package/dist/components/data-entry/index.js +10 -1
  56. package/dist/components/data-entry/input-otp.d.ts +1 -1
  57. package/dist/components/data-entry/input.d.ts +12 -34
  58. package/dist/components/data-entry/input.js +92 -24
  59. package/dist/components/data-entry/month-picker.d.ts +1 -1
  60. package/dist/components/data-entry/month-picker.js +47 -10
  61. package/dist/components/data-entry/month-range-picker.d.ts +1 -1
  62. package/dist/components/data-entry/month-range-picker.js +51 -11
  63. package/dist/components/data-entry/number-input.d.ts +7 -0
  64. package/dist/components/data-entry/number-input.js +147 -98
  65. package/dist/components/data-entry/password-input.d.ts +1 -1
  66. package/dist/components/data-entry/radio.d.ts +1 -1
  67. package/dist/components/data-entry/radio.js +61 -13
  68. package/dist/components/data-entry/search-input.d.ts +1 -1
  69. package/dist/components/data-entry/search-input.js +16 -2
  70. package/dist/components/data-entry/search-select.d.ts +2 -2
  71. package/dist/components/data-entry/search-select.js +209 -78
  72. package/dist/components/data-entry/select.d.ts +22 -4
  73. package/dist/components/data-entry/select.js +215 -163
  74. package/dist/components/data-entry/slider.d.ts +9 -1
  75. package/dist/components/data-entry/slider.js +87 -9
  76. package/dist/components/data-entry/switch.d.ts +3 -0
  77. package/dist/components/data-entry/switch.js +29 -3
  78. package/dist/components/data-entry/textarea.d.ts +14 -56
  79. package/dist/components/data-entry/textarea.js +80 -33
  80. package/dist/components/data-entry/time-picker.d.ts +2 -2
  81. package/dist/components/data-entry/time-picker.js +333 -109
  82. package/dist/components/data-entry/time-range-picker.d.ts +5 -0
  83. package/dist/components/data-entry/time-range-picker.js +89 -0
  84. package/dist/components/data-entry/transfer.d.ts +1 -1
  85. package/dist/components/data-entry/transfer.js +86 -28
  86. package/dist/components/data-entry/tree-select.d.ts +1 -1
  87. package/dist/components/data-entry/tree-select.js +201 -113
  88. package/dist/components/data-entry/tree-utils.js +7 -14
  89. package/dist/components/data-entry/upload-files.d.ts +2 -0
  90. package/dist/components/data-entry/upload-files.js +31 -0
  91. package/dist/components/data-entry/upload-request.d.ts +4 -0
  92. package/dist/components/data-entry/upload-request.js +53 -0
  93. package/dist/components/data-entry/upload-types.d.ts +28 -0
  94. package/dist/components/data-entry/upload-types.js +2 -0
  95. package/dist/components/data-entry/upload.d.ts +2 -2
  96. package/dist/components/data-entry/upload.js +475 -115
  97. package/dist/components/feedback/dialog.js +16 -19
  98. package/dist/components/general/button.d.ts +1 -1
  99. package/dist/components/general/button.js +5 -1
  100. package/dist/components/general/index.d.ts +1 -0
  101. package/dist/components/general/index.js +2 -0
  102. package/dist/components/general/typography.d.ts +3 -0
  103. package/dist/components/general/typography.js +15 -1
  104. package/dist/components/general/visually-hidden.d.ts +3 -0
  105. package/dist/components/general/visually-hidden.js +9 -0
  106. package/dist/components/layout/app-launcher.d.ts +34 -0
  107. package/dist/components/layout/app-launcher.js +228 -0
  108. package/dist/components/layout/app-shell.d.ts +2 -0
  109. package/dist/components/layout/app-shell.js +20 -7
  110. package/dist/components/layout/breadcrumb.d.ts +14 -2
  111. package/dist/components/layout/breadcrumb.js +46 -4
  112. package/dist/components/layout/flex.d.ts +1 -1
  113. package/dist/components/layout/flex.js +23 -2
  114. package/dist/components/layout/index.d.ts +3 -0
  115. package/dist/components/layout/index.js +5 -1
  116. package/dist/components/layout/org-switcher.js +20 -1
  117. package/dist/components/layout/page-container.d.ts +1 -1
  118. package/dist/components/layout/page-container.js +5 -3
  119. package/dist/components/layout/responsive-grid.d.ts +16 -2
  120. package/dist/components/layout/responsive-grid.js +29 -2
  121. package/dist/components/layout/topbar-item.d.ts +3 -0
  122. package/dist/components/layout/topbar-item.js +18 -3
  123. package/dist/components/layout/topbar.d.ts +1 -1
  124. package/dist/components/layout/topbar.js +27 -6
  125. package/dist/components/navigation/dropdown-menu.d.ts +30 -2
  126. package/dist/components/navigation/dropdown-menu.js +68 -11
  127. package/dist/components/navigation/pagination.d.ts +2 -2
  128. package/dist/components/navigation/pagination.js +155 -83
  129. package/dist/components/navigation/steps.d.ts +2 -2
  130. package/dist/components/navigation/steps.js +29 -4
  131. package/dist/components/navigation/tabs.d.ts +5 -33
  132. package/dist/components/navigation/tabs.js +232 -64
  133. package/dist/components/ui/input-otp.d.ts +26 -28
  134. package/dist/components/ui/input-otp.js +50 -7
  135. package/dist/components/ui/password-input.d.ts +36 -2
  136. package/dist/components/ui/password-input.js +27 -7
  137. package/dist/components/ui/rating.d.ts +25 -0
  138. package/dist/components/ui/rating.js +67 -27
  139. package/dist/components/ui/segmented.d.ts +9 -0
  140. package/dist/components/ui/segmented.js +17 -2
  141. package/dist/components/ui/separator.d.ts +4 -0
  142. package/dist/components/ui/separator.js +13 -0
  143. package/dist/components/ui/tag-input.d.ts +45 -0
  144. package/dist/components/ui/tag-input.js +109 -27
  145. package/dist/form/form-context.d.ts +29 -0
  146. package/dist/form/form-context.js +44 -4
  147. package/dist/form/form-field-array.d.ts +22 -0
  148. package/dist/form/form-field-array.js +50 -0
  149. package/dist/form/form-field-control.d.ts +2 -1
  150. package/dist/form/form-field-control.js +116 -40
  151. package/dist/form/form-root.d.ts +2 -1
  152. package/dist/form/form-root.js +142 -23
  153. package/dist/form/index.d.ts +3 -1
  154. package/dist/form/index.js +12 -1
  155. package/dist/i18n/messages/en.json +56 -5
  156. package/dist/i18n/messages/ja.json +56 -5
  157. package/dist/i18n/messages/vi.json +56 -5
  158. package/dist/inertia/index.d.ts +20 -0
  159. package/dist/inertia/index.js +60 -1
  160. package/dist/lib/control-styles.d.ts +25 -3
  161. package/dist/lib/control-styles.js +9 -3
  162. package/dist/lib/datetime/picker-format.d.ts +8 -0
  163. package/dist/lib/datetime/picker-format.js +54 -0
  164. package/dist/props/components/charts.prop.d.ts +21 -0
  165. package/dist/props/components/data-display.prop.d.ts +55 -4
  166. package/dist/props/components/data-entry.prop.d.ts +687 -43
  167. package/dist/props/components/form.prop.d.ts +142 -4
  168. package/dist/props/components/general.prop.d.ts +17 -1
  169. package/dist/props/components/index.d.ts +2 -2
  170. package/dist/props/components/layout.prop.d.ts +163 -6
  171. package/dist/props/components/navigation.prop.d.ts +113 -3
  172. package/dist/props/registry.d.ts +376 -10
  173. package/dist/props/registry.js +493 -9
  174. package/dist/props/vocabulary/data.prop.d.ts +179 -1
  175. package/dist/props/vocabulary/index.d.ts +4 -4
  176. package/dist/props/vocabulary/interaction.prop.d.ts +51 -2
  177. package/dist/props/vocabulary/navigation.prop.d.ts +40 -0
  178. package/dist/props/vocabulary/shared.prop.d.ts +33 -0
  179. package/dist/styles/badge-layout.css +2 -1
  180. package/dist/styles/card-layout.css +26 -4
  181. package/dist/styles/chart-layout.css +15 -0
  182. package/dist/styles/control.css +515 -14
  183. package/dist/styles/data-display-layout.css +241 -6
  184. package/dist/styles/data-entry-layout.css +13 -0
  185. package/dist/styles/layout.css +221 -4
  186. package/dist/styles/navigation-layout.css +227 -0
  187. package/dist/styles/shell-layout.css +229 -5
  188. package/dist/styles/table-layout.css +95 -6
  189. package/dist/styles/text-layout.css +5 -0
  190. package/dist/tokens/base.css +1 -0
  191. package/dist/tokens/components/badge.css +1 -0
  192. package/dist/tokens/components/chart.css +6 -0
  193. package/dist/tokens/components/control.css +79 -2
  194. package/dist/tokens/components/data-display.css +9 -0
  195. package/dist/tokens/components/descriptions.css +11 -0
  196. package/dist/tokens/components/flex.css +8 -0
  197. package/dist/tokens/components/navigation.css +55 -0
  198. package/dist/tokens/components/shell.css +50 -2
  199. package/dist/tokens/components/table.css +14 -0
  200. package/dist/tokens/semantic/layout.css +9 -0
  201. package/docs/CONSUMER-RULES.md +13 -0
  202. package/docs/DESIGN-AUTHORITY.md +43 -6
  203. package/docs/DEVELOPMENT.md +4 -3
  204. package/docs/FORMS.md +151 -6
  205. package/docs/FRAME-COVERAGE-REPORT.md +29 -16
  206. package/docs/README.md +1 -1
  207. package/docs/STANDARDS-vocabulary-tokens.md +1 -1
  208. package/docs/TESTING.md +15 -6
  209. package/docs/charts/cjk-category-axis.tsx +81 -0
  210. package/docs/data-display/card/index.tsx +22 -0
  211. package/docs/data-display/data-table/examples/antd-parity.tsx +257 -0
  212. package/docs/data-display/data-table/index.tsx +23 -0
  213. package/docs/data-display/descriptions.tsx +41 -0
  214. package/docs/data-display/scroll-area.tsx +31 -25
  215. package/docs/data-display/table.tsx +104 -45
  216. package/docs/data-display/timeline.tsx +41 -0
  217. package/docs/data-entry/date-picker.tsx +85 -0
  218. package/docs/data-entry/date-range-picker.tsx +26 -0
  219. package/docs/data-entry/form-dynamic-fields.tsx +199 -0
  220. package/docs/data-entry/form.tsx +74 -4
  221. package/docs/data-entry/input-otp.tsx +24 -0
  222. package/docs/data-entry/input.tsx +46 -1
  223. package/docs/data-entry/month-range-picker.tsx +1 -1
  224. package/docs/data-entry/select.tsx +27 -0
  225. package/docs/data-entry/switch.tsx +41 -0
  226. package/docs/data-entry/textarea.tsx +38 -0
  227. package/docs/data-entry/time-picker.tsx +85 -1
  228. package/docs/data-entry/time-range-picker.tsx +55 -0
  229. package/docs/data-entry/transfer.tsx +17 -0
  230. package/docs/data-entry/upload.tsx +56 -12
  231. package/docs/feedback/tooltip.tsx +1 -1
  232. package/docs/general/activity.tsx +2 -2
  233. package/docs/general/button/index.tsx +14 -1
  234. package/docs/general/typography.tsx +14 -1
  235. package/docs/layout/app-launcher.tsx +151 -0
  236. package/docs/layout/app-shell.tsx +11 -0
  237. package/docs/layout/flex.tsx +50 -0
  238. package/docs/layout/responsive-grid.tsx +21 -1
  239. package/docs/layout/topbar.tsx +5 -9
  240. package/docs/navigation/app-setting-picker.tsx +11 -0
  241. package/docs/navigation/breadcrumb.tsx +48 -0
  242. package/docs/navigation/dropdown-menu.tsx +21 -0
  243. package/docs/navigation/pagination.tsx +52 -0
  244. package/docs/navigation/steps.tsx +37 -0
  245. package/docs/navigation/tabs.tsx +97 -1
  246. package/docs/query/button-refetch.tsx +1 -0
  247. package/package.json +19 -2
  248. package/scripts/_agent-setup.mjs +19 -2
  249. package/scripts/init-guinea-pig.mjs +26 -4
  250. package/scripts/ui-audit.mjs +243 -30
@@ -1,36 +1,92 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
- import { CalendarIcon, X } from "lucide-react";
4
+ import { CalendarIcon, ChevronLeft, ChevronRight, X } from "lucide-react";
5
5
  import { usePickerLocales, useTranslation } from "../../i18n/use-translation.js";
6
- import { parseDateInput, toIsoDate } from "../../lib/datetime/parse.js";
6
+ import { toIsoDate } from "../../lib/datetime/parse.js";
7
+ import {
8
+ formatPickerDate,
9
+ parsePickerDate,
10
+ pickerDateAllowed,
11
+ pickerPeriodStart
12
+ } from "../../lib/datetime/picker-format.js";
13
+ import { Button } from "../general/button.js";
14
+ import { Flex } from "../layout/flex.js";
15
+ import { TimePicker } from "./time-picker.js";
7
16
  import { useControlledLatch } from "../../lib/hooks.js";
8
17
  import { pickFieldA11y, useFieldIdentity } from "../../lib/field-a11y.js";
9
18
  import { cn } from "../../lib/utils.js";
19
+ import { resolveAllowClear } from "./control-surface.js";
10
20
  import { Input } from "./input.js";
11
21
  import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../data-display/popover.js";
12
22
  import { Calendar } from "./calendar.js";
13
23
  const ISO_HINT = "yyyy-mm-dd";
14
- function DatePicker({
15
- value: valueProp,
16
- defaultValue,
17
- onValueChange,
18
- placeholder,
19
- disabled,
20
- className,
21
- id,
22
- name,
23
- locale: localeProp,
24
- showToday,
25
- showClose,
26
- fromDate,
27
- toDate,
28
- allowClear = true,
29
- ...ariaProps
30
- }) {
24
+ function DatePicker(props) {
25
+ const {
26
+ value: valueProp,
27
+ defaultValue,
28
+ placeholder,
29
+ disabled,
30
+ className,
31
+ id,
32
+ name,
33
+ locale: localeProp,
34
+ showToday,
35
+ showClose,
36
+ fromDate,
37
+ toDate,
38
+ disabledDate,
39
+ cellRender,
40
+ allowClear,
41
+ format: formatProp,
42
+ parseFormat,
43
+ minDate,
44
+ maxDate,
45
+ showWeek,
46
+ showTime,
47
+ presets,
48
+ multiple = false,
49
+ picker = "date",
50
+ order = true,
51
+ needConfirm = Boolean(showTime),
52
+ open: openProp,
53
+ defaultOpen = false,
54
+ onOpenChange,
55
+ inputReadOnly,
56
+ preserveInvalidOnBlur,
57
+ placement = "bottom-start",
58
+ renderExtraFooter,
59
+ size,
60
+ status,
61
+ variant,
62
+ ref,
63
+ ...ariaProps
64
+ } = props;
65
+ const format = formatProp ?? (typeof showTime === "object" && showTime.showSeconds ? "yyyy-MM-dd HH:mm:ss" : void 0);
31
66
  const { t } = useTranslation();
32
- const { dayPickerLocale } = usePickerLocales(localeProp);
33
- const [open, setOpen] = React.useState(false);
67
+ const { dayPickerLocale, locale } = usePickerLocales(localeProp);
68
+ const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
69
+ const open = !disabled && (openProp ?? internalOpen);
70
+ const [pending, setPending] = React.useState();
71
+ const [hasPending, setHasPending] = React.useState(false);
72
+ const setOpen = (next) => {
73
+ if (disabled && next) return;
74
+ if (openProp === void 0) setInternalOpen(next);
75
+ onOpenChange?.(next);
76
+ if (!next) {
77
+ setHasPending(false);
78
+ setPending(void 0);
79
+ }
80
+ };
81
+ const timeAllowed = (date) => {
82
+ const rules = typeof showTime === "object" ? showTime.disabledTime?.() : void 0;
83
+ return !(rules?.disabledHours?.().includes(date.getHours()) || rules?.disabledMinutes?.(date.getHours()).includes(date.getMinutes()) || rules?.disabledSeconds?.(date.getHours(), date.getMinutes()).includes(date.getSeconds()));
84
+ };
85
+ const minimum = minDate ?? fromDate;
86
+ const maximum = maxDate ?? toDate;
87
+ const allowed = (date) => pickerDateAllowed(date, minimum, maximum, disabledDate);
88
+ const display = (date) => Array.isArray(date) ? date.map((day) => formatPickerDate(day, format, locale)).join(", ") : formatPickerDate(date, format, locale, Boolean(showTime));
89
+ const parse = (text2) => parsePickerDate(text2, format, parseFormat, Boolean(showTime));
34
90
  const fieldA11y = pickFieldA11y(ariaProps);
35
91
  const identity = useFieldIdentity({ id, name, "data-field": fieldA11y["data-field"] });
36
92
  const resolvedName = name ?? identity.name;
@@ -40,63 +96,106 @@ function DatePicker({
40
96
  const isControlled = useControlledLatch(valueProp !== void 0);
41
97
  const [internalValue, setInternalValue] = React.useState(defaultValue);
42
98
  const value = isControlled ? valueProp : internalValue;
99
+ const working = hasPending ? pending : value;
100
+ const selectedDate = Array.isArray(working) ? working[0] : working;
101
+ const [viewYear, setViewYear] = React.useState((selectedDate ?? /* @__PURE__ */ new Date()).getFullYear());
102
+ const periodDate = (date) => pickerPeriodStart(date, picker, dayPickerLocale);
43
103
  const emit = (next) => {
44
104
  if (!isControlled) setInternalValue(next);
45
- onValueChange?.(next);
105
+ if (props.multiple)
106
+ props.onValueChange?.(Array.isArray(next) ? next : next ? [next] : void 0);
107
+ else props.onValueChange?.(Array.isArray(next) ? next[0] : next);
46
108
  };
47
- const [text, setText] = React.useState(() => toIsoDate(value));
109
+ const [text, setText] = React.useState(() => display(value));
48
110
  React.useEffect(() => {
49
- setText(toIsoDate(value));
50
- }, [value]);
111
+ setText(
112
+ Array.isArray(value) ? value.map((date) => formatPickerDate(date, format, locale)).join(", ") : formatPickerDate(value, format, locale, Boolean(showTime))
113
+ );
114
+ }, [value, format, locale, showTime]);
51
115
  const resolvedPlaceholder = placeholder ?? t("dataEntry.datePicker.placeholder") ?? ISO_HINT;
52
116
  const clear = () => {
53
117
  emit(void 0);
54
118
  setText("");
55
119
  };
56
- const showClear = allowClear && text !== "" && !disabled;
120
+ const clearControl = resolveAllowClear(allowClear, true, t("common.clear") ?? "Clear");
121
+ const showClear = clearControl.enabled && text !== "" && !disabled;
122
+ const choose = (input) => {
123
+ let date = input;
124
+ if (Array.isArray(date)) {
125
+ if (date.some((day) => !allowed(day))) return;
126
+ if (order) date = [...date].sort((a, b) => +a - +b);
127
+ } else if (date) {
128
+ date = periodDate(date);
129
+ if (!allowed(date) || !needConfirm && !timeAllowed(date)) return;
130
+ if (multiple) {
131
+ const current = Array.isArray(working) ? working : [];
132
+ date = current.some((day) => +day === +date) ? current.filter((day) => +day !== +date) : [...current, date];
133
+ if (order) date.sort((a, b) => +a - +b);
134
+ }
135
+ }
136
+ if (needConfirm) {
137
+ setPending(date);
138
+ setHasPending(true);
139
+ } else {
140
+ emit(date);
141
+ setText(display(date));
142
+ }
143
+ };
57
144
  const commit = (raw) => {
58
- const trimmed = raw.trim();
59
- if (trimmed === "") {
60
- emit(void 0);
145
+ if (!raw.trim()) {
146
+ choose(void 0);
61
147
  return;
62
148
  }
63
- if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) return;
64
- const parsed = parseDateInput(trimmed);
65
- if (parsed) {
66
- emit(parsed);
67
- }
149
+ const parsed = parse(raw);
150
+ if (parsed && allowed(parsed)) choose(parsed);
68
151
  };
69
- return /* @__PURE__ */ jsx(Popover, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
70
- /* @__PURE__ */ jsx(
71
- Input,
152
+ return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
153
+ (format || showTime || multiple || needConfirm || preserveInvalidOnBlur) && resolvedName ? /* @__PURE__ */ jsx(
154
+ "input",
72
155
  {
73
- id,
74
- name: resolvedName,
75
- "data-field": resolvedField,
76
- value: text,
156
+ type: "hidden",
77
157
  disabled,
78
- placeholder: resolvedPlaceholder,
79
- inputMode: "numeric",
80
- autoComplete: "off",
81
- role: "combobox",
82
- "aria-expanded": open,
83
- "aria-haspopup": "dialog",
84
- "aria-controls": open ? dialogId : void 0,
85
- ...fieldA11y,
86
- className: showClear ? "ui-control-inline-affix-pair-affixed" : void 0,
87
- trailingIcon: /* @__PURE__ */ jsxs("span", { className: "ui-time-picker-affix", children: [
88
- showClear ? /* @__PURE__ */ jsx(
158
+ name: resolvedName,
159
+ value: showTime ? (Array.isArray(value) ? value[0] : value)?.toISOString() ?? "" : Array.isArray(value) ? value.map(toIsoDate).join(",") : toIsoDate(value)
160
+ }
161
+ ) : null,
162
+ /* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
163
+ /* @__PURE__ */ jsx(
164
+ Input,
165
+ {
166
+ id,
167
+ name: format || showTime || multiple || needConfirm || preserveInvalidOnBlur ? "" : resolvedName,
168
+ ref,
169
+ size,
170
+ status,
171
+ variant,
172
+ readOnly: inputReadOnly || multiple,
173
+ "data-field": resolvedField,
174
+ value: text,
175
+ disabled,
176
+ placeholder: resolvedPlaceholder,
177
+ inputMode: "numeric",
178
+ autoComplete: "off",
179
+ role: "combobox",
180
+ "aria-expanded": open,
181
+ "aria-haspopup": "dialog",
182
+ "aria-controls": open ? dialogId : void 0,
183
+ ...fieldA11y,
184
+ trailingIcon: /* @__PURE__ */ jsx("span", { className: "ui-time-picker-affix", children: showClear ? /* @__PURE__ */ jsx(
89
185
  "button",
90
186
  {
91
187
  type: "button",
92
188
  tabIndex: -1,
93
- "aria-label": t("common.clear") ?? "Clear",
94
- onClick: clear,
189
+ "aria-label": clearControl.label,
190
+ onClick: (event) => {
191
+ event.stopPropagation();
192
+ event.currentTarget.closest("div")?.querySelector("input:not([type=hidden])")?.focus();
193
+ clear();
194
+ },
95
195
  className: "ui-control-inline-affix-action",
96
- children: /* @__PURE__ */ jsx(X, { className: "ui-control-inline-affix-icon", "aria-hidden": "true" })
196
+ children: clearControl.clearIcon ?? /* @__PURE__ */ jsx(X, { className: "ui-control-inline-affix-icon", "aria-hidden": "true" })
97
197
  }
98
- ) : null,
99
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
198
+ ) : /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
100
199
  "button",
101
200
  {
102
201
  type: "button",
@@ -106,64 +205,196 @@ function DatePicker({
106
205
  className: "ui-control-inline-affix-action",
107
206
  children: /* @__PURE__ */ jsx(CalendarIcon, { className: "ui-control-inline-affix-icon", "aria-hidden": "true" })
108
207
  }
109
- ) })
110
- ] }),
111
- onClick: () => {
112
- if (!disabled) setOpen(true);
113
- },
114
- onKeyDown: (event) => {
115
- if (event.key === "ArrowDown") {
116
- event.preventDefault();
117
- setOpen(true);
118
- } else if (event.key === "Escape" && open) {
119
- setOpen(false);
120
- }
121
- },
122
- onChange: (event) => {
123
- setText(event.target.value);
124
- commit(event.target.value);
125
- },
126
- onBlur: (event) => {
127
- const parsed = parseDateInput(event.target.value.trim());
128
- setText(parsed ? toIsoDate(parsed) : toIsoDate(value));
129
- }
130
- }
131
- ),
132
- /* @__PURE__ */ jsx(
133
- PopoverContent,
134
- {
135
- id: dialogId,
136
- role: "dialog",
137
- "aria-label": t("dataEntry.datePicker.openCalendar") ?? "Calendar",
138
- className: "ui-control-panel-flush",
139
- align: "start",
140
- onOpenAutoFocus: (event) => event.preventDefault(),
141
- children: /* @__PURE__ */ jsx(
142
- Calendar,
143
- {
144
- mode: "single",
145
- selected: value,
146
- defaultMonth: value,
147
- onSelect: (date) => {
148
- emit(date);
149
- setText(toIsoDate(date));
208
+ ) }) }),
209
+ onClick: () => {
210
+ if (!disabled) setOpen(true);
211
+ },
212
+ onKeyDown: (event) => {
213
+ if (event.key === "ArrowDown") {
214
+ event.preventDefault();
215
+ setOpen(true);
216
+ } else if (event.key === "Enter") {
217
+ const parsed = parse(text);
218
+ if (parsed && allowed(parsed) && timeAllowed(parsed)) {
219
+ const next = periodDate(parsed);
220
+ emit(next);
221
+ setText(display(parsed));
222
+ setOpen(false);
223
+ }
224
+ } else if (event.key === "Escape" && open) {
150
225
  setOpen(false);
151
- },
152
- locale: dayPickerLocale,
153
- disabled: [
154
- ...fromDate ? [{ before: fromDate }] : [],
155
- ...toDate ? [{ after: toDate }] : []
156
- ],
157
- startMonth: fromDate,
158
- endMonth: toDate,
159
- showToday,
160
- showClose,
161
- onClose: () => setOpen(false)
226
+ }
227
+ },
228
+ onChange: (event) => {
229
+ setText(event.target.value);
230
+ commit(event.target.value);
231
+ },
232
+ onBlur: (event) => {
233
+ const parsed = parse(event.target.value);
234
+ const accepted = parsed && allowed(parsed) && timeAllowed(parsed) ? parsed : void 0;
235
+ if (!preserveInvalidOnBlur) setText(accepted ? display(accepted) : display(value));
162
236
  }
163
- )
164
- }
165
- )
166
- ] }) }) });
237
+ }
238
+ ),
239
+ /* @__PURE__ */ jsxs(
240
+ PopoverContent,
241
+ {
242
+ id: dialogId,
243
+ role: "dialog",
244
+ "aria-label": t("dataEntry.datePicker.openCalendar") ?? "Calendar",
245
+ className: "ui-control-panel-flush",
246
+ side: placement.startsWith("top") ? "top" : "bottom",
247
+ align: placement.endsWith("end") ? "end" : "start",
248
+ onOpenAutoFocus: (event) => event.preventDefault(),
249
+ children: [
250
+ presets?.length ? /* @__PURE__ */ jsx(Flex, { wrap: true, gap: "xs", pad: "sm", children: presets.map((preset, index) => /* @__PURE__ */ jsx(
251
+ Button,
252
+ {
253
+ variant: "ghost",
254
+ size: "sm",
255
+ type: "button",
256
+ onClick: () => {
257
+ const date = typeof preset.value === "function" ? preset.value() : preset.value;
258
+ if (!allowed(date)) return;
259
+ choose(date);
260
+ if (!needConfirm && !multiple) setOpen(false);
261
+ },
262
+ children: preset.label
263
+ },
264
+ index
265
+ )) }) : null,
266
+ picker === "date" || picker === "week" ? multiple ? /* @__PURE__ */ jsx(
267
+ Calendar,
268
+ {
269
+ mode: "multiple",
270
+ selected: Array.isArray(working) ? working : [],
271
+ defaultMonth: selectedDate,
272
+ locale: dayPickerLocale,
273
+ onSelect: choose,
274
+ disabled: (day) => !allowed(day),
275
+ cellRender,
276
+ showWeekNumber: showWeek,
277
+ startMonth: minimum,
278
+ endMonth: maximum,
279
+ showToday,
280
+ showClose,
281
+ onClose: () => setOpen(false)
282
+ }
283
+ ) : /* @__PURE__ */ jsx(
284
+ Calendar,
285
+ {
286
+ mode: "single",
287
+ selected: selectedDate,
288
+ defaultMonth: selectedDate,
289
+ showWeekNumber: showWeek,
290
+ onSelect: (date) => {
291
+ if (date && showTime && selectedDate)
292
+ date.setHours(
293
+ selectedDate.getHours(),
294
+ selectedDate.getMinutes(),
295
+ selectedDate.getSeconds()
296
+ );
297
+ choose(date);
298
+ if (!needConfirm && !multiple) setOpen(false);
299
+ },
300
+ locale: dayPickerLocale,
301
+ disabled: [
302
+ ...minimum ? [{ before: minimum }] : [],
303
+ ...maximum ? [{ after: maximum }] : [],
304
+ ...disabledDate ? [disabledDate] : []
305
+ ],
306
+ cellRender,
307
+ startMonth: minimum,
308
+ endMonth: maximum,
309
+ showToday,
310
+ showClose,
311
+ onClose: () => setOpen(false)
312
+ }
313
+ ) : /* @__PURE__ */ jsxs("div", { className: "ui-month-picker-panel", children: [
314
+ /* @__PURE__ */ jsxs(Flex, { justify: "between", align: "center", children: [
315
+ /* @__PURE__ */ jsx(
316
+ Button,
317
+ {
318
+ type: "button",
319
+ variant: "ghost",
320
+ "aria-label": t("dataEntry.monthPicker.previousYear"),
321
+ onClick: () => setViewYear(viewYear - (picker === "year" ? 12 : 1)),
322
+ children: /* @__PURE__ */ jsx(ChevronLeft, { "aria-hidden": "true" })
323
+ }
324
+ ),
325
+ /* @__PURE__ */ jsx("span", { "aria-live": "polite", children: new Intl.NumberFormat(locale, { useGrouping: false }).format(viewYear) }),
326
+ /* @__PURE__ */ jsx(
327
+ Button,
328
+ {
329
+ type: "button",
330
+ variant: "ghost",
331
+ "aria-label": t("dataEntry.monthPicker.nextYear"),
332
+ onClick: () => setViewYear(viewYear + (picker === "year" ? 12 : 1)),
333
+ children: /* @__PURE__ */ jsx(ChevronRight, { "aria-hidden": "true" })
334
+ }
335
+ )
336
+ ] }),
337
+ /* @__PURE__ */ jsx("div", { className: "ui-month-picker-grid", children: Array.from({ length: picker === "quarter" ? 4 : 12 }, (_, index) => {
338
+ const date = picker === "year" ? new Date(viewYear + index, 0, 1) : new Date(viewYear, index * (picker === "quarter" ? 3 : 1), 1);
339
+ const label = picker === "year" ? new Intl.DateTimeFormat(locale, { year: "numeric" }).format(date) : picker === "quarter" ? t("dataEntry.datePicker.quarter", { quarter: index + 1 }) : new Intl.DateTimeFormat(locale, { month: "short" }).format(date);
340
+ const selected = (Array.isArray(working) ? working : working ? [working] : []).some((day) => +periodDate(day) === +date);
341
+ return /* @__PURE__ */ jsx(
342
+ Button,
343
+ {
344
+ type: "button",
345
+ variant: selected ? "default" : "ghost",
346
+ "aria-pressed": selected,
347
+ disabled: !allowed(date),
348
+ onClick: () => {
349
+ choose(date);
350
+ if (!needConfirm && !multiple) setOpen(false);
351
+ },
352
+ children: label
353
+ },
354
+ index
355
+ );
356
+ }) })
357
+ ] }),
358
+ showTime ? /* @__PURE__ */ jsx(Flex, { pad: "sm", children: /* @__PURE__ */ jsx(
359
+ TimePicker,
360
+ {
361
+ ...typeof showTime === "object" ? showTime : {},
362
+ "aria-label": t("dataEntry.timePicker.openPicker"),
363
+ value: selectedDate ? [
364
+ selectedDate.getHours(),
365
+ selectedDate.getMinutes(),
366
+ ...typeof showTime === "object" && showTime.showSeconds ? [selectedDate.getSeconds()] : []
367
+ ].map((n) => String(n).padStart(2, "0")).join(":") : "",
368
+ onValueChange: (time) => {
369
+ if (!time) return;
370
+ const date = new Date(selectedDate ?? /* @__PURE__ */ new Date());
371
+ const [h, m, sec = 0] = time.split(":").map(Number);
372
+ date.setHours(h, m, sec, 0);
373
+ choose(date);
374
+ }
375
+ }
376
+ ) }) : null,
377
+ needConfirm ? /* @__PURE__ */ jsx(Flex, { pad: "sm", justify: "end", children: /* @__PURE__ */ jsx(
378
+ Button,
379
+ {
380
+ type: "button",
381
+ disabled: !selectedDate || !allowed(selectedDate) || !timeAllowed(selectedDate),
382
+ onClick: () => {
383
+ if (selectedDate && allowed(selectedDate) && timeAllowed(selectedDate)) {
384
+ emit(working);
385
+ setText(display(working));
386
+ setOpen(false);
387
+ }
388
+ },
389
+ children: t("dataEntry.timePicker.confirm")
390
+ }
391
+ ) }) : null,
392
+ renderExtraFooter?.()
393
+ ]
394
+ }
395
+ )
396
+ ] }) })
397
+ ] });
167
398
  }
168
399
  export {
169
400
  DatePicker
@@ -8,4 +8,4 @@ export type { DateRangePickerProp, DateRangePickerProp as DateRangePickerProps,
8
8
  * `${name}_to`, screen-reader friendly, e2e-testable by filling either input); the
9
9
  * range calendar is the visual affordance.
10
10
  */
11
- export declare function DateRangePicker({ value: valueProp, defaultValue, onValueChange, placeholder, disabled, className, id, name, locale: localeProp, showToday, showClose, fromDate, toDate, allowClear, ...ariaProps }: DateRangePickerProp): React.JSX.Element;
11
+ export declare function DateRangePicker({ value: valueProp, defaultValue, onValueChange, placeholder, disabled, className, id, name, locale: localeProp, showToday, showClose, fromDate, toDate, disabledDate, cellRender, allowClear, format, parseFormat, minDate, maxDate, showWeek, presets, needConfirm, allowEmpty, order, open: openProp, defaultOpen, onOpenChange, inputReadOnly, preserveInvalidOnBlur, placement, renderExtraFooter, size, status, variant, ref, ...ariaProps }: DateRangePickerProp): React.JSX.Element;