@strapi/design-system 1.7.10 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +9 -17
  2. package/dist/Button/Button.cjs +2 -2
  3. package/dist/Button/Button.js +4 -4
  4. package/dist/Combobox/Combobox.cjs +14 -13
  5. package/dist/Combobox/Combobox.js +73 -68
  6. package/dist/DatePicker/DatePicker.cjs +82 -6
  7. package/dist/DatePicker/DatePicker.js +414 -55
  8. package/dist/DateTimePicker/DateTimePicker.cjs +7 -1
  9. package/dist/DateTimePicker/DateTimePicker.js +97 -53
  10. package/dist/DateTimePicker/index.cjs +1 -1
  11. package/dist/DateTimePicker/index.js +3 -2
  12. package/dist/DesignSystemProvider.cjs +1 -0
  13. package/dist/DesignSystemProvider.js +10 -0
  14. package/dist/Grid/Grid.cjs +3 -3
  15. package/dist/Grid/Grid.js +6 -3
  16. package/dist/MainNav/MainNav.cjs +2 -2
  17. package/dist/MainNav/MainNav.js +9 -31
  18. package/dist/MainNav/MainNavContext.cjs +1 -1
  19. package/dist/MainNav/MainNavContext.js +1 -1
  20. package/dist/MainNav/NavBrand.cjs +3 -3
  21. package/dist/MainNav/NavBrand.js +12 -38
  22. package/dist/MainNav/NavCondense.cjs +2 -2
  23. package/dist/MainNav/NavCondense.js +15 -23
  24. package/dist/MainNav/NavFooter.cjs +1 -1
  25. package/dist/MainNav/NavFooter.js +4 -10
  26. package/dist/MainNav/NavLink.cjs +9 -9
  27. package/dist/MainNav/NavLink.js +13 -35
  28. package/dist/MainNav/NavSection.cjs +1 -1
  29. package/dist/MainNav/NavSection.js +9 -43
  30. package/dist/MainNav/NavSections.cjs +2 -2
  31. package/dist/MainNav/NavSections.js +7 -21
  32. package/dist/MainNav/NavUser.cjs +2 -2
  33. package/dist/MainNav/NavUser.js +13 -27
  34. package/dist/NumberInput/NumberInput.cjs +2 -2
  35. package/dist/NumberInput/NumberInput.js +40 -40
  36. package/dist/Popover/Popover.cjs +3 -4
  37. package/dist/Popover/Popover.js +46 -48
  38. package/dist/Popover/index.cjs +1 -1
  39. package/dist/Popover/index.js +5 -9
  40. package/dist/Popover/primitives.cjs +1 -0
  41. package/dist/Popover/primitives.js +5 -0
  42. package/dist/Searchbar/Searchbar.cjs +2 -2
  43. package/dist/Searchbar/Searchbar.js +5 -5
  44. package/dist/Select/SelectParts.cjs +1 -1
  45. package/dist/Select/SelectParts.js +1 -1
  46. package/dist/Select/SingleSelect.cjs +1 -1
  47. package/dist/Select/SingleSelect.js +36 -32
  48. package/dist/SimpleMenu/SimpleMenu.cjs +9 -9
  49. package/dist/SimpleMenu/SimpleMenu.js +62 -151
  50. package/dist/SubNav/SubNav.cjs +5 -5
  51. package/dist/SubNav/SubNav.js +8 -13
  52. package/dist/SubNav/SubNavHeader.cjs +3 -3
  53. package/dist/SubNav/SubNavHeader.js +29 -76
  54. package/dist/SubNav/SubNavLink.cjs +13 -13
  55. package/dist/SubNav/SubNavLink.js +20 -52
  56. package/dist/SubNav/SubNavLinkSection.cjs +4 -4
  57. package/dist/SubNav/SubNavLinkSection.js +19 -35
  58. package/dist/SubNav/SubNavSection.cjs +2 -2
  59. package/dist/SubNav/SubNavSection.js +15 -55
  60. package/dist/SubNav/SubNavSectionLabel.cjs +3 -3
  61. package/dist/SubNav/SubNavSectionLabel.js +10 -38
  62. package/dist/SubNav/SubNavSections.cjs +1 -1
  63. package/dist/SubNav/SubNavSections.js +4 -18
  64. package/dist/TextInput/TextInput.cjs +1 -1
  65. package/dist/TextInput/TextInput.js +5 -5
  66. package/dist/ThemeProvider/ThemeProvider.cjs +2 -2
  67. package/dist/ThemeProvider/ThemeProvider.js +4 -3
  68. package/dist/TimePicker/TimePicker.cjs +5 -7
  69. package/dist/TimePicker/TimePicker.js +79 -33
  70. package/dist/TimePicker/index.cjs +1 -1
  71. package/dist/TimePicker/index.js +3 -2
  72. package/dist/helpers/context.cjs +1 -0
  73. package/dist/helpers/context.js +21 -0
  74. package/dist/helpers/getDefaultLocale.cjs +4 -1
  75. package/dist/helpers/getDefaultLocale.js +7 -2
  76. package/dist/hooks/useDateFormatter.cjs +1 -0
  77. package/dist/hooks/useDateFormatter.js +20 -0
  78. package/dist/index.cjs +1 -1
  79. package/dist/index.js +309 -304
  80. package/dist/v2/Breadcrumbs/Breadcrumbs.cjs +2 -2
  81. package/dist/v2/Breadcrumbs/Breadcrumbs.js +15 -23
  82. package/dist/v2/Breadcrumbs/Crumb.cjs +1 -1
  83. package/dist/v2/Breadcrumbs/Crumb.js +6 -25
  84. package/dist/v2/Breadcrumbs/CrumbLink.cjs +2 -2
  85. package/dist/v2/Breadcrumbs/CrumbLink.js +6 -15
  86. package/dist/v2/Breadcrumbs/CrumbSimpleMenu.cjs +4 -3
  87. package/dist/v2/Breadcrumbs/CrumbSimpleMenu.js +8 -14
  88. package/dist/v2/Breadcrumbs/Divider.cjs +1 -1
  89. package/dist/v2/Breadcrumbs/Divider.js +3 -4
  90. package/dist/v2/SimpleMenu/Menu.cjs +10 -10
  91. package/dist/v2/SimpleMenu/Menu.js +11 -11
  92. package/package.json +11 -10
  93. package/dist/DatePicker/DatePickerCalendar.cjs +0 -1
  94. package/dist/DatePicker/DatePickerCalendar.js +0 -43
  95. package/dist/DatePicker/DatePickerTd.cjs +0 -19
  96. package/dist/DatePicker/DatePickerTd.js +0 -29
  97. package/dist/DatePicker/DatePickerTh.cjs +0 -9
  98. package/dist/DatePicker/DatePickerTh.js +0 -18
  99. package/dist/DatePicker/compareDates.cjs +0 -1
  100. package/dist/DatePicker/compareDates.js +0 -4
  101. package/dist/DatePicker/components.cjs +0 -39
  102. package/dist/DatePicker/components.js +0 -53
  103. package/dist/DatePicker/utils/formatDate.cjs +0 -1
  104. package/dist/DatePicker/utils/formatDate.js +0 -4
  105. package/dist/DatePicker/utils/generateWeeks.cjs +0 -1
  106. package/dist/DatePicker/utils/generateWeeks.js +0 -17
  107. package/dist/DatePicker/utils/getDayOfWeek.cjs +0 -1
  108. package/dist/DatePicker/utils/getDayOfWeek.js +0 -15
  109. package/dist/DatePicker/utils/getMonths.cjs +0 -1
  110. package/dist/DatePicker/utils/getMonths.js +0 -7
  111. package/dist/DatePicker/utils/getYears.cjs +0 -1
  112. package/dist/DatePicker/utils/getYears.js +0 -9
  113. package/dist/DatePicker/utils/index.cjs +0 -1
  114. package/dist/DatePicker/utils/index.js +0 -12
  115. package/dist/DateTimePicker/parseDate.cjs +0 -1
  116. package/dist/DateTimePicker/parseDate.js +0 -8
@@ -1,71 +1,430 @@
1
- import { jsxs as R, jsx as r } from "react/jsx-runtime";
2
- import { useState as S, useRef as W } from "react";
3
- import { Cross as $, Calendar as v } from "@strapi/icons";
4
- import m from "styled-components";
5
- import { DatePickerWrapper as A } from "./components.js";
6
- import { DatePickerCalendar as P } from "./DatePickerCalendar.js";
7
- import { formatDate as j } from "./utils/formatDate.js";
8
- import { getDefaultLocale as E } from "../helpers/getDefaultLocale.js";
9
- import { TextInput as I } from "../TextInput/TextInput.js";
10
- import { FieldAction as V } from "../Field/FieldAction.js";
11
- const N = ({
1
+ import { jsxs as F, jsx as i } from "react/jsx-runtime";
2
+ import * as c from "react";
3
+ import { useFloating as be, offset as we, shift as xe, flip as ke, autoUpdate as Te } from "@floating-ui/react-dom";
4
+ import { getLocalTimeZone as Ee, today as J, minDate as H, maxDate as X, startOfMonth as Pe, startOfWeek as le, getDayOfWeek as Ie, isSameDay as se, endOfMonth as Ae, parseAbsolute as Re, toCalendarDate as Se } from "@internationalized/date";
5
+ import { useFocusGuards as Me } from "@radix-ui/react-focus-guards";
6
+ import { FocusScope as ve } from "@radix-ui/react-focus-scope";
7
+ import { Cross as $e, Calendar as Fe } from "@strapi/icons";
8
+ import { composeEventHandlers as L } from "@strapi/ui-primitives";
9
+ import { createPortal as Le } from "react-dom";
10
+ import { RemoveScroll as Ne } from "react-remove-scroll";
11
+ import I from "styled-components";
12
+ import { useDesignSystem as Oe } from "../DesignSystemProvider.js";
13
+ import { DismissibleLayer as _e } from "../DismissibleLayer/index.js";
14
+ import { createContext as Ve } from "../helpers/context.js";
15
+ import { once as Ye } from "../helpers/deprecations.js";
16
+ import { useComposedRefs as Q } from "../hooks/useComposeRefs.js";
17
+ import { useControllableState as ze } from "../hooks/useControllableState.js";
18
+ import { useDateFormatter as S } from "../hooks/useDateFormatter.js";
19
+ import { useId as ce } from "../hooks/useId.js";
20
+ import { SingleSelectInput as ne, SingleSelectOption as ae } from "../Select/SingleSelect.js";
21
+ import { Portal as Ue } from "../Portal/Portal.js";
22
+ import { Flex as U } from "../Flex/Flex.js";
23
+ import { getThemeSize as We, inputFocusStyle as Be } from "../themes/utils.js";
24
+ import { Box as W } from "../Box/Box.js";
25
+ import { Typography as B } from "../Typography/Typography.js";
26
+ import { Field as Ze } from "../Field/Field.js";
27
+ import { FieldLabel as qe } from "../Field/FieldLabel.js";
28
+ import { FieldHint as Ke } from "../Field/FieldHint.js";
29
+ import { FieldError as Ge } from "../Field/FieldError.js";
30
+ const je = 200, oe = 15, [He, N] = Ve("DatePicker"), Xe = c.forwardRef(({
12
31
  /**
13
- * DatePicker props
32
+ * DatePickerCalendar props
14
33
  */
15
- ariaLabel: e,
16
- onClear: a,
17
- clearLabel: u = "Clear",
34
+ calendarLabel: e,
35
+ className: r,
36
+ initialDate: n,
37
+ locale: t,
38
+ maxDate: a,
39
+ minDate: s,
40
+ monthSelectLabel: g = "Month",
41
+ onChange: u,
42
+ selectedDate: l,
43
+ yearSelectLabel: b = "Year",
18
44
  /**
19
- * DatePickerCalendar props
45
+ * Combobox props
46
+ */
47
+ error: x,
48
+ id: y,
49
+ disabled: m = !1,
50
+ placeholder: k,
51
+ required: w = !1,
52
+ onClear: E,
53
+ clearLabel: P = "Clear",
54
+ size: d,
55
+ /**
56
+ * @preserve
57
+ * @deprecated This is no longer used.
20
58
  */
21
- initialDate: d,
22
- locale: h,
23
- maxDate: C,
24
- minDate: D,
25
- onChange: c,
26
- selectedDate: n,
59
+ ariaLabel: h,
27
60
  /**
28
- * TextInput props
61
+ * @preserve
62
+ * @deprecated This is no longer used.
29
63
  */
30
- disabled: o = !1,
31
- ...g
32
- }) => {
33
- const [s, i] = S(!1), t = W(null), f = h || E(), p = n ? j(n, f) : "", x = () => {
34
- o || i((l) => !l);
35
- }, b = () => {
36
- o || a && (a(), t.current.inputWrapperRef.current.focus());
37
- }, k = (l) => {
38
- c && c(l), i(!1);
39
- }, y = () => {
40
- i(!1);
64
+ selectedDateLabel: o,
65
+ ...f
66
+ }, p) => {
67
+ const T = Ee(), M = Oe("DatePicker"), v = t ?? M.locale, $ = S(v, {
68
+ day: "2-digit",
69
+ month: "2-digit",
70
+ year: "numeric"
71
+ }), [O, Z] = c.useState(!1), [q, C] = c.useState(null), [A, K] = c.useState(null), [ue, me] = c.useState(null), [Y, _] = c.useState(), [V, ee] = ze({
72
+ defaultProp: n ? R(n) : void 0,
73
+ prop: l ? R(l) : void 0,
74
+ onChange(D) {
75
+ u && u(D?.toDate(T));
76
+ }
77
+ }), [te, re] = c.useMemo(() => {
78
+ const D = n ? R(n) : J("UTC"), z = s ? R(s) : D.set({ day: 1, month: 1, year: D.year - je });
79
+ let j = a ? R(a) : D.set({ day: 31, month: 12, year: D.year + oe });
80
+ return j.compare(z) < 0 && (j = z.set({ day: 31, month: 12, year: z.year + oe })), [z, j];
81
+ }, [s, a, n]), [fe, G] = c.useState(Je({
82
+ currentValue: V,
83
+ minDate: te,
84
+ maxDate: re
85
+ })), pe = ce(), he = c.useRef(null), ge = (D) => {
86
+ E && !m && (_(""), ee(void 0), E(D), A?.focus());
87
+ }, De = c.useCallback((D) => {
88
+ D && V && G(V), Z(D);
89
+ }, [V]);
90
+ c.useLayoutEffect(() => {
91
+ if (l) {
92
+ const D = R(l);
93
+ _($.format(D.toDate(T))), G(D);
94
+ } else
95
+ _("");
96
+ }, [l, $, T]), c.useLayoutEffect(() => {
97
+ if (n && Y === void 0) {
98
+ const D = R(n);
99
+ _($.format(D.toDate(T)));
100
+ }
101
+ }, [n, Y, $, T]);
102
+ const ye = `${y}-hint`, Ce = `${y}-error`;
103
+ return F(He, { calendarDate: fe, content: ue, contentId: pe, disabled: m, locale: v, minDate: te, maxDate: re, open: O, onCalendarDateChange: G, onContentChange: me, onOpenChange: De, onTextInputChange: K, onTextValueChange: _, onTriggerChange: C, onValueChange: ee, required: w, textInput: A, textValue: Y, timeZone: T, trigger: q, value: V, children: [F(et, { className: r, size: d, hasError: !!x, children: [i(nt, { "aria-hidden": !0 }), i(ot, { ref: p, placeholder: k, "aria-describedby": `${ye} ${Ce}`, id: y, ...f }), Y && E ? i(rt, { as: "button", hasRadius: !0, background: "transparent", type: "button", onClick: ge, "aria-disabled": m, "aria-label": P, title: P, ref: he, children: i($e, {}) }) : null] }), i(Ue, { children: i(ct, { label: e, children: i(pt, { monthSelectLabel: g, yearSelectLabel: b }) }) })] });
104
+ }), ie = (e) => !!e.match(/^[^a-zA-Z]*$/), Je = ({ currentValue: e, minDate: r, maxDate: n }) => {
105
+ const t = J("UTC");
106
+ return e || (H(r, t) === r && X(n, t) === n ? t : H(r, t) === t ? r : X(n, t) === t ? n : t);
107
+ }, Qe = "DatePickerTrigger", et = c.forwardRef(({ hasError: e, size: r = "M", ...n }, t) => {
108
+ const a = N(Qe), s = Q(t, (u) => a.onTriggerChange(u)), g = () => {
109
+ a.disabled || a.onOpenChange(!0);
41
110
  };
42
- return R(A, { bold: s, children: [r(I, {
43
- ref: t,
44
- onClick: x,
45
- // Prevent input from changing for now
46
- onChange: () => {
111
+ return i(ve, {
112
+ asChild: !0,
113
+ // we make sure we're not trapping once it's been closed
114
+ // (closed !== unmounted when animating out)
115
+ trapped: a.open,
116
+ onMountAutoFocus: (u) => {
117
+ u.preventDefault();
47
118
  },
48
- value: p,
49
- startAction: r(F, { "aria-hidden": !0 }),
50
- endAction: a && p ? r(V, { label: u, onClick: b, "aria-disabled": o || void 0, children: r(w, {}) }) : void 0,
51
- "aria-autocomplete": "none",
52
- "aria-label": e,
53
- disabled: o,
54
- type: "text",
55
- ...g
56
- }), t.current && t.current.inputWrapperRef && s && r(P, { selectedDate: n, initialDate: d, onChange: k, onEscape: y, locale: f, popoverSource: t.current.inputWrapperRef, minDate: D, maxDate: C })] });
57
- }, w = m($)`
58
- height: ${11 / 16}rem;
59
- width: ${11 / 16}rem;
119
+ onUnmountAutoFocus: (u) => {
120
+ document.getSelection()?.empty(), u.preventDefault();
121
+ },
122
+ children: i(tt, { ref: s, $hasError: e, $size: r, ...n, paddingLeft: 3, paddingRight: 3, hasRadius: !0, gap: 3, overflow: "hidden", background: a.disabled ? "neutral150" : "neutral0", onClick: L(n.onClick, () => {
123
+ a.textInput?.focus();
124
+ }), onPointerDown: L(n.onPointerDown, (u) => {
125
+ const l = u.target;
126
+ l.hasPointerCapture(u.pointerId) && l.releasePointerCapture(u.pointerId), (l.closest("button") ?? l.closest("div")) === u.currentTarget && u.button === 0 && u.ctrlKey === !1 && (g(), a.textInput?.focus());
127
+ }) })
128
+ });
129
+ }), tt = I(U)`
130
+ border: 1px solid ${({ theme: e, $hasError: r }) => r ? e.colors.danger600 : e.colors.neutral200};
131
+ min-height: ${({ theme: e, $size: r }) => We("input")({ theme: e, size: r })};
132
+
133
+ &[data-disabled] {
134
+ color: ${({ theme: e }) => e.colors.neutral600};
135
+ background: ${({ theme: e }) => e.colors.neutral150};
136
+ cursor: not-allowed;
137
+ }
60
138
 
61
- path {
139
+ /* Required to ensure the below inputFocusStyles are adhered too */
140
+ &:focus-visible {
141
+ outline: none;
142
+ }
143
+
144
+ ${({ theme: e, $hasError: r }) => Be()({ theme: e, hasError: r })};
145
+ `, rt = I(W)`
146
+ border: none;
147
+
148
+ svg {
149
+ height: ${11 / 16}rem;
150
+ width: ${11 / 16}rem;
151
+ }
152
+
153
+ svg path {
62
154
  fill: ${({ theme: e }) => e.colors.neutral600};
63
155
  }
64
- `, F = m(v)`
156
+ `, nt = I(Fe)`
65
157
  & > path {
66
158
  fill: ${({ theme: e }) => e.colors.neutral500};
67
159
  }
68
- `;
160
+ `, at = "DatePickerTextInput", ot = c.forwardRef(({ placeholder: e, ...r }, n) => {
161
+ const t = N(at), { onTextValueChange: a, textValue: s, onTextInputChange: g, onOpenChange: u, disabled: l, locale: b } = t, x = Q(n, (d) => g(d)), y = () => {
162
+ l || u(!0);
163
+ }, m = S(b, {
164
+ year: "numeric",
165
+ month: "2-digit",
166
+ day: "2-digit"
167
+ }), [k, w, E] = c.useMemo(() => {
168
+ const d = m.formatToParts(/* @__PURE__ */ new Date()), h = d.filter((p) => p.type === "year" || p.type === "month" || p.type === "day"), o = h.map((p) => {
169
+ switch (p.type) {
170
+ case "day":
171
+ return "DD";
172
+ case "month":
173
+ return "MM";
174
+ case "year":
175
+ return "YYYY";
176
+ default:
177
+ return "";
178
+ }
179
+ }), f = d.find((p) => p.type === "literal")?.value ?? "";
180
+ return [o, f, h];
181
+ }, [m]), P = k.map((d) => `\\d${d.length}`).join(w);
182
+ return i(lt, { role: "combobox", type: "text", inputMode: "numeric", ref: x, "aria-autocomplete": "none", "aria-controls": t.contentId, "aria-disabled": t.disabled, "aria-expanded": t.open, "aria-required": t.required, "aria-haspopup": "dialog", "data-state": t.open ? "open" : "closed", disabled: l, "data-disabled": l ? "" : void 0, pattern: P, placeholder: e ?? k.join(w), ...r, value: s ?? "", onBlur: L(r.onBlur, () => {
183
+ if (!t.textValue) {
184
+ t.onValueChange(void 0);
185
+ return;
186
+ }
187
+ t.onTextValueChange(m.format(t.calendarDate.toDate(t.timeZone))), t.onValueChange(t.calendarDate);
188
+ }), onChange: L(r.onChange, (d) => {
189
+ if (ie(d.target.value)) {
190
+ const h = d.target.value.split(w), [o, f, p] = E.map((C, A) => {
191
+ const K = h[A];
192
+ return {
193
+ ...C,
194
+ value: K
195
+ };
196
+ }).sort((C, A) => C.type === "year" ? 1 : A.type === "year" ? -1 : C.type === "month" ? 1 : A.type === "month" ? -1 : 0).map((C) => C.value), T = t.calendarDate.year;
197
+ let M = t.calendarDate.year;
198
+ if (p) {
199
+ let C = p.length === 1 ? `0${p}` : p;
200
+ M = p.length < 3 ? Number(`${T}`.slice(0, 4 - C.length) + C) : Number(C);
201
+ }
202
+ p && p.length < 3 && M > t.maxDate.year && (M -= 100);
203
+ const v = t.calendarDate.set({ year: M }), $ = v.calendar.getMonthsInYear(v), O = v.set({
204
+ month: f && Number(f) <= $ ? Number(f) : void 0
205
+ }), Z = O.calendar.getDaysInMonth(O), q = O.set({
206
+ day: o && Number(o) <= Z ? Number(o) : void 0
207
+ });
208
+ t.onCalendarDateChange(it(q, t.minDate, t.maxDate)), t.onTextValueChange(d.target.value);
209
+ }
210
+ }), onKeyDown: L(r.onKeyDown, (d) => {
211
+ if (!t.open && (ie(d.key) || ["ArrowDown", "Backspace"].includes(d.key)))
212
+ y();
213
+ else if (["Tab"].includes(d.key) && t.open)
214
+ d.preventDefault();
215
+ else if (["Escape"].includes(d.key))
216
+ t.open ? t.onOpenChange(!1) : (t.onValueChange(void 0), t.onTextValueChange("")), d.preventDefault();
217
+ else if (t.open && ["ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"].includes(d.key))
218
+ switch (d.preventDefault(), d.key) {
219
+ case "ArrowDown": {
220
+ const h = t.calendarDate.add({ weeks: 1 });
221
+ if (t.maxDate && h.compare(t.maxDate) > 0)
222
+ return;
223
+ t.onCalendarDateChange(h);
224
+ return;
225
+ }
226
+ case "ArrowRight": {
227
+ const h = t.calendarDate.add({ days: 1 });
228
+ if (t.maxDate && h.compare(t.maxDate) > 0)
229
+ return;
230
+ t.onCalendarDateChange(h);
231
+ return;
232
+ }
233
+ case "ArrowUp": {
234
+ const h = t.calendarDate.subtract({ weeks: 1 });
235
+ if (t.minDate && h.compare(t.minDate) < 0)
236
+ return;
237
+ t.onCalendarDateChange(h);
238
+ return;
239
+ }
240
+ case "ArrowLeft": {
241
+ const h = t.calendarDate.subtract({ days: 1 });
242
+ if (t.minDate && h.compare(t.minDate) < 0)
243
+ return;
244
+ t.onCalendarDateChange(h);
245
+ }
246
+ }
247
+ else
248
+ t.open && ["Enter"].includes(d.key) && (d.preventDefault(), a(m.format(t.calendarDate.toDate(t.timeZone))), t.onValueChange(t.calendarDate), t.onOpenChange(!1));
249
+ }) });
250
+ });
251
+ function it(e, r, n) {
252
+ return r && (e = X(e, r)), n && (e = H(e, n)), e;
253
+ }
254
+ const lt = I.input`
255
+ width: 100%;
256
+ font-size: ${14 / 16}rem;
257
+ color: ${({ theme: e }) => e.colors.neutral800};
258
+ height: 100%;
259
+ border: none;
260
+ background-color: transparent;
261
+
262
+ &:focus-visible {
263
+ outline: none;
264
+ }
265
+
266
+ &[aria-disabled='true'] {
267
+ cursor: inherit;
268
+ }
269
+ `, st = "DatePickerContent", ct = c.forwardRef((e, r) => {
270
+ const [n, t] = c.useState(), a = N(st);
271
+ if (c.useLayoutEffect(() => {
272
+ t(new DocumentFragment());
273
+ }, []), !a.open) {
274
+ const s = n;
275
+ return s ? Le(i("div", { children: e.children }), s) : null;
276
+ }
277
+ return i(ut, { ...e, ref: r });
278
+ }), dt = "DatePickerContent", ut = c.forwardRef((e, r) => {
279
+ const { label: n = "Choose date", ...t } = e, { onOpenChange: a, ...s } = N(dt), { x: g, y: u, reference: l, floating: b, strategy: x } = be({
280
+ strategy: "fixed",
281
+ placement: "bottom-start",
282
+ middleware: [
283
+ we({
284
+ mainAxis: 4
285
+ }),
286
+ xe(),
287
+ ke()
288
+ ],
289
+ whileElementsMounted: Te
290
+ });
291
+ c.useEffect(() => {
292
+ const m = () => {
293
+ a(!1);
294
+ };
295
+ return window.addEventListener("blur", m), window.addEventListener("resize", m), () => {
296
+ window.removeEventListener("blur", m), window.removeEventListener("resize", m);
297
+ };
298
+ }, [a]), c.useLayoutEffect(() => {
299
+ l(s.trigger);
300
+ }, [l, s.trigger]);
301
+ const y = Q(r, (m) => s.onContentChange(m), b);
302
+ return Me(), i(Ne, { allowPinchZoom: !0, children: i(_e, {
303
+ asChild: !0,
304
+ // When focus is trapped, a focusout event may still happen.
305
+ // We make sure we don't trigger our `onDismiss` in such case.
306
+ onFocusOutside: (m) => {
307
+ m.preventDefault();
308
+ },
309
+ onDismiss: () => {
310
+ a(!1);
311
+ },
312
+ children: i(mt, { ref: y, "data-state": s.open ? "open" : "closed", onContextMenu: (m) => m.preventDefault(), id: s.contentId, role: "dialog", "aria-modal": "true", "aria-label": n, style: {
313
+ left: g,
314
+ top: u,
315
+ position: x
316
+ }, hasRadius: !0, background: "neutral0", padding: 1, ...t })
317
+ }) });
318
+ }), mt = I(W)`
319
+ box-shadow: ${({ theme: e }) => e.shadows.filterShadow};
320
+ z-index: ${({ theme: e }) => e.zIndices[0]};
321
+ border: 1px solid ${({ theme: e }) => e.colors.neutral150};
322
+ `, ft = "DatePickerCalendar", pt = c.forwardRef(({ monthSelectLabel: e, yearSelectLabel: r, ...n }, t) => {
323
+ const { locale: a, timeZone: s, minDate: g, maxDate: u, calendarDate: l, onCalendarDateChange: b } = N(ft), x = Pe(l), y = c.useMemo(() => {
324
+ const o = g.year, f = u.year;
325
+ return [...Array(f - o + 1).keys()].map((p) => (o + p).toString());
326
+ }, [g, u]), m = S(a, { month: "long" }), k = c.useMemo(() => [...Array(l.calendar.getMonthsInYear(l)).keys()].map((o) => m.format(l.set({ month: o + 1 }).toDate(s))), [l, m, s]), w = S(a, { weekday: "short" }), E = c.useMemo(() => {
327
+ let o = le(J(s), a);
328
+ return [...new Array(7).keys()].map((f) => {
329
+ let T = o.add({ days: f }).toDate(s);
330
+ return w.format(T);
331
+ });
332
+ }, [s, a, w]), P = (o) => {
333
+ if (typeof o == "number")
334
+ return;
335
+ const f = l.set({ month: k.indexOf(o) + 1 });
336
+ b(f);
337
+ }, d = (o) => {
338
+ if (typeof o == "number")
339
+ return;
340
+ const f = l.set({ year: parseInt(o, 10) });
341
+ b(f);
342
+ }, h = ht(x, a);
343
+ return F(U, { ref: t, direction: "column", alignItems: "stretch", padding: 4, ...n, children: [F(gt, { justifyContent: "flex-start", paddingBottom: 4, paddingLeft: 2, paddingRight: 2, gap: 2, children: [i(ne, { label: e, size: "S", value: k[l.month - 1], onChange: P, children: k.map((o) => i(ae, { value: o, children: o }, o)) }), i(ne, { size: "S", value: l.year.toString(), label: r, onChange: d, children: y.map((o) => i(ae, { value: o, children: o }, o)) })] }), F("table", { role: "grid", children: [i("thead", { "aria-hidden": !0, children: i("tr", { "aria-rowindex": 0, children: E.map((o, f) => i(Dt, { "aria-colindex": f, children: o }, o)) }) }), i("tbody", { children: [...new Array(6).keys()].map((o) => i("tr", { "aria-rowindex": o + 2, children: h(o).map((f, p) => f ? i(bt, { "aria-colindex": p + 1, date: f, startDate: x }, f.toString()) : i(de, { "aria-colindex": p + 1 })) }, o)) })] })] });
344
+ }), ht = (e, r) => (n) => {
345
+ let t = e.add({ weeks: n }), a = [];
346
+ t = le(t, r);
347
+ let s = Ie(t, r);
348
+ for (let g = 0; g < s; g++)
349
+ a.push(null);
350
+ for (; a.length < 7; ) {
351
+ a.push(t);
352
+ let g = t.add({ days: 1 });
353
+ if (se(t, g))
354
+ break;
355
+ t = g;
356
+ }
357
+ for (; a.length < 7; )
358
+ a.push(null);
359
+ return a;
360
+ }, gt = I(U)`
361
+ div[role='combobox'] {
362
+ border: 1px solid transparent;
363
+ background: transparent;
364
+ font-weight: ${(e) => e.theme.fontWeights.bold};
365
+
366
+ ${B} {
367
+ color: ${({ theme: e }) => e.colors.neutral800};
368
+ }
369
+
370
+ svg {
371
+ > g,
372
+ path {
373
+ fill: ${({ theme: e }) => e.colors.neutral500};
374
+ }
375
+ }
376
+
377
+ &:hover {
378
+ background-color: ${({ theme: e }) => e.colors.neutral100};
379
+ }
380
+ }
381
+ `, Dt = c.forwardRef(({ children: e, ...r }, n) => i(yt, { as: "th", role: "gridcell", ref: n, ...r, height: `${24 / 16}rem`, width: `${32 / 16}rem`, children: i(B, { variant: "pi", fontWeight: "bold", color: "neutral800", children: e.slice(0, 2) }) })), yt = I(W)`
382
+ border-radius: ${({ theme: e }) => e.borderRadius};
383
+ text-transform: capitalize;
384
+ `, Ct = "DatePickerCalendarCell", bt = c.forwardRef(({ date: e, startDate: r, ...n }, t) => {
385
+ const { timeZone: a, locale: s, calendarDate: g, onValueChange: u, onOpenChange: l, onTextValueChange: b, onCalendarDateChange: x } = N(Ct), y = se(g, e), m = S(s, {
386
+ weekday: "long",
387
+ day: "numeric",
388
+ month: "long",
389
+ year: "numeric"
390
+ }), k = c.useMemo(() => m.format(e.toDate(a)), [m, e, a]), w = S(s, {
391
+ day: "numeric",
392
+ calendar: e.calendar.identifier
393
+ }), E = c.useMemo(() => w.formatToParts(e.toDate(a)).find((f) => f.type === "day").value, [w, e, a]), P = S(s, {
394
+ day: "2-digit",
395
+ month: "2-digit",
396
+ year: "numeric"
397
+ }), d = Ae(r), h = e.compare(r) < 0 || e.compare(d) > 0;
398
+ let o = "neutral900";
399
+ return y ? o = "primary600" : h && (o = "neutral600"), i(de, { as: "td", role: "gridcell", ref: t, "aria-selected": y, ...n, hasRadius: !0, "aria-label": k, tabIndex: y ? 0 : -1, background: y ? "primary100" : "neutral0", cursor: "pointer", onPointerDown: L(n.onPointerDown, (f) => {
400
+ f.preventDefault(), x(e), u(e), b(P.format(e.toDate(a))), l(!1);
401
+ }), children: i(B, { variant: "pi", textColor: o, children: E }) });
402
+ }), de = I(W)`
403
+ text-align: center;
404
+ padding: ${7 / 16}rem;
405
+ // Trick to prevent the outline from overflowing because of the general outline-offset
406
+ outline-offset: -2px !important;
407
+
408
+ &:hover {
409
+ background: ${({ theme: e }) => e.colors.primary100};
410
+
411
+ & > ${B} {
412
+ color: ${({ theme: e }) => e.colors.primary600};
413
+ }
414
+ }
415
+ `, wt = c.forwardRef((e, r) => {
416
+ const { error: n, hint: t, id: a, required: s, label: g, ...u } = e, l = ce(a);
417
+ return i(Ze, { error: n, hint: t, required: s, ref: r, id: l, children: F(U, { direction: "column", alignItems: "stretch", gap: 1, children: [i(qe, { children: g }), i(Xe, { id: l, error: n, required: s, ...u }), i(Ke, {}), i(Ge, {})] }) });
418
+ }), xt = Ye(console.warn), R = (e) => {
419
+ if (typeof e == "string") {
420
+ xt("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");
421
+ const t = Date.parse(e);
422
+ Number.isNaN(t) ? e = /* @__PURE__ */ new Date() : e = new Date(t);
423
+ }
424
+ const r = e.toISOString(), n = Re(r, "UTC");
425
+ return Se(n);
426
+ }, Xt = wt;
69
427
  export {
70
- N as DatePicker
428
+ Xt as DatePicker,
429
+ Xe as DatePickerInput
71
430
  };
@@ -1 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),$=require("../hooks/useControllableState.cjs"),w=require("../hooks/useId.cjs"),L=require("../DatePicker/DatePicker.cjs"),N=require("../TimePicker/TimePicker.cjs"),V=require("../Field/Field.cjs"),f=require("../Flex/Flex.cjs"),v=require("../Field/FieldLabel.cjs"),E=require("../Field/FieldHint.cjs"),z=require("../Field/FieldError.cjs"),B=({ariaLabel:a,clearLabel:s="clear",disabled:m=!1,error:c,hint:u,id:x,label:d,labelAction:b,onChange:q,onClear:D,name:F,required:p=!1,selectButtonTitle:j="select",size:h="M",step:T=1,value:C,...I})=>{const k=O(C),[t,o]=$.useControllableState({prop:k,onChange:q}),r=t?`${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}`:void 0,y=e=>{if(r){const[i,g]=r.split(":");e.setHours(parseInt(i,10)),e.setMinutes(parseInt(g,10))}o(e)},P=e=>{const i=t?new Date(t):new Date,[g,M]=e.split(":");i.setHours(parseInt(g,10)),i.setMinutes(parseInt(M,10)),o(i)},S=()=>{o(void 0),D&&D()},H=()=>{let e=t?new Date(t):new Date;e.setHours(0),e.setMinutes(0),o(e)},l=w.useId(x);return n.jsx(V.Field,{name:F,role:"group",id:l,"aria-labelledby":l,hint:u,error:c,required:p,children:n.jsxs(f.Flex,{direction:"column",alignItems:"stretch",gap:1,children:[n.jsx(v.FieldLabel,{action:b,children:d}),n.jsxs(f.Flex,{gap:2,children:[n.jsx(L.DatePicker,{ariaLabel:d||a,selectedDate:t,selectedDateLabel:e=>`Date picker, current is ${e}`,onChange:y,error:typeof c=="string",hint:typeof u=="string",required:p,size:h,onClear:S,clearLabel:`${s} date`,disabled:m,id:l,...I}),n.jsx(N.TimePicker,{size:h,"aria-label":d||a,error:typeof c=="string",hint:typeof u=="string",value:r,onChange:P,onClear:r!==void 0&&r!=="0:0:0"?H:void 0,clearLabel:`${s} time`,required:p,selectButtonTitle:j,disabled:m,step:T,id:l})]}),n.jsx(E.FieldHint,{}),n.jsx(z.FieldError,{})]})})},O=a=>{const s=Date.parse(a);if(!Number.isNaN(s))return new Date(s)};exports.DateTimePicker=B;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),E=require("react"),d=require("@internationalized/date"),U=require("styled-components"),A=require("../DatePicker/DatePicker.cjs"),G=require("../DesignSystemProvider.cjs"),J=require("../helpers/deprecations.cjs"),K=require("../hooks/useControllableState.cjs"),Q=require("../hooks/useDateFormatter.cjs"),x=require("../hooks/useId.cjs"),W=require("../TimePicker/TimePicker.cjs"),X=require("../Field/Field.cjs"),P=require("../Flex/Flex.cjs"),Y=require("../Field/FieldLabel.cjs"),j=require("../VisuallyHidden/VisuallyHidden.cjs"),ee=require("../Field/FieldHint.cjs"),te=require("../Field/FieldError.cjs"),w=e=>e&&e.__esModule?e:{default:e},ne=w(E),S=w(U),re=({ariaLabel:e,clearLabel:u="clear",dateLabel:D="Choose date",timeLabel:o="Choose time",disabled:l=!1,error:p,hint:L,id:_,label:V,labelAction:H,onChange:q,onClear:m,name:R,required:g=!1,selectButtonTitle:oe,size:I="M",step:$,value:T,initialDate:y,...v})=>{const F=ne.default.useRef(null),[r,f]=K.useControllableState({defaultProp:y?a(y,!1):void 0,prop:T?a(T,!1):T??void 0,onChange(t){q&&q(t?.toDate(d.getLocalTimeZone()))}}),M=G.useDesignSystem("DateTimePicker"),N=Q.useDateFormatter(M.locale,{hour:"2-digit",minute:"2-digit",hour12:!1}),c=r?N.format(r.toDate(d.getLocalTimeZone())):"",O=t=>{let i=t?a(t):void 0;if(!(i&&r&&i.compare(r)===0)){if(c&&i){const[h,b]=c.split(":");i=i.set({hour:parseInt(h,10),minute:parseInt(b,10)})}f(i)}},Z=t=>{if(!t)return;const[i,h]=t.split(":"),b=r?r.set({hour:parseInt(i,10),minute:parseInt(h,10)}):a(new Date).set({hour:parseInt(i,10),minute:parseInt(h,10)});f(b)},z=t=>{f(void 0),m&&m(t)},B=()=>{const t=r?r.set({hour:0,minute:0}):a(new Date);f(t)},s=x.useId(_),k=x.useId(),C=x.useId();return n.jsx(X.Field,{name:R,as:"fieldset",id:s,"aria-labelledby":s,hint:L,error:p,required:g,children:n.jsxs(P.Flex,{as:"span",direction:"column",alignItems:"stretch",gap:1,children:[n.jsx(Y.FieldLabel,{onClick:()=>{F.current.focus()},as:"legend",id:s,action:H,children:V}),n.jsxs(P.Flex,{flex:"1",gap:1,children:[n.jsx(j.VisuallyHidden,{as:"label",htmlFor:C,children:D}),n.jsx(se,{...v,selectedDate:r?.toDate(d.getLocalTimeZone()),onChange:O,error:typeof p=="string",required:g,size:I,onClear:m?z:void 0,clearLabel:`${u} date`,disabled:l,id:C,ref:F,"aria-describedby":`${s}-hint ${s}-error`}),n.jsx(j.VisuallyHidden,{as:"label",htmlFor:k,children:o}),n.jsx(ae,{size:I,error:typeof p=="string",value:c,onChange:Z,onClear:m&&c!==void 0&&c!=="00:00"?B:void 0,clearLabel:`${u} time`,required:g,disabled:l,step:$,id:k,"aria-describedby":`${s}-hint ${s}-error`})]}),n.jsx(ee.FieldHint,{}),n.jsx(te.FieldError,{})]})})},ie=J.once(console.warn),a=(e,u=!0)=>{if(typeof e=="string"){ie("It looks like you're passing a string as representation of a Date to the DatePicker. This is deprecated, look to passing a Date instead.");const l=Date.parse(e);Number.isNaN(l)?e=new Date:e=new Date(l)}const D=e.toISOString();let o=d.parseAbsoluteToLocal(D);return u&&(o=o.set({hour:0,minute:0})),d.toCalendarDateTime(o)},se=S.default(A.DatePickerInput)`
2
+ flex: 1 1 70%;
3
+ min-width: 120px;
4
+ `,ae=S.default(W.TimePickerInput)`
5
+ flex: 1 1 30%;
6
+ min-width: 120px;
7
+ `;exports.DateTimePicker=re;exports.convertUTCDateToCalendarDateTime=a;