@strapi/design-system 1.7.10 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -17
- package/dist/Combobox/Combobox.cjs +14 -13
- package/dist/Combobox/Combobox.js +73 -68
- package/dist/DatePicker/DatePicker.cjs +82 -6
- package/dist/DatePicker/DatePicker.js +381 -55
- package/dist/DateTimePicker/DateTimePicker.cjs +7 -1
- package/dist/DateTimePicker/DateTimePicker.js +91 -53
- package/dist/DateTimePicker/index.cjs +1 -1
- package/dist/DateTimePicker/index.js +3 -2
- package/dist/DesignSystemProvider.cjs +1 -0
- package/dist/DesignSystemProvider.js +10 -0
- package/dist/NumberInput/NumberInput.cjs +2 -2
- package/dist/NumberInput/NumberInput.js +40 -40
- package/dist/Popover/Popover.cjs +3 -4
- package/dist/Popover/Popover.js +46 -48
- package/dist/Popover/index.cjs +1 -1
- package/dist/Popover/index.js +5 -9
- package/dist/Popover/primitives.cjs +1 -0
- package/dist/Popover/primitives.js +5 -0
- package/dist/Searchbar/Searchbar.cjs +2 -2
- package/dist/Searchbar/Searchbar.js +5 -5
- package/dist/Select/SelectParts.cjs +1 -1
- package/dist/Select/SelectParts.js +1 -1
- package/dist/Select/SingleSelect.cjs +1 -1
- package/dist/Select/SingleSelect.js +36 -32
- package/dist/TextInput/TextInput.cjs +1 -1
- package/dist/TextInput/TextInput.js +5 -5
- package/dist/ThemeProvider/ThemeProvider.cjs +2 -2
- package/dist/ThemeProvider/ThemeProvider.js +4 -3
- package/dist/TimePicker/TimePicker.cjs +5 -7
- package/dist/TimePicker/TimePicker.js +79 -33
- package/dist/TimePicker/index.cjs +1 -1
- package/dist/TimePicker/index.js +3 -2
- package/dist/helpers/context.cjs +1 -0
- package/dist/helpers/context.js +21 -0
- package/dist/helpers/getDefaultLocale.cjs +4 -1
- package/dist/helpers/getDefaultLocale.js +7 -2
- package/dist/hooks/useDateFormatter.cjs +1 -0
- package/dist/hooks/useDateFormatter.js +20 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +309 -304
- package/package.json +6 -5
- package/dist/DatePicker/DatePickerCalendar.cjs +0 -1
- package/dist/DatePicker/DatePickerCalendar.js +0 -43
- package/dist/DatePicker/DatePickerTd.cjs +0 -19
- package/dist/DatePicker/DatePickerTd.js +0 -29
- package/dist/DatePicker/DatePickerTh.cjs +0 -9
- package/dist/DatePicker/DatePickerTh.js +0 -18
- package/dist/DatePicker/compareDates.cjs +0 -1
- package/dist/DatePicker/compareDates.js +0 -4
- package/dist/DatePicker/components.cjs +0 -39
- package/dist/DatePicker/components.js +0 -53
- package/dist/DatePicker/utils/formatDate.cjs +0 -1
- package/dist/DatePicker/utils/formatDate.js +0 -4
- package/dist/DatePicker/utils/generateWeeks.cjs +0 -1
- package/dist/DatePicker/utils/generateWeeks.js +0 -17
- package/dist/DatePicker/utils/getDayOfWeek.cjs +0 -1
- package/dist/DatePicker/utils/getDayOfWeek.js +0 -15
- package/dist/DatePicker/utils/getMonths.cjs +0 -1
- package/dist/DatePicker/utils/getMonths.js +0 -7
- package/dist/DatePicker/utils/getYears.cjs +0 -1
- package/dist/DatePicker/utils/getYears.js +0 -9
- package/dist/DatePicker/utils/index.cjs +0 -1
- package/dist/DatePicker/utils/index.js +0 -12
- package/dist/DateTimePicker/parseDate.cjs +0 -1
- package/dist/DateTimePicker/parseDate.js +0 -8
|
@@ -1,71 +1,397 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
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";
|
|
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(({
|
|
12
30
|
/**
|
|
13
|
-
*
|
|
31
|
+
* DatePickerCalendar props
|
|
14
32
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
calendarLabel: e,
|
|
34
|
+
className: r,
|
|
35
|
+
initialDate: n,
|
|
36
|
+
locale: t,
|
|
37
|
+
maxDate: o,
|
|
38
|
+
minDate: c,
|
|
39
|
+
monthSelectLabel: h = "Month",
|
|
40
|
+
onChange: u,
|
|
41
|
+
selectedDate: i,
|
|
42
|
+
yearSelectLabel: p = "Year",
|
|
18
43
|
/**
|
|
19
|
-
*
|
|
44
|
+
* Combobox props
|
|
45
|
+
*/
|
|
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,
|
|
54
|
+
/**
|
|
55
|
+
* @preserve
|
|
56
|
+
* @deprecated This is no longer used.
|
|
20
57
|
*/
|
|
21
|
-
|
|
22
|
-
locale: h,
|
|
23
|
-
maxDate: C,
|
|
24
|
-
minDate: D,
|
|
25
|
-
onChange: c,
|
|
26
|
-
selectedDate: n,
|
|
58
|
+
ariaLabel: T,
|
|
27
59
|
/**
|
|
28
|
-
*
|
|
60
|
+
* @preserve
|
|
61
|
+
* @deprecated This is no longer used.
|
|
29
62
|
*/
|
|
30
|
-
|
|
31
|
-
...
|
|
32
|
-
}) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
i(
|
|
63
|
+
selectedDateLabel: s,
|
|
64
|
+
...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"));
|
|
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($));
|
|
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($));
|
|
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);
|
|
41
110
|
};
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
|
|
111
|
+
return l(Me, {
|
|
112
|
+
asChild: !0,
|
|
113
|
+
// we make sure we're not trapping once it's been closed
|
|
114
|
+
// (closed !== unmounted when animating out)
|
|
115
|
+
trapped: o.open,
|
|
116
|
+
onMountAutoFocus: (u) => {
|
|
117
|
+
u.preventDefault();
|
|
47
118
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
119
|
+
onUnmountAutoFocus: (u) => {
|
|
120
|
+
document.getSelection()?.empty(), u.preventDefault();
|
|
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());
|
|
127
|
+
}) })
|
|
128
|
+
});
|
|
129
|
+
}), Qe = E(V)`
|
|
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 })};
|
|
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
|
-
|
|
139
|
+
/* Required to ensure the below inputFocusStyles are adhered too */
|
|
140
|
+
&:focus-visible {
|
|
141
|
+
outline: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
${({ theme: e, $hasError: r }) => Ue()({ theme: e, hasError: r })};
|
|
145
|
+
`, et = E(Y)`
|
|
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
|
-
`,
|
|
156
|
+
`, tt = E($e)`
|
|
65
157
|
& > path {
|
|
66
158
|
fill: ${({ theme: e }) => e.colors.neutral500};
|
|
67
159
|
}
|
|
68
|
-
|
|
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, () => {
|
|
165
|
+
if (!t.textValue) {
|
|
166
|
+
t.onValueChange(void 0);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
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);
|
|
177
|
+
}
|
|
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
|
|
183
|
+
});
|
|
184
|
+
t.onCalendarDateChange(at(v, t.minDate, t.maxDate)), t.onTextValueChange(a.target.value);
|
|
185
|
+
}
|
|
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) {
|
|
195
|
+
case "ArrowDown": {
|
|
196
|
+
const f = t.calendarDate.add({ weeks: 1 });
|
|
197
|
+
if (t.maxDate && f.compare(t.maxDate) > 0)
|
|
198
|
+
return;
|
|
199
|
+
t.onCalendarDateChange(f);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
case "ArrowRight": {
|
|
203
|
+
const f = t.calendarDate.add({ days: 1 });
|
|
204
|
+
if (t.maxDate && f.compare(t.maxDate) > 0)
|
|
205
|
+
return;
|
|
206
|
+
t.onCalendarDateChange(f);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
case "ArrowUp": {
|
|
210
|
+
const f = t.calendarDate.subtract({ weeks: 1 });
|
|
211
|
+
if (t.minDate && f.compare(t.minDate) < 0)
|
|
212
|
+
return;
|
|
213
|
+
t.onCalendarDateChange(f);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
case "ArrowLeft": {
|
|
217
|
+
const f = t.calendarDate.subtract({ days: 1 });
|
|
218
|
+
if (t.minDate && f.compare(t.minDate) < 0)
|
|
219
|
+
return;
|
|
220
|
+
t.onCalendarDateChange(f);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
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));
|
|
225
|
+
}) });
|
|
226
|
+
});
|
|
227
|
+
function at(e, r, n) {
|
|
228
|
+
return r && (e = W(e, r)), n && (e = U(e, n)), e;
|
|
229
|
+
}
|
|
230
|
+
const ot = E.input`
|
|
231
|
+
width: 100%;
|
|
232
|
+
font-size: ${14 / 16}rem;
|
|
233
|
+
color: ${({ theme: e }) => e.colors.neutral800};
|
|
234
|
+
height: 100%;
|
|
235
|
+
border: none;
|
|
236
|
+
background-color: transparent;
|
|
237
|
+
|
|
238
|
+
&:focus-visible {
|
|
239
|
+
outline: none;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
&[aria-disabled='true'] {
|
|
243
|
+
cursor: inherit;
|
|
244
|
+
}
|
|
245
|
+
`, lt = "DatePickerContent", st = d.forwardRef((e, r) => {
|
|
246
|
+
const [n, t] = d.useState(), o = M(lt);
|
|
247
|
+
if (d.useLayoutEffect(() => {
|
|
248
|
+
t(new DocumentFragment());
|
|
249
|
+
}, []), !o.open) {
|
|
250
|
+
const c = n;
|
|
251
|
+
return c ? Le(l("div", { children: e.children }), c) : null;
|
|
252
|
+
}
|
|
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({
|
|
256
|
+
strategy: "fixed",
|
|
257
|
+
placement: "bottom-start",
|
|
258
|
+
middleware: [
|
|
259
|
+
xe({
|
|
260
|
+
mainAxis: 4
|
|
261
|
+
}),
|
|
262
|
+
we(),
|
|
263
|
+
ke()
|
|
264
|
+
],
|
|
265
|
+
whileElementsMounted: Te
|
|
266
|
+
});
|
|
267
|
+
d.useEffect(() => {
|
|
268
|
+
const a = () => {
|
|
269
|
+
o(!1);
|
|
270
|
+
};
|
|
271
|
+
return window.addEventListener("blur", a), window.addEventListener("resize", a), () => {
|
|
272
|
+
window.removeEventListener("blur", a), window.removeEventListener("resize", a);
|
|
273
|
+
};
|
|
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, {
|
|
279
|
+
asChild: !0,
|
|
280
|
+
// When focus is trapped, a focusout event may still happen.
|
|
281
|
+
// We make sure we don't trigger our `onDismiss` in such case.
|
|
282
|
+
onFocusOutside: (a) => {
|
|
283
|
+
a.preventDefault();
|
|
284
|
+
},
|
|
285
|
+
onDismiss: () => {
|
|
286
|
+
o(!1);
|
|
287
|
+
},
|
|
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,
|
|
290
|
+
top: u,
|
|
291
|
+
position: y
|
|
292
|
+
}, hasRadius: !0, background: "neutral0", padding: 1, ...t })
|
|
293
|
+
}) });
|
|
294
|
+
}), dt = E(Y)`
|
|
295
|
+
box-shadow: ${({ theme: e }) => e.shadows.filterShadow};
|
|
296
|
+
z-index: ${({ theme: e }) => e.zIndices[0]};
|
|
297
|
+
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);
|
|
304
|
+
return [...new Array(7).keys()].map((m) => {
|
|
305
|
+
let v = s.add({ days: m }).toDate(c);
|
|
306
|
+
return b.format(v);
|
|
307
|
+
});
|
|
308
|
+
}, [c, o, b]), k = (s) => {
|
|
309
|
+
if (typeof s == "number")
|
|
310
|
+
return;
|
|
311
|
+
const m = i.set({ month: f.indexOf(s) + 1 });
|
|
312
|
+
p(m);
|
|
313
|
+
}, x = (s) => {
|
|
314
|
+
if (typeof s == "number")
|
|
315
|
+
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))
|
|
330
|
+
break;
|
|
331
|
+
t = h;
|
|
332
|
+
}
|
|
333
|
+
for (; o.length < 7; )
|
|
334
|
+
o.push(null);
|
|
335
|
+
return o;
|
|
336
|
+
}, ht = E(V)`
|
|
337
|
+
div[role='combobox'] {
|
|
338
|
+
border: 1px solid transparent;
|
|
339
|
+
background: transparent;
|
|
340
|
+
font-weight: ${(e) => e.theme.fontWeights.bold};
|
|
341
|
+
|
|
342
|
+
${z} {
|
|
343
|
+
color: ${({ theme: e }) => e.colors.neutral800};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
svg {
|
|
347
|
+
> g,
|
|
348
|
+
path {
|
|
349
|
+
fill: ${({ theme: e }) => e.colors.neutral500};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
&:hover {
|
|
354
|
+
background-color: ${({ theme: e }) => e.colors.neutral100};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
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)`
|
|
358
|
+
border-radius: ${({ theme: e }) => e.borderRadius};
|
|
359
|
+
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, {
|
|
362
|
+
weekday: "long",
|
|
363
|
+
day: "numeric",
|
|
364
|
+
month: "long",
|
|
365
|
+
year: "numeric"
|
|
366
|
+
}), b = d.useMemo(() => f.format(e.toDate(o)), [f, e, o]), D = _(c, {
|
|
367
|
+
day: "numeric",
|
|
368
|
+
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)`
|
|
375
|
+
text-align: center;
|
|
376
|
+
padding: ${7 / 16}rem;
|
|
377
|
+
// Trick to prevent the outline from overflowing because of the general outline-offset
|
|
378
|
+
outline-offset: -2px !important;
|
|
379
|
+
|
|
380
|
+
&:hover {
|
|
381
|
+
background: ${({ theme: e }) => e.colors.primary100};
|
|
382
|
+
|
|
383
|
+
& > ${z} {
|
|
384
|
+
color: ${({ theme: e }) => e.colors.primary600};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
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;
|
|
69
394
|
export {
|
|
70
|
-
|
|
395
|
+
Kt as DatePicker,
|
|
396
|
+
Ze as DatePickerInput
|
|
71
397
|
};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),U=require("react"),d=require("@internationalized/date"),A=require("styled-components"),G=require("../DatePicker/DatePicker.cjs"),J=require("../DesignSystemProvider.cjs"),K=require("../hooks/useControllableState.cjs"),N=require("../hooks/useDateFormatter.cjs"),x=require("../hooks/useId.cjs"),Q=require("../TimePicker/TimePicker.cjs"),W=require("../Field/Field.cjs"),j=require("../Flex/Flex.cjs"),X=require("../Field/FieldLabel.cjs"),k=require("../VisuallyHidden/VisuallyHidden.cjs"),Y=require("../Field/FieldHint.cjs"),ee=require("../Field/FieldError.cjs"),S=i=>i&&i.__esModule?i:{default:i},te=S(U),L=S(A),ne=({ariaLabel:i,clearLabel:c="clear",dateLabel:h="Choose date",timeLabel:o="Choose time",disabled:b=!1,error:D,hint:_,id:$,label:w,labelAction:V,onChange:q,onClear:u,name:H,required:p=!1,selectButtonTitle:se,size:I="M",step:R,value:T,initialDate:F,...v})=>{const C=te.default.useRef(null),[n,m]=K.useControllableState({defaultProp:F?a(F,!1):void 0,prop:T?a(T,!1):T??void 0,onChange(e){q&&q(e?.toDate(d.getLocalTimeZone()))}}),M=J.useDesignSystem("DateTimePicker"),Z=N.useDateFormatter(M.locale,{hour:"2-digit",minute:"2-digit",hour12:!1}),l=n?Z.format(n.toDate(d.getLocalTimeZone())):"",z=e=>{let r=e?a(e):void 0;if(!(r&&n&&r.compare(n)===0)){if(l&&r){const[f,g]=l.split(":");r=r.set({hour:parseInt(f,10),minute:parseInt(g,10)})}m(r)}},B=e=>{if(!e)return;const[r,f]=e.split(":"),g=n?n.set({hour:parseInt(r,10),minute:parseInt(f,10)}):a(new Date).set({hour:parseInt(r,10),minute:parseInt(f,10)});m(g)},E=e=>{m(void 0),u&&u(e)},O=()=>{const e=n?n.set({hour:0,minute:0}):a(new Date);m(e)},s=x.useId($),y=x.useId(),P=x.useId();return t.jsx(W.Field,{name:H,as:"fieldset",id:s,"aria-labelledby":s,hint:_,error:D,required:p,children:t.jsxs(j.Flex,{as:"span",direction:"column",alignItems:"stretch",gap:1,children:[t.jsx(X.FieldLabel,{onClick:()=>{C.current.focus()},as:"legend",id:s,action:V,children:w}),t.jsxs(j.Flex,{flex:"1",gap:1,children:[t.jsx(k.VisuallyHidden,{as:"label",htmlFor:P,children:h}),t.jsx(re,{...v,selectedDate:n?.toDate(d.getLocalTimeZone()),onChange:z,error:typeof D=="string",required:p,size:I,onClear:u?E:void 0,clearLabel:`${c} date`,disabled:b,id:P,ref:C,"aria-describedby":`${s}-hint ${s}-error`}),t.jsx(k.VisuallyHidden,{as:"label",htmlFor:y,children:o}),t.jsx(ie,{size:I,error:typeof D=="string",value:l,onChange:B,onClear:u&&l!==void 0&&l!=="00:00"?O:void 0,clearLabel:`${c} time`,required:p,disabled:b,step:R,id:y,"aria-describedby":`${s}-hint ${s}-error`})]}),t.jsx(Y.FieldHint,{}),t.jsx(ee.FieldError,{})]})})},a=(i,c=!0)=>{const h=i.toISOString();let o=d.parseAbsoluteToLocal(h);return c&&(o=o.set({hour:0,minute:0})),d.toCalendarDateTime(o)},re=L.default(G.DatePickerInput)`
|
|
2
|
+
flex: 1 1 70%;
|
|
3
|
+
min-width: 120px;
|
|
4
|
+
`,ie=L.default(Q.TimePickerInput)`
|
|
5
|
+
flex: 1 1 30%;
|
|
6
|
+
min-width: 120px;
|
|
7
|
+
`;exports.DateTimePicker=ne;exports.convertUTCDateToCalendarDateTime=a;
|
|
@@ -1,56 +1,94 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { jsx as i, jsxs as w } from "react/jsx-runtime";
|
|
2
|
+
import Z from "react";
|
|
3
|
+
import { getLocalTimeZone as g, parseAbsoluteToLocal as v, toCalendarDateTime as G } from "@internationalized/date";
|
|
4
|
+
import $ from "styled-components";
|
|
5
|
+
import { DatePickerInput as J } from "../DatePicker/DatePicker.js";
|
|
6
|
+
import { useDesignSystem as K } from "../DesignSystemProvider.js";
|
|
7
|
+
import { useControllableState as N } from "../hooks/useControllableState.js";
|
|
8
|
+
import { useDateFormatter as Q } from "../hooks/useDateFormatter.js";
|
|
9
|
+
import { useId as T } from "../hooks/useId.js";
|
|
10
|
+
import { TimePickerInput as W } from "../TimePicker/TimePicker.js";
|
|
11
|
+
import { Field as X } from "../Field/Field.js";
|
|
12
|
+
import { Flex as L } from "../Flex/Flex.js";
|
|
13
|
+
import { FieldLabel as Y } from "../Field/FieldLabel.js";
|
|
14
|
+
import { VisuallyHidden as S } from "../VisuallyHidden/VisuallyHidden.js";
|
|
15
|
+
import { FieldHint as ee } from "../Field/FieldHint.js";
|
|
16
|
+
import { FieldError as te } from "../Field/FieldError.js";
|
|
17
|
+
const Ce = ({
|
|
18
|
+
/**
|
|
19
|
+
* @preserve
|
|
20
|
+
* @deprecated This is no longer used.
|
|
21
|
+
*/
|
|
22
|
+
ariaLabel: b,
|
|
23
|
+
clearLabel: l = "clear",
|
|
24
|
+
dateLabel: u = "Choose date",
|
|
25
|
+
timeLabel: n = "Choose time",
|
|
26
|
+
disabled: I = !1,
|
|
27
|
+
error: f,
|
|
28
|
+
hint: V,
|
|
29
|
+
id: _,
|
|
30
|
+
label: R,
|
|
31
|
+
labelAction: j,
|
|
32
|
+
onChange: C,
|
|
33
|
+
onClear: d,
|
|
34
|
+
name: z,
|
|
35
|
+
required: p = !1,
|
|
36
|
+
/**
|
|
37
|
+
* @preserve
|
|
38
|
+
* @deprecated This is no longer used.
|
|
39
|
+
*/
|
|
40
|
+
selectButtonTitle: oe,
|
|
41
|
+
size: x = "M",
|
|
42
|
+
step: B,
|
|
43
|
+
value: h,
|
|
44
|
+
initialDate: F,
|
|
45
|
+
...H
|
|
46
|
+
}) => {
|
|
47
|
+
const k = Z.useRef(null), [t, m] = N({
|
|
48
|
+
defaultProp: F ? s(F, !1) : void 0,
|
|
49
|
+
prop: h ? s(h, !1) : h ?? void 0,
|
|
50
|
+
onChange(e) {
|
|
51
|
+
C && C(e?.toDate(g()));
|
|
19
52
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
}), q = K("DateTimePicker"), A = Q(q.locale, {
|
|
54
|
+
hour: "2-digit",
|
|
55
|
+
minute: "2-digit",
|
|
56
|
+
hour12: !1
|
|
57
|
+
}), a = t ? A.format(t.toDate(g())) : "", E = (e) => {
|
|
58
|
+
let r = e ? s(e) : void 0;
|
|
59
|
+
if (!(r && t && r.compare(t) === 0)) {
|
|
60
|
+
if (a && r) {
|
|
61
|
+
const [c, D] = a.split(":");
|
|
62
|
+
r = r.set({ hour: parseInt(c, 10), minute: parseInt(D, 10) });
|
|
63
|
+
}
|
|
64
|
+
m(r);
|
|
65
|
+
}
|
|
66
|
+
}, M = (e) => {
|
|
67
|
+
if (!e)
|
|
68
|
+
return;
|
|
69
|
+
const [r, c] = e.split(":"), D = t ? t.set({ hour: parseInt(r, 10), minute: parseInt(c, 10) }) : s(/* @__PURE__ */ new Date()).set({ hour: parseInt(r, 10), minute: parseInt(c, 10) });
|
|
70
|
+
m(D);
|
|
71
|
+
}, O = (e) => {
|
|
72
|
+
m(void 0), d && d(e);
|
|
73
|
+
}, U = () => {
|
|
74
|
+
const e = t ? t.set({ hour: 0, minute: 0 }) : s(/* @__PURE__ */ new Date());
|
|
75
|
+
m(e);
|
|
76
|
+
}, o = T(_), y = T(), P = T();
|
|
77
|
+
return i(X, { name: z, as: "fieldset", id: o, "aria-labelledby": o, hint: V, error: f, required: p, children: w(L, { as: "span", direction: "column", alignItems: "stretch", gap: 1, children: [i(Y, { onClick: () => {
|
|
78
|
+
k.current.focus();
|
|
79
|
+
}, as: "legend", id: o, action: j, children: R }), w(L, { flex: "1", gap: 1, children: [i(S, { as: "label", htmlFor: P, children: u }), i(re, { ...H, selectedDate: t?.toDate(g()), onChange: E, error: typeof f == "string", required: p, size: x, onClear: d ? O : void 0, clearLabel: `${l} date`, disabled: I, id: P, ref: k, "aria-describedby": `${o}-hint ${o}-error` }), i(S, { as: "label", htmlFor: y, children: n }), i(ie, { size: x, error: typeof f == "string", value: a, onChange: M, onClear: d && a !== void 0 && a !== "00:00" ? U : void 0, clearLabel: `${l} time`, required: p, disabled: I, step: B, id: y, "aria-describedby": `${o}-hint ${o}-error` })] }), i(ee, {}), i(te, {})] }) });
|
|
80
|
+
}, s = (b, l = !0) => {
|
|
81
|
+
const u = b.toISOString();
|
|
82
|
+
let n = v(u);
|
|
83
|
+
return l && (n = n.set({ hour: 0, minute: 0 })), G(n);
|
|
84
|
+
}, re = $(J)`
|
|
85
|
+
flex: 1 1 70%;
|
|
86
|
+
min-width: 120px;
|
|
87
|
+
`, ie = $(W)`
|
|
88
|
+
flex: 1 1 30%;
|
|
89
|
+
min-width: 120px;
|
|
90
|
+
`;
|
|
54
91
|
export {
|
|
55
|
-
|
|
92
|
+
Ce as DateTimePicker,
|
|
93
|
+
s as convertUTCDateToCalendarDateTime
|
|
56
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DateTimePicker.cjs");exports.DateTimePicker=e.DateTimePicker;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DateTimePicker.cjs");exports.DateTimePicker=e.DateTimePicker;exports.convertUTCDateToCalendarDateTime=e.convertUTCDateToCalendarDateTime;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./helpers/context.cjs"),s=require("./ThemeProvider/ThemeProvider.cjs"),t="en-EN",r=()=>typeof navigator>"u"?t:navigator.language?navigator.language:t,[a,u]=o.createContext("StrapiDesignSystem",{locale:r()}),c=({locale:n=r(),...i})=>e.jsx(a,{locale:n,children:e.jsx(s.ThemeProvider,{...i})});exports.DesignSystemProvider=c;exports.useDesignSystem=u;
|