@strapi/design-system 1.8.0 → 1.8.2

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