impact-nova 2.0.7 → 2.0.9
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/dist/components/ui/ag-grid-react/headers/header-search-input.d.ts +2 -2
- package/dist/components/ui/ag-grid-react/headers/header-search-input.js +210 -204
- package/dist/components/ui/ag-grid-react/headers/use-header-search-editing-state.d.ts +34 -0
- package/dist/components/ui/ag-grid-react/headers/use-header-search-editing-state.js +70 -0
- package/dist/components/ui/date-picker/date-picker.js +33 -32
- package/dist/components/ui/date-picker/date-range-picker.js +1 -0
- package/dist/components/ui/date-picker/month-picker.js +48 -47
- package/dist/components/ui/date-picker/month-range-picker.js +32 -31
- package/dist/components/ui/date-picker/multi-date-picker.js +20 -19
- package/dist/components/ui/date-picker/multi-month-picker.js +80 -61
- package/dist/components/ui/date-picker/multi-week-picker.js +100 -81
- package/dist/components/ui/date-picker/week-picker.js +26 -25
- package/dist/components/ui/date-picker/week-range-picker.js +24 -23
- package/dist/components/ui/select/select.js +34 -37
- package/package.json +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ColDef, GridApi } from 'ag-grid-community';
|
|
2
|
+
import { HeaderSearchCommittedState } from './derive-header-search-state';
|
|
3
|
+
interface UseHeaderSearchEditingStateOptions {
|
|
4
|
+
api: GridApi;
|
|
5
|
+
colId: string;
|
|
6
|
+
colDef: ColDef | undefined;
|
|
7
|
+
isDateFilter: boolean;
|
|
8
|
+
isMonthVariant: boolean;
|
|
9
|
+
isWeekVariant: boolean;
|
|
10
|
+
datePickerVariant: "date" | "month" | "week";
|
|
11
|
+
dateDisplayFormat: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Inline header search display state.
|
|
15
|
+
*
|
|
16
|
+
* AG Grid's filter model is the source of truth. While inline search is open,
|
|
17
|
+
* AgGridWrapper skips refreshHeader on filterChanged, so this hook subscribes
|
|
18
|
+
* to filterChanged and keeps a column-scoped snapshot in React state. When the
|
|
19
|
+
* snapshot changes, committed display values are re-derived from the live filter
|
|
20
|
+
* model. While an input is focused, a draft overlays committed values so typing
|
|
21
|
+
* is not interrupted.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useHeaderSearchEditingState(options: UseHeaderSearchEditingStateOptions): {
|
|
24
|
+
searchText: string;
|
|
25
|
+
dateDisplayString: string;
|
|
26
|
+
selectedDate: Date;
|
|
27
|
+
selectedMonth: import('../../calendar').MonthSelection;
|
|
28
|
+
selectedWeek: import('../../calendar').WeekSelection;
|
|
29
|
+
updateDraft: (patch: Partial<HeaderSearchCommittedState>) => void;
|
|
30
|
+
handleFocus: () => void;
|
|
31
|
+
handleBlur: () => void;
|
|
32
|
+
clearEditingOverlay: () => void;
|
|
33
|
+
};
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useCallback as V, useState as l, useEffect as b, useMemo as v } from "react";
|
|
2
|
+
import { subscribeGridApiEvent as W } from "../grid-api-event-subscription.js";
|
|
3
|
+
import { deriveHeaderSearchCommittedState as H } from "./derive-header-search-state.js";
|
|
4
|
+
function A(D) {
|
|
5
|
+
const {
|
|
6
|
+
api: e,
|
|
7
|
+
colId: r,
|
|
8
|
+
colDef: c,
|
|
9
|
+
isDateFilter: d,
|
|
10
|
+
isMonthVariant: u,
|
|
11
|
+
isWeekVariant: m,
|
|
12
|
+
datePickerVariant: S,
|
|
13
|
+
dateDisplayFormat: f
|
|
14
|
+
} = D, n = V(
|
|
15
|
+
() => JSON.stringify(e.getFilterModel()[r] ?? null),
|
|
16
|
+
[e, r]
|
|
17
|
+
), [y, g] = l(
|
|
18
|
+
n
|
|
19
|
+
), [i, o] = l(null), [M, p] = l(!1);
|
|
20
|
+
b(() => W(
|
|
21
|
+
e,
|
|
22
|
+
"filterChanged",
|
|
23
|
+
() => {
|
|
24
|
+
const a = n();
|
|
25
|
+
g(
|
|
26
|
+
(F) => F === a ? F : a
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
), [e, r, n]);
|
|
30
|
+
const h = v(() => H({
|
|
31
|
+
api: e,
|
|
32
|
+
colId: r,
|
|
33
|
+
colDef: c,
|
|
34
|
+
isDateFilter: d,
|
|
35
|
+
isMonthVariant: u,
|
|
36
|
+
isWeekVariant: m,
|
|
37
|
+
datePickerVariant: S,
|
|
38
|
+
dateDisplayFormat: f
|
|
39
|
+
}), [
|
|
40
|
+
e,
|
|
41
|
+
r,
|
|
42
|
+
c,
|
|
43
|
+
d,
|
|
44
|
+
u,
|
|
45
|
+
m,
|
|
46
|
+
S,
|
|
47
|
+
f,
|
|
48
|
+
y
|
|
49
|
+
]), s = (t) => M && i && i[t] !== void 0 ? i[t] : h[t], k = (t) => {
|
|
50
|
+
o((a) => ({ ...h, ...a, ...t }));
|
|
51
|
+
}, C = () => p(!0), x = () => {
|
|
52
|
+
p(!1), o(null);
|
|
53
|
+
}, E = () => {
|
|
54
|
+
o(null);
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
searchText: s("searchText"),
|
|
58
|
+
dateDisplayString: s("dateDisplayString"),
|
|
59
|
+
selectedDate: s("selectedDate"),
|
|
60
|
+
selectedMonth: s("selectedMonth"),
|
|
61
|
+
selectedWeek: s("selectedWeek"),
|
|
62
|
+
updateDraft: k,
|
|
63
|
+
handleFocus: C,
|
|
64
|
+
handleBlur: x,
|
|
65
|
+
clearEditingOverlay: E
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
A as useHeaderSearchEditingState
|
|
70
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as x, jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import * as o from "react";
|
|
3
3
|
import { Cross as Z, CalendarMonth as _ } from "impact-nova-icons";
|
|
4
|
-
import { format as
|
|
4
|
+
import { format as m, isValid as I, parse as b } from "date-fns";
|
|
5
5
|
import { cn as $, padValidDateString as F, maskDate as ee } from "../../../lib/utils.js";
|
|
6
6
|
import { Input as te } from "../input.js";
|
|
7
7
|
import { Popover as ne, PopoverAnchor as re, PopoverContent as oe } from "../popover.js";
|
|
8
8
|
import { Calendar as ce } from "../calendar.js";
|
|
9
9
|
import { Tooltip as S, TooltipTrigger as E, TooltipContent as T } from "../tooltip.js";
|
|
10
|
-
import { getDateFnsLocale as
|
|
11
|
-
import { useImpactNovaI18n as
|
|
10
|
+
import { getDateFnsLocale as le } from "../../../i18n/getDateFnsLocale.js";
|
|
11
|
+
import { useImpactNovaI18n as ie } from "../../../i18n/ImpactNovaI18nContext.js";
|
|
12
12
|
const ae = o.forwardRef(
|
|
13
13
|
({
|
|
14
14
|
value: t,
|
|
@@ -20,44 +20,44 @@ const ae = o.forwardRef(
|
|
|
20
20
|
startMonth: z,
|
|
21
21
|
endMonth: B,
|
|
22
22
|
showFooter: d = !0,
|
|
23
|
-
weekStartsOn:
|
|
23
|
+
weekStartsOn: N,
|
|
24
24
|
disabled: a,
|
|
25
25
|
className: O,
|
|
26
26
|
...H
|
|
27
27
|
}, q) => {
|
|
28
|
-
const { locale:
|
|
28
|
+
const { locale: R, t: h } = ie(), l = o.useMemo(() => le(R), [R]), G = j ?? h("datePicker.selectDate"), g = o.useRef(null), D = o.useRef(null);
|
|
29
29
|
o.useImperativeHandle(q, () => g.current);
|
|
30
|
-
const [c,
|
|
30
|
+
const [c, i] = o.useState(!1), k = o.useRef(!1), [v, s] = o.useState(t), [p, f] = o.useState(t ? m(t, n, { locale: l }) : ""), [J, w] = o.useState(t || /* @__PURE__ */ new Date());
|
|
31
31
|
o.useEffect(() => {
|
|
32
32
|
g.current && D.current !== null && (g.current.setSelectionRange(D.current, D.current), D.current = null);
|
|
33
33
|
}, [p]), o.useEffect(() => {
|
|
34
|
-
c || (f(t ?
|
|
35
|
-
}, [t, n, c,
|
|
34
|
+
c || (f(t ? m(t, n, { locale: l }) : ""), s(t));
|
|
35
|
+
}, [t, n, c, l]), o.useEffect(() => {
|
|
36
36
|
c && (s(t), w(t || /* @__PURE__ */ new Date()));
|
|
37
37
|
}, [c, t]);
|
|
38
38
|
const Q = (e) => {
|
|
39
|
-
s(e), e && f(
|
|
39
|
+
s(e), e && f(m(e, n, { locale: l })), d || (u?.(e), i(!1));
|
|
40
40
|
}, U = (e) => {
|
|
41
|
-
u?.(e !== void 0 ? e : v),
|
|
41
|
+
u?.(e !== void 0 ? e : v), i(!1);
|
|
42
42
|
}, V = () => {
|
|
43
|
-
s(t), f(t ?
|
|
43
|
+
s(t), f(t ? m(t, n, { locale: l }) : ""), i(!1);
|
|
44
44
|
}, A = () => {
|
|
45
|
-
s(void 0), f(""), u?.(void 0), d ||
|
|
45
|
+
s(void 0), f(""), u?.(void 0), d || i(!1);
|
|
46
46
|
}, W = (e) => {
|
|
47
47
|
const y = e.target.value, C = ee(y, n, p);
|
|
48
48
|
if (f(C), C === "") {
|
|
49
49
|
s(void 0), d || u?.(void 0);
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
I(
|
|
52
|
+
const P = b(C, n, /* @__PURE__ */ new Date(), { locale: l });
|
|
53
|
+
I(P) && C.length === n.length && (s(P), w(P), d || u?.(P));
|
|
54
54
|
}, X = () => {
|
|
55
55
|
if (c) return;
|
|
56
|
-
const e = F(p, n), y =
|
|
57
|
-
!I(y) || e.length !== n.length ? (f(t ?
|
|
58
|
-
}, M = (t ?
|
|
59
|
-
return /* @__PURE__ */
|
|
60
|
-
a ||
|
|
56
|
+
const e = F(p, n), y = b(e, n, /* @__PURE__ */ new Date(), { locale: l });
|
|
57
|
+
!I(y) || e.length !== n.length ? (f(t ? m(t, n, { locale: l }) : ""), s(t)) : (f(e), d || u?.(y));
|
|
58
|
+
}, M = (t ? m(t, n, { locale: l }) : "") !== p, Y = p.length === n.length && !I(b(p, n, /* @__PURE__ */ new Date(), { locale: l }));
|
|
59
|
+
return /* @__PURE__ */ x(ne, { open: a ? !1 : c, onOpenChange: (e) => {
|
|
60
|
+
a || i(e);
|
|
61
61
|
}, children: [
|
|
62
62
|
/* @__PURE__ */ r(re, { asChild: !0, children: /* @__PURE__ */ r("div", { "data-component": "date-picker", "data-state": c ? "open" : "closed", "data-pending": M || void 0, children: /* @__PURE__ */ r(
|
|
63
63
|
te,
|
|
@@ -66,9 +66,9 @@ const ae = o.forwardRef(
|
|
|
66
66
|
value: p,
|
|
67
67
|
onChange: W,
|
|
68
68
|
onBlur: X,
|
|
69
|
-
onClick: () => !a &&
|
|
69
|
+
onClick: () => !a && i(!0),
|
|
70
70
|
onKeyDown: (e) => {
|
|
71
|
-
(e.key === "Enter" || e.key === "ArrowDown") && !c && !a && (e.preventDefault(), k.current = !0,
|
|
71
|
+
(e.key === "Enter" || e.key === "ArrowDown") && !c && !a && (e.preventDefault(), k.current = !0, i(!0)), e.key === "Escape" && c && (e.preventDefault(), V());
|
|
72
72
|
},
|
|
73
73
|
placeholder: c ? n : G,
|
|
74
74
|
disabled: a,
|
|
@@ -78,14 +78,14 @@ const ae = o.forwardRef(
|
|
|
78
78
|
Y ? "text-destructive" : M ? "text-content-muted" : "",
|
|
79
79
|
O
|
|
80
80
|
),
|
|
81
|
-
suffix: /* @__PURE__ */
|
|
82
|
-
t && !a && /* @__PURE__ */
|
|
81
|
+
suffix: /* @__PURE__ */ x("div", { className: "flex items-center gap-1", children: [
|
|
82
|
+
t && !a && /* @__PURE__ */ x(S, { children: [
|
|
83
83
|
/* @__PURE__ */ r(E, { asChild: !0, children: /* @__PURE__ */ r(
|
|
84
84
|
"button",
|
|
85
85
|
{
|
|
86
86
|
type: "button",
|
|
87
87
|
tabIndex: 0,
|
|
88
|
-
"aria-label":
|
|
88
|
+
"aria-label": h("calendar.clear"),
|
|
89
89
|
onClick: (e) => {
|
|
90
90
|
e.stopPropagation(), A();
|
|
91
91
|
},
|
|
@@ -93,15 +93,15 @@ const ae = o.forwardRef(
|
|
|
93
93
|
children: /* @__PURE__ */ r(Z, { className: "size-3 hover:text-content" })
|
|
94
94
|
}
|
|
95
95
|
) }),
|
|
96
|
-
/* @__PURE__ */ r(T, { variant: "tertiary", side: "top", children:
|
|
96
|
+
/* @__PURE__ */ r(T, { variant: "tertiary", side: "top", children: h("calendar.clear") })
|
|
97
97
|
] }),
|
|
98
|
-
/* @__PURE__ */
|
|
99
|
-
/* @__PURE__ */ r(E, { asChild: !0, children: /* @__PURE__ */ r("button", { type: "button", tabIndex: 0, "aria-label":
|
|
100
|
-
e.stopPropagation(), a ||
|
|
98
|
+
/* @__PURE__ */ x(S, { children: [
|
|
99
|
+
/* @__PURE__ */ r(E, { asChild: !0, children: /* @__PURE__ */ r("button", { type: "button", tabIndex: 0, "aria-label": h("datePicker.selectDate"), onClick: (e) => {
|
|
100
|
+
e.stopPropagation(), a || i(!c);
|
|
101
101
|
}, onKeyDown: (e) => {
|
|
102
|
-
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), e.stopPropagation(), a || (k.current = !0,
|
|
102
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), e.stopPropagation(), a || (k.current = !0, i(!c)));
|
|
103
103
|
}, className: "inline-flex items-center justify-center bg-transparent border-none p-0 cursor-pointer", children: /* @__PURE__ */ r(_, { className: "h-4 w-4 text-secondary-foreground" }) }) }),
|
|
104
|
-
/* @__PURE__ */ r(T, { variant: "tertiary", side: "top", children:
|
|
104
|
+
/* @__PURE__ */ r(T, { variant: "tertiary", side: "top", children: h("datePicker.selectDate") })
|
|
105
105
|
] })
|
|
106
106
|
] }),
|
|
107
107
|
...H
|
|
@@ -112,6 +112,7 @@ const ae = o.forwardRef(
|
|
|
112
112
|
{
|
|
113
113
|
className: "w-auto p-0",
|
|
114
114
|
align: "start",
|
|
115
|
+
"aria-label": h("datePicker.selectDate"),
|
|
115
116
|
onOpenAutoFocus: (e) => {
|
|
116
117
|
k.current || e.preventDefault(), k.current = !1;
|
|
117
118
|
},
|
|
@@ -131,7 +132,7 @@ const ae = o.forwardRef(
|
|
|
131
132
|
onCancel: V,
|
|
132
133
|
onClear: A,
|
|
133
134
|
captionLayout: "dropdown",
|
|
134
|
-
...
|
|
135
|
+
...N !== void 0 ? { weekStartsOn: N } : {}
|
|
135
136
|
}
|
|
136
137
|
)
|
|
137
138
|
}
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import * as
|
|
1
|
+
import { jsxs as u, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import * as r from "react";
|
|
3
3
|
import { Cross as L, CalendarMonth as Q } from "impact-nova-icons";
|
|
4
|
-
import { isValid as C, parse as
|
|
4
|
+
import { isValid as C, parse as P } from "date-fns";
|
|
5
5
|
import { cn as U, padValidDateString as W, maskDate as X } from "../../../lib/utils.js";
|
|
6
6
|
import { Input as Z } from "../input.js";
|
|
7
7
|
import { Popover as _, PopoverAnchor as F, PopoverContent as v } from "../popover.js";
|
|
8
8
|
import { Calendar as tt } from "../calendar.js";
|
|
9
9
|
import { Tooltip as I, TooltipTrigger as N, TooltipContent as T } from "../tooltip.js";
|
|
10
10
|
import { useImpactNovaI18n as et } from "../../../i18n/ImpactNovaI18nContext.js";
|
|
11
|
-
const c = (t) => `${(t.month + 1).toString().padStart(2, "0")}/${t.year}`, nt =
|
|
11
|
+
const c = (t) => `${(t.month + 1).toString().padStart(2, "0")}/${t.year}`, nt = r.forwardRef(
|
|
12
12
|
({
|
|
13
13
|
value: t,
|
|
14
14
|
onChange: s,
|
|
15
15
|
placeholder: V,
|
|
16
16
|
minDate: A,
|
|
17
|
-
maxDate:
|
|
18
|
-
startMonth:
|
|
17
|
+
maxDate: b,
|
|
18
|
+
startMonth: R,
|
|
19
19
|
endMonth: j,
|
|
20
20
|
showFooter: l = !0,
|
|
21
|
-
disabled:
|
|
21
|
+
disabled: y,
|
|
22
22
|
className: O,
|
|
23
23
|
...Y
|
|
24
24
|
}, z) => {
|
|
25
|
-
const { t:
|
|
26
|
-
|
|
27
|
-
const [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, [
|
|
31
|
-
|
|
32
|
-
}, [
|
|
25
|
+
const { t: d } = et(), B = V ?? d("datePicker.selectMonth"), k = r.useRef(null);
|
|
26
|
+
r.useRef(null), r.useImperativeHandle(z, () => k.current);
|
|
27
|
+
const [o, p] = r.useState(!1), [x, a] = r.useState(t), [h, i] = r.useState(t ? c(t) : ""), [E, g] = r.useState(t ? new Date(t.year, t.month) : /* @__PURE__ */ new Date());
|
|
28
|
+
r.useEffect(() => {
|
|
29
|
+
o || (i(t ? c(t) : ""), a(t));
|
|
30
|
+
}, [o, t]), r.useEffect(() => {
|
|
31
|
+
o && (a(t), g(t ? new Date(t.year, t.month) : /* @__PURE__ */ new Date()), i(t ? c(t) : ""));
|
|
32
|
+
}, [o, t]);
|
|
33
33
|
const $ = (e) => {
|
|
34
34
|
a(e), e && i(c(e)), l || (s?.(e), p(!1));
|
|
35
35
|
}, H = (e) => {
|
|
36
|
-
s?.(e !== void 0 ? e :
|
|
36
|
+
s?.(e !== void 0 ? e : x), p(!1);
|
|
37
37
|
}, q = () => {
|
|
38
38
|
a(t), i(t ? c(t) : ""), p(!1);
|
|
39
|
-
},
|
|
39
|
+
}, S = () => {
|
|
40
40
|
a(void 0), i(""), s?.(void 0), l || p(!1);
|
|
41
41
|
}, G = (e) => {
|
|
42
|
-
const f = e.target.value,
|
|
43
|
-
if (i(
|
|
42
|
+
const f = e.target.value, m = X(f, "MM/yyyy", h);
|
|
43
|
+
if (i(m), m === "") {
|
|
44
44
|
a(void 0), l || s?.(void 0);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
if (C(
|
|
49
|
-
const D = { month:
|
|
50
|
-
a(D), g(
|
|
47
|
+
const M = P(m, "MM/yyyy", /* @__PURE__ */ new Date());
|
|
48
|
+
if (C(M) && m.length === 7) {
|
|
49
|
+
const D = { month: M.getMonth(), year: M.getFullYear() };
|
|
50
|
+
a(D), g(M), l || s?.(D);
|
|
51
51
|
}
|
|
52
52
|
}, J = () => {
|
|
53
|
-
if (
|
|
54
|
-
const e = W(
|
|
53
|
+
if (o) return;
|
|
54
|
+
const e = W(h, "MM/yyyy"), f = P(e, "MM/yyyy", /* @__PURE__ */ new Date());
|
|
55
55
|
if (!C(f) || e.length !== 7)
|
|
56
56
|
i(t ? c(t) : ""), a(t);
|
|
57
57
|
else if (i(e), !l) {
|
|
58
|
-
const
|
|
59
|
-
s?.(
|
|
58
|
+
const m = { month: f.getMonth(), year: f.getFullYear() };
|
|
59
|
+
s?.(m);
|
|
60
60
|
}
|
|
61
|
-
}, w = (t ? c(t) : "") !==
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
-
|
|
61
|
+
}, w = (t ? c(t) : "") !== h, K = h.length === 7 && !C(P(h, "MM/yyyy", /* @__PURE__ */ new Date()));
|
|
62
|
+
return /* @__PURE__ */ u(_, { open: y ? !1 : o, onOpenChange: (e) => {
|
|
63
|
+
y || p(e);
|
|
64
64
|
}, children: [
|
|
65
|
-
/* @__PURE__ */ n(F, { asChild: !0, children: /* @__PURE__ */ n("div", { "data-component": "month-picker", "data-state":
|
|
65
|
+
/* @__PURE__ */ n(F, { asChild: !0, children: /* @__PURE__ */ n("div", { "data-component": "month-picker", "data-state": o ? "open" : "closed", "data-pending": w || void 0, children: /* @__PURE__ */ n(
|
|
66
66
|
Z,
|
|
67
67
|
{
|
|
68
|
-
ref:
|
|
69
|
-
value:
|
|
68
|
+
ref: k,
|
|
69
|
+
value: h,
|
|
70
70
|
onChange: G,
|
|
71
71
|
onBlur: J,
|
|
72
|
-
onClick: () => !
|
|
73
|
-
placeholder:
|
|
74
|
-
disabled:
|
|
72
|
+
onClick: () => !y && p(!0),
|
|
73
|
+
placeholder: o ? d("datePicker.monthYearFormat") : B,
|
|
74
|
+
disabled: y,
|
|
75
75
|
"data-form-control": "input",
|
|
76
76
|
className: U(
|
|
77
77
|
"cursor-pointer",
|
|
78
78
|
K ? "text-destructive" : w ? "text-content-muted" : "",
|
|
79
79
|
O
|
|
80
80
|
),
|
|
81
|
-
suffix: /* @__PURE__ */
|
|
82
|
-
t && !
|
|
81
|
+
suffix: /* @__PURE__ */ u("div", { className: "flex items-center gap-1", children: [
|
|
82
|
+
t && !y && /* @__PURE__ */ u(I, { children: [
|
|
83
83
|
/* @__PURE__ */ n(N, { asChild: !0, children: /* @__PURE__ */ n(
|
|
84
84
|
"button",
|
|
85
85
|
{
|
|
86
86
|
type: "button",
|
|
87
87
|
tabIndex: 0,
|
|
88
|
-
"aria-label":
|
|
88
|
+
"aria-label": d("calendar.clear"),
|
|
89
89
|
onClick: (e) => {
|
|
90
|
-
e.stopPropagation(),
|
|
90
|
+
e.stopPropagation(), S();
|
|
91
91
|
},
|
|
92
92
|
className: "inline-flex size-4 items-center justify-center bg-transparent border-none p-0 cursor-pointer",
|
|
93
93
|
children: /* @__PURE__ */ n(L, { className: "size-3 hover:text-content" })
|
|
94
94
|
}
|
|
95
95
|
) }),
|
|
96
|
-
/* @__PURE__ */ n(T, { variant: "tertiary", side: "top", children:
|
|
96
|
+
/* @__PURE__ */ n(T, { variant: "tertiary", side: "top", children: d("calendar.clear") })
|
|
97
97
|
] }),
|
|
98
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ u(I, { children: [
|
|
99
99
|
/* @__PURE__ */ n(N, { asChild: !0, children: /* @__PURE__ */ n(Q, { className: "h-4 w-4 text-secondary-foreground" }) }),
|
|
100
|
-
/* @__PURE__ */ n(T, { variant: "tertiary", side: "top", children:
|
|
100
|
+
/* @__PURE__ */ n(T, { variant: "tertiary", side: "top", children: d("datePicker.selectMonth") })
|
|
101
101
|
] })
|
|
102
102
|
] }),
|
|
103
103
|
...Y
|
|
@@ -108,23 +108,24 @@ const c = (t) => `${(t.month + 1).toString().padStart(2, "0")}/${t.year}`, nt =
|
|
|
108
108
|
{
|
|
109
109
|
className: "w-auto p-0",
|
|
110
110
|
align: "start",
|
|
111
|
+
"aria-label": d("datePicker.selectMonth"),
|
|
111
112
|
onOpenAutoFocus: (e) => e.preventDefault(),
|
|
112
113
|
children: /* @__PURE__ */ n(
|
|
113
114
|
tt,
|
|
114
115
|
{
|
|
115
116
|
pickerType: "month",
|
|
116
117
|
monthMode: "single",
|
|
117
|
-
selectedMonths:
|
|
118
|
+
selectedMonths: x,
|
|
118
119
|
onMonthSelect: $,
|
|
119
120
|
month: E,
|
|
120
121
|
onMonthChange: g,
|
|
121
|
-
disabled: { before: A, after:
|
|
122
|
-
startMonth:
|
|
122
|
+
disabled: { before: A, after: b },
|
|
123
|
+
startMonth: R,
|
|
123
124
|
endMonth: j,
|
|
124
125
|
showFooter: l,
|
|
125
126
|
onApply: H,
|
|
126
127
|
onCancel: q,
|
|
127
|
-
onClear:
|
|
128
|
+
onClear: S
|
|
128
129
|
}
|
|
129
130
|
)
|
|
130
131
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as h, jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import * as u from "react";
|
|
3
3
|
import { Cross as ht, CalendarMonth as gt, Info as J } from "impact-nova-icons";
|
|
4
|
-
import { isValid as
|
|
4
|
+
import { isValid as y, parse as w } from "date-fns";
|
|
5
5
|
import { cn as x, padValidDateString as R, maskDate as L } from "../../../lib/utils.js";
|
|
6
6
|
import { Popover as xt, PopoverAnchor as Mt, PopoverContent as Yt } from "../popover.js";
|
|
7
7
|
import { Calendar as yt } from "../calendar.js";
|
|
@@ -33,55 +33,55 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
33
33
|
displayFormat: a = "MM/YYYY",
|
|
34
34
|
...et
|
|
35
35
|
}, nt) => {
|
|
36
|
-
const { t:
|
|
37
|
-
A ??
|
|
36
|
+
const { t: Y } = wt();
|
|
37
|
+
A ?? Y("datePicker.selectMonthRange");
|
|
38
38
|
const H = u.useRef(null), ot = u.useRef(null), c = u.useMemo(
|
|
39
39
|
() => a === "YYYY/MM" ? "yyyy/MM" : "MM/yyyy",
|
|
40
40
|
[a]
|
|
41
41
|
);
|
|
42
42
|
u.useImperativeHandle(nt, () => H.current);
|
|
43
|
-
const [l, g] = u.useState(!1), V = u.useRef(!1), [
|
|
43
|
+
const [l, g] = u.useState(!1), V = u.useRef(!1), [v, b] = u.useState(e), [k, N] = u.useState(e?.from ? p(e.from, a) : ""), [D, P] = u.useState(e?.to ? p(e.to, a) : ""), [rt, j] = u.useState(() => e?.from ? new Date(e.from.year, e.from.month, 1) : I || /* @__PURE__ */ new Date());
|
|
44
44
|
u.useEffect(() => {
|
|
45
|
-
l || (N(e?.from ? p(e.from, a) : ""),
|
|
45
|
+
l || (N(e?.from ? p(e.from, a) : ""), P(e?.to ? p(e.to, a) : ""), b(e));
|
|
46
46
|
}, [l, e, a]), u.useEffect(() => {
|
|
47
|
-
l && (b(e), N(e?.from ? p(e.from, a) : ""),
|
|
47
|
+
l && (b(e), N(e?.from ? p(e.from, a) : ""), P(e?.to ? p(e.to, a) : ""), j(e?.from ? new Date(e.from.year, e.from.month, 1) : I || /* @__PURE__ */ new Date()));
|
|
48
48
|
}, [l, e, a, I]);
|
|
49
49
|
const at = (t) => {
|
|
50
|
-
b(t), t?.from && N(p(t.from, a)), t?.to &&
|
|
50
|
+
b(t), t?.from && N(p(t.from, a)), t?.to && P(p(t.to, a)), !M && t?.from && t?.to && (t.from.month !== t.to.month || t.from.year !== t.to.year) && (s?.(t), g(!1));
|
|
51
51
|
}, st = (t) => {
|
|
52
|
-
s?.(t !== void 0 ? t :
|
|
52
|
+
s?.(t !== void 0 ? t : v), g(!1);
|
|
53
53
|
}, K = () => {
|
|
54
|
-
b(e), N(e?.from ? p(e.from, a) : ""),
|
|
54
|
+
b(e), N(e?.from ? p(e.from, a) : ""), P(e?.to ? p(e.to, a) : ""), g(!1);
|
|
55
55
|
}, $ = () => {
|
|
56
|
-
b(void 0), N(""),
|
|
56
|
+
b(void 0), N(""), P(""), s?.(void 0), M || g(!1);
|
|
57
57
|
}, ct = (t) => {
|
|
58
58
|
const f = t.target.value, r = L(f, c, k);
|
|
59
59
|
if (N(r), r === "") {
|
|
60
|
-
const o = { from: void 0, to:
|
|
60
|
+
const o = { from: void 0, to: v?.to };
|
|
61
61
|
b(o), M || s?.(o);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
const n =
|
|
65
|
-
if (
|
|
66
|
-
const d = { from: { month: n.getMonth(), year: n.getFullYear() }, to:
|
|
64
|
+
const n = w(r, c, /* @__PURE__ */ new Date());
|
|
65
|
+
if (y(n) && r.length === 7) {
|
|
66
|
+
const d = { from: { month: n.getMonth(), year: n.getFullYear() }, to: v?.to };
|
|
67
67
|
b(d), j(n), M || s?.(d);
|
|
68
68
|
}
|
|
69
69
|
}, it = (t) => {
|
|
70
70
|
const f = t.target.value, r = L(f, c, D);
|
|
71
|
-
if (
|
|
72
|
-
const o = { from:
|
|
71
|
+
if (P(r), r === "") {
|
|
72
|
+
const o = { from: v?.from, to: void 0 };
|
|
73
73
|
b(o), M || s?.(o);
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
const n =
|
|
77
|
-
if (
|
|
78
|
-
const o = { month: n.getMonth(), year: n.getFullYear() }, d = { from:
|
|
76
|
+
const n = w(r, c, /* @__PURE__ */ new Date());
|
|
77
|
+
if (y(n) && r.length === 7) {
|
|
78
|
+
const o = { month: n.getMonth(), year: n.getFullYear() }, d = { from: v?.from, to: o };
|
|
79
79
|
b(d), j(n), M || s?.(d);
|
|
80
80
|
}
|
|
81
81
|
}, T = () => {
|
|
82
82
|
if (l) return;
|
|
83
|
-
const t = R(k, c), f = R(D, c), r =
|
|
84
|
-
k && !o ? N(e?.from ? p(e.from, a) : "") : o && N(t), D && !d ?
|
|
83
|
+
const t = R(k, c), f = R(D, c), r = w(t, c, /* @__PURE__ */ new Date()), n = w(f, c, /* @__PURE__ */ new Date()), o = y(r) && t.length === 7, d = y(n) && f.length === 7;
|
|
84
|
+
k && !o ? N(e?.from ? p(e.from, a) : "") : o && N(t), D && !d ? P(e?.to ? p(e.to, a) : "") : d && P(f), o && d && !M ? s?.({
|
|
85
85
|
from: { month: r.getMonth(), year: r.getFullYear() },
|
|
86
86
|
to: { month: n.getMonth(), year: n.getFullYear() }
|
|
87
87
|
}) : o && !M ? s?.({
|
|
@@ -91,7 +91,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
91
91
|
from: e?.from,
|
|
92
92
|
to: { month: n.getMonth(), year: n.getFullYear() }
|
|
93
93
|
});
|
|
94
|
-
}, lt = e?.from ? p(e.from, a) : "", dt = e?.to ? p(e.to, a) : "", ft = k !== lt, mt = D !== dt, pt = k.length === 7 && !
|
|
94
|
+
}, lt = e?.from ? p(e.from, a) : "", dt = e?.to ? p(e.to, a) : "", ft = k !== lt, mt = D !== dt, pt = k.length === 7 && !y(w(k, c, /* @__PURE__ */ new Date())), ut = D.length === 7 && !y(w(D, c, /* @__PURE__ */ new Date())), q = Y("datePicker.startMonth"), G = Y("datePicker.endMonth");
|
|
95
95
|
return /* @__PURE__ */ h("div", { className: "flex w-full min-w-[240px] flex-col gap-[6px]", "data-component": "month-range-picker", "data-disabled": m || void 0, children: [
|
|
96
96
|
/* @__PURE__ */ h("div", { className: "flex flex-col gap-[6px]", children: [
|
|
97
97
|
O && /* @__PURE__ */ h(
|
|
@@ -146,7 +146,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
146
146
|
onKeyDown: (t) => {
|
|
147
147
|
if (t.key === "Enter" && !l) {
|
|
148
148
|
t.preventDefault();
|
|
149
|
-
const f = R(k, c), r = R(D, c), n =
|
|
149
|
+
const f = R(k, c), r = R(D, c), n = w(f, c, /* @__PURE__ */ new Date()), o = w(r, c, /* @__PURE__ */ new Date()), d = y(n) && f.length === 7, C = y(o) && r.length === 7;
|
|
150
150
|
d && C ? s?.({
|
|
151
151
|
from: { month: n.getMonth(), year: n.getFullYear() },
|
|
152
152
|
to: { month: o.getMonth(), year: o.getFullYear() }
|
|
@@ -160,7 +160,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
160
160
|
}
|
|
161
161
|
t.key === "ArrowDown" && !l && !m && (t.preventDefault(), V.current = !0, g(!0)), t.key === "Escape" && l && (t.preventDefault(), K());
|
|
162
162
|
},
|
|
163
|
-
placeholder: l ? a === "YYYY/MM" ? "YYYY/MM" :
|
|
163
|
+
placeholder: l ? a === "YYYY/MM" ? "YYYY/MM" : Y("datePicker.monthYearFormat") : q,
|
|
164
164
|
disabled: !!m,
|
|
165
165
|
"aria-label": q,
|
|
166
166
|
"data-field": "start",
|
|
@@ -183,7 +183,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
183
183
|
onKeyDown: (t) => {
|
|
184
184
|
if (t.key === "Enter" && !l) {
|
|
185
185
|
t.preventDefault();
|
|
186
|
-
const f = R(k, c), r = R(D, c), n =
|
|
186
|
+
const f = R(k, c), r = R(D, c), n = w(f, c, /* @__PURE__ */ new Date()), o = w(r, c, /* @__PURE__ */ new Date()), d = y(n) && f.length === 7, C = y(o) && r.length === 7;
|
|
187
187
|
d && C ? s?.({
|
|
188
188
|
from: { month: n.getMonth(), year: n.getFullYear() },
|
|
189
189
|
to: { month: o.getMonth(), year: o.getFullYear() }
|
|
@@ -197,7 +197,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
197
197
|
}
|
|
198
198
|
t.key === "ArrowDown" && !l && !m && (t.preventDefault(), V.current = !0, g(!0)), t.key === "Escape" && l && (t.preventDefault(), K());
|
|
199
199
|
},
|
|
200
|
-
placeholder: l ? a === "YYYY/MM" ? "YYYY/MM" :
|
|
200
|
+
placeholder: l ? a === "YYYY/MM" ? "YYYY/MM" : Y("datePicker.monthYearFormat") : G,
|
|
201
201
|
disabled: !!m,
|
|
202
202
|
"aria-label": G,
|
|
203
203
|
"data-field": "end",
|
|
@@ -215,7 +215,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
215
215
|
{
|
|
216
216
|
type: "button",
|
|
217
217
|
tabIndex: 0,
|
|
218
|
-
"aria-label":
|
|
218
|
+
"aria-label": Y("calendar.clear"),
|
|
219
219
|
onClick: (t) => {
|
|
220
220
|
t.stopPropagation(), $();
|
|
221
221
|
},
|
|
@@ -226,15 +226,15 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
226
226
|
children: /* @__PURE__ */ i(ht, { className: "size-3 hover:text-content text-content-muted" })
|
|
227
227
|
}
|
|
228
228
|
) }),
|
|
229
|
-
/* @__PURE__ */ i(W, { variant: "tertiary", side: "top", children:
|
|
229
|
+
/* @__PURE__ */ i(W, { variant: "tertiary", side: "top", children: Y("calendar.clear") })
|
|
230
230
|
] }),
|
|
231
231
|
/* @__PURE__ */ h(Q, { children: [
|
|
232
|
-
/* @__PURE__ */ i(U, { asChild: !0, children: /* @__PURE__ */ i("button", { type: "button", tabIndex: 0, "aria-label":
|
|
232
|
+
/* @__PURE__ */ i(U, { asChild: !0, children: /* @__PURE__ */ i("button", { type: "button", tabIndex: 0, "aria-label": Y("datePicker.selectMonthRange"), onClick: (t) => {
|
|
233
233
|
t.stopPropagation(), m || g(!l);
|
|
234
234
|
}, onKeyDown: (t) => {
|
|
235
235
|
(t.key === "Enter" || t.key === " ") && (t.preventDefault(), t.stopPropagation(), m || (V.current = !0, g(!l)));
|
|
236
236
|
}, className: "inline-flex items-center justify-center bg-transparent border-none p-0 cursor-pointer", children: /* @__PURE__ */ i(gt, { className: "h-4 w-4 text-secondary-foreground" }) }) }),
|
|
237
|
-
/* @__PURE__ */ i(W, { variant: "tertiary", side: "top", children:
|
|
237
|
+
/* @__PURE__ */ i(W, { variant: "tertiary", side: "top", children: Y("datePicker.selectMonthRange") })
|
|
238
238
|
] })
|
|
239
239
|
] })
|
|
240
240
|
]
|
|
@@ -245,6 +245,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
245
245
|
{
|
|
246
246
|
className: "w-auto p-0",
|
|
247
247
|
align: "start",
|
|
248
|
+
"aria-label": Y("datePicker.selectMonthRange"),
|
|
248
249
|
onOpenAutoFocus: (t) => {
|
|
249
250
|
V.current || t.preventDefault(), V.current = !1;
|
|
250
251
|
},
|
|
@@ -253,7 +254,7 @@ const p = (e, s = "MM/YYYY") => {
|
|
|
253
254
|
{
|
|
254
255
|
pickerType: "month",
|
|
255
256
|
monthMode: "range",
|
|
256
|
-
selectedMonths:
|
|
257
|
+
selectedMonths: v,
|
|
257
258
|
onMonthSelect: at,
|
|
258
259
|
month: rt,
|
|
259
260
|
onMonthChange: j,
|