impact-nova 1.6.2 → 1.6.3

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.
@@ -1,195 +1,209 @@
1
1
  import { jsxs as m, jsx as s } from "react/jsx-runtime";
2
- import * as r from "react";
3
- import { X as me } from "lucide-react";
4
- import { CalendarMonth as he, Info as ue } from "../../../icons/index.js";
5
- import { format as c, isValid as N, parse as k } from "date-fns";
6
- import { cn as C, padValidDateString as j, maskDate as B } from "../../../lib/utils.js";
7
- import { Popover as xe, PopoverTrigger as ge, PopoverContent as be } from "../popover.js";
2
+ import * as i from "react";
3
+ import { X as ue } from "lucide-react";
4
+ import { CalendarMonth as he, Info as ge } from "../../../icons/index.js";
5
+ import { format as c, isValid as P, parse as R } from "date-fns";
6
+ import { cn as N, padValidDateString as z, maskDate as H } from "../../../lib/utils.js";
7
+ import { Popover as xe, PopoverTrigger as be, PopoverContent as ye } from "../popover.js";
8
8
  import { Calendar as we } from "../calendar.js";
9
- import { Tooltip as O, TooltipTrigger as z, TooltipContent as H } from "../tooltip.js";
10
- import { getDateFnsLocale as ye } from "../../../i18n/getDateFnsLocale.js";
11
- import { useImpactNovaI18n as Pe } from "../../../i18n/ImpactNovaI18nContext.js";
12
- const Ne = r.forwardRef(
9
+ import { Tooltip as X, TooltipTrigger as q, TooltipContent as G } from "../tooltip.js";
10
+ import { getDateFnsLocale as ke } from "../../../i18n/getDateFnsLocale.js";
11
+ import { useImpactNovaI18n as De } from "../../../i18n/ImpactNovaI18nContext.js";
12
+ const Pe = i.forwardRef(
13
13
  ({
14
- value: e,
14
+ value: t,
15
15
  onChange: h,
16
- format: t = "MM/dd/yyyy",
17
- startPlaceholder: X,
18
- endPlaceholder: q,
19
- minDate: G,
20
- maxDate: J,
21
- startMonth: K,
22
- endMonth: Q,
23
- showFooter: u = !0,
24
- disabled: b,
25
- label: v,
26
- helperText: V,
27
- prefix: ke,
28
- prefixClick: Ce,
29
- isError: D,
30
- size: M,
31
- required: U,
32
- className: W,
33
- ...Y
34
- }, Z) => {
35
- const { locale: E, t: S } = Pe(), o = r.useMemo(() => ye(E), [E]), $ = X ?? S("datePicker.startDate"), _ = q ?? S("datePicker.endDate"), T = r.useRef(null), F = r.useRef(null);
36
- r.useRef(null), r.useRef(null), r.useImperativeHandle(Z, () => T.current);
37
- const [d, R] = r.useState(!1), [w, p] = r.useState(e), [y, x] = r.useState(e?.from ? c(e.from, t, { locale: o }) : ""), [P, g] = r.useState(e?.to ? c(e.to, t, { locale: o }) : ""), [ee, I] = r.useState(e?.from || /* @__PURE__ */ new Date());
38
- r.useEffect(() => {
39
- d || (x(e?.from ? c(e.from, t, { locale: o }) : ""), g(e?.to ? c(e.to, t, { locale: o }) : ""), p(e));
40
- }, [e, t, d, o]), r.useEffect(() => {
41
- d && (p(e), x(e?.from ? c(e.from, t, { locale: o }) : ""), g(e?.to ? c(e.to, t, { locale: o }) : ""), I(e?.from || /* @__PURE__ */ new Date()));
42
- }, [d, e, t, o]);
43
- const te = (n) => {
44
- p(n), n?.from && x(c(n.from, t, { locale: o })), n?.to && g(c(n.to, t, { locale: o })), u || n?.from && n?.to && n.from.getTime() !== n.to.getTime() && (h?.(n), R(!1));
45
- }, ne = (n) => {
46
- let l = n !== void 0 ? n : w;
47
- l?.from && !l.to && (l = { from: l.from, to: l.from }), h?.(l), R(!1);
48
- }, oe = () => {
49
- p(e), x(e?.from ? c(e.from, t, { locale: o }) : ""), g(e?.to ? c(e.to, t, { locale: o }) : ""), R(!1);
50
- }, A = () => {
51
- p(void 0), x(""), g(""), h?.(void 0), u || R(!1);
52
- }, le = (n) => {
53
- const l = n.target.value, a = B(l, t, y);
54
- if (x(a), a === "") {
55
- const i = { from: void 0, to: w?.to };
56
- p(i), u || h?.(i);
16
+ format: n = "MM/dd/yyyy",
17
+ startPlaceholder: J,
18
+ endPlaceholder: Q,
19
+ minDate: U,
20
+ maxDate: W,
21
+ startMonth: Y,
22
+ endMonth: Z,
23
+ showFooter: g = !0,
24
+ disabled: y,
25
+ label: V,
26
+ helperText: M,
27
+ prefix: Re,
28
+ prefixClick: Ne,
29
+ isError: v,
30
+ size: T,
31
+ required: $,
32
+ className: _,
33
+ ...F
34
+ }, ee) => {
35
+ const { locale: A, t: C } = De(), o = i.useMemo(() => ke(A), [A]), j = J ?? C("datePicker.startDate"), K = Q ?? C("datePicker.endDate"), L = i.useRef(null), te = i.useRef(null);
36
+ i.useRef(null), i.useRef(null), i.useImperativeHandle(ee, () => L.current);
37
+ const [r, u] = i.useState(!1), I = i.useRef(!1), [w, p] = i.useState(t), [k, x] = i.useState(t?.from ? c(t.from, n, { locale: o }) : ""), [D, b] = i.useState(t?.to ? c(t.to, n, { locale: o }) : ""), [ne, S] = i.useState(t?.from || /* @__PURE__ */ new Date());
38
+ i.useEffect(() => {
39
+ r || (x(t?.from ? c(t.from, n, { locale: o }) : ""), b(t?.to ? c(t.to, n, { locale: o }) : ""), p(t));
40
+ }, [t, n, r, o]), i.useEffect(() => {
41
+ r && (p(t), x(t?.from ? c(t.from, n, { locale: o }) : ""), b(t?.to ? c(t.to, n, { locale: o }) : ""), S(t?.from || /* @__PURE__ */ new Date()));
42
+ }, [r, t, n, o]);
43
+ const oe = (e) => {
44
+ p(e), e?.from && x(c(e.from, n, { locale: o })), e?.to && b(c(e.to, n, { locale: o })), g || e?.from && e?.to && e.from.getTime() !== e.to.getTime() && (h?.(e), u(!1));
45
+ }, re = (e) => {
46
+ let l = e !== void 0 ? e : w;
47
+ l?.from && !l.to && (l = { from: l.from, to: l.from }), h?.(l), u(!1);
48
+ }, E = () => {
49
+ p(t), x(t?.from ? c(t.from, n, { locale: o }) : ""), b(t?.to ? c(t.to, n, { locale: o }) : ""), u(!1);
50
+ }, B = () => {
51
+ p(void 0), x(""), b(""), h?.(void 0), g || u(!1);
52
+ }, le = (e) => {
53
+ const l = e.target.value, d = H(l, n, k);
54
+ if (x(d), d === "") {
55
+ const a = { from: void 0, to: w?.to };
56
+ p(a), g || h?.(a);
57
57
  return;
58
58
  }
59
- const f = k(a, t, /* @__PURE__ */ new Date(), { locale: o });
60
- if (N(f) && a.length === t.length) {
61
- const i = { from: f, to: w?.to };
62
- p(i), I(f), u || h?.(i);
59
+ const f = R(d, n, /* @__PURE__ */ new Date(), { locale: o });
60
+ if (P(f) && d.length === n.length) {
61
+ const a = { from: f, to: w?.to };
62
+ p(a), S(f), g || h?.(a);
63
63
  }
64
- }, se = (n) => {
65
- const l = n.target.value, a = B(l, t, P);
66
- if (g(a), a === "") {
67
- const i = { from: w?.from, to: void 0 };
68
- p(i), u || h?.(i);
64
+ }, se = (e) => {
65
+ const l = e.target.value, d = H(l, n, D);
66
+ if (b(d), d === "") {
67
+ const a = { from: w?.from, to: void 0 };
68
+ p(a), g || h?.(a);
69
69
  return;
70
70
  }
71
- const f = k(a, t, /* @__PURE__ */ new Date(), { locale: o });
72
- if (N(f) && a.length === t.length) {
73
- const i = { from: w?.from, to: f };
74
- p(i), f && I(f), u || h?.(i);
71
+ const f = R(d, n, /* @__PURE__ */ new Date(), { locale: o });
72
+ if (P(f) && d.length === n.length) {
73
+ const a = { from: w?.from, to: f };
74
+ p(a), f && S(f), g || h?.(a);
75
75
  }
76
- }, L = () => {
77
- if (d) return;
78
- const n = j(y, t), l = j(P, t), a = k(n, t, /* @__PURE__ */ new Date(), { locale: o }), f = k(l, t, /* @__PURE__ */ new Date(), { locale: o }), i = N(a) && n.length === t.length, pe = N(f) && l.length === t.length;
79
- !i || !pe ? (x(e?.from ? c(e.from, t, { locale: o }) : ""), g(e?.to ? c(e.to, t, { locale: o }) : ""), p(e)) : (x(n), g(l), u || h?.({ from: a, to: f }));
80
- }, re = e?.from ? c(e.from, t, { locale: o }) : "", ce = e?.to ? c(e.to, t, { locale: o }) : "", ie = y !== re, ae = P !== ce, de = y.length === t.length && !N(k(y, t, /* @__PURE__ */ new Date(), { locale: o })), fe = P.length === t.length && !N(k(P, t, /* @__PURE__ */ new Date(), { locale: o }));
81
- return /* @__PURE__ */ m("div", { className: "flex w-full min-w-[240px] flex-col gap-[6px]", "data-component": "date-range-picker", "data-disabled": b || void 0, children: [
76
+ }, O = () => {
77
+ if (r) return;
78
+ const e = z(k, n), l = z(D, n), d = R(e, n, /* @__PURE__ */ new Date(), { locale: o }), f = R(l, n, /* @__PURE__ */ new Date(), { locale: o }), a = P(d) && e.length === n.length, me = P(f) && l.length === n.length;
79
+ !a || !me ? (x(t?.from ? c(t.from, n, { locale: o }) : ""), b(t?.to ? c(t.to, n, { locale: o }) : ""), p(t)) : (x(e), b(l), g || h?.({ from: d, to: f }));
80
+ }, ie = t?.from ? c(t.from, n, { locale: o }) : "", ce = t?.to ? c(t.to, n, { locale: o }) : "", ae = k !== ie, de = D !== ce, fe = k.length === n.length && !P(R(k, n, /* @__PURE__ */ new Date(), { locale: o })), pe = D.length === n.length && !P(R(D, n, /* @__PURE__ */ new Date(), { locale: o }));
81
+ return /* @__PURE__ */ m("div", { className: "flex w-full min-w-[240px] flex-col gap-[6px]", "data-component": "date-range-picker", "data-disabled": y || void 0, children: [
82
82
  /* @__PURE__ */ m("div", { className: "flex flex-col gap-[6px]", children: [
83
- v && /* @__PURE__ */ m(
83
+ V && /* @__PURE__ */ m(
84
84
  "label",
85
85
  {
86
- className: C(
86
+ className: N(
87
87
  "text-xs font-medium leading-[18px] text-content-tertiary",
88
- b && "opacity-70",
89
- D && "text-destructive"
88
+ y && "opacity-70",
89
+ v && "text-destructive"
90
90
  ),
91
91
  children: [
92
- v,
92
+ V,
93
93
  " ",
94
- U && /* @__PURE__ */ s("span", { className: "text-destructive", children: "*" })
94
+ $ && /* @__PURE__ */ s("span", { className: "text-destructive", children: "*" })
95
95
  ]
96
96
  }
97
97
  ),
98
- /* @__PURE__ */ m(xe, { open: d, onOpenChange: R, children: [
99
- /* @__PURE__ */ s(ge, { asChild: !0, children: /* @__PURE__ */ m(
98
+ /* @__PURE__ */ m(xe, { open: r, onOpenChange: u, children: [
99
+ /* @__PURE__ */ s(be, { asChild: !0, children: /* @__PURE__ */ m(
100
100
  "div",
101
101
  {
102
- "data-state": d ? "open" : "closed",
103
- className: C(
102
+ "data-state": r ? "open" : "closed",
103
+ className: N(
104
104
  "flex w-full items-center justify-between gap-2 rounded-md border bg-canvas-elevated px-3 text-sm shadow-sm transition-colors hover:border-brand disabled:cursor-not-allowed disabled:bg-disabled-surface disabled:text-disabled-foreground disabled:border-stroke",
105
- D ? "border-destructive hover:border-destructive" : "border-field",
106
- M === "sm" ? "h-6" : M === "md" ? "h-[28px]" : "h-8",
107
- b && "pointer-events-none opacity-100 bg-disabled-surface border-stroke text-disabled-foreground hover:border-stroke",
105
+ v ? "border-destructive hover:border-destructive" : "border-field",
106
+ T === "sm" ? "h-6" : T === "md" ? "h-[28px]" : "h-8",
107
+ y && "pointer-events-none opacity-100 bg-disabled-surface border-stroke text-disabled-foreground hover:border-stroke",
108
108
  "cursor-pointer",
109
- W
109
+ _
110
110
  ),
111
111
  children: [
112
112
  /* @__PURE__ */ m("div", { className: "flex items-center gap-4 flex-1 min-w-0", children: [
113
113
  /* @__PURE__ */ s(
114
114
  "input",
115
115
  {
116
- ref: T,
116
+ ref: L,
117
117
  type: "text",
118
- value: y,
118
+ value: k,
119
119
  onChange: le,
120
- onBlur: L,
121
- onClick: (n) => d && n.stopPropagation(),
122
- placeholder: d ? t : $,
123
- disabled: !!b,
120
+ onBlur: O,
121
+ onClick: (e) => r && e.stopPropagation(),
122
+ onKeyDown: (e) => {
123
+ (e.key === "Enter" || e.key === "ArrowDown") && !r && (e.preventDefault(), I.current = !0, u(!0)), e.key === "Escape" && r && (e.preventDefault(), E());
124
+ },
125
+ placeholder: r ? n : j,
126
+ disabled: !!y,
127
+ "aria-label": j,
124
128
  "data-field": "start",
125
- className: C(
129
+ className: N(
126
130
  "flex-1 min-w-0 bg-transparent p-0 text-sm font-medium outline-none placeholder:font-medium placeholder:text-content-empty disabled:cursor-not-allowed disabled:opacity-50",
127
- de ? "text-destructive" : ie ? "text-content-muted" : ""
131
+ fe ? "text-destructive" : ae ? "text-content-muted" : ""
128
132
  ),
129
- ...Y
133
+ ...F
130
134
  }
131
135
  ),
132
136
  /* @__PURE__ */ s(
133
137
  "input",
134
138
  {
135
- ref: F,
139
+ ref: te,
136
140
  type: "text",
137
- value: P,
141
+ value: D,
138
142
  onChange: se,
139
- onBlur: L,
140
- onClick: (n) => d && n.stopPropagation(),
141
- placeholder: d ? t : _,
142
- disabled: !!b,
143
+ onBlur: O,
144
+ onClick: (e) => r && e.stopPropagation(),
145
+ onKeyDown: (e) => {
146
+ (e.key === "Enter" || e.key === "ArrowDown") && !r && (e.preventDefault(), I.current = !0, u(!0)), e.key === "Escape" && r && (e.preventDefault(), E());
147
+ },
148
+ placeholder: r ? n : K,
149
+ disabled: !!y,
150
+ "aria-label": K,
143
151
  "data-field": "end",
144
- className: C(
152
+ className: N(
145
153
  "flex-1 min-w-0 bg-transparent p-0 text-sm font-medium outline-none placeholder:font-medium placeholder:text-content-empty disabled:cursor-not-allowed disabled:opacity-50",
146
- fe ? "text-destructive" : ae ? "text-content-muted" : ""
154
+ pe ? "text-destructive" : de ? "text-content-muted" : ""
147
155
  )
148
156
  }
149
157
  )
150
158
  ] }),
151
159
  /* @__PURE__ */ m("div", { className: "flex items-center gap-1 shrink-0", children: [
152
- e?.from && !b && /* @__PURE__ */ m(O, { children: [
153
- /* @__PURE__ */ s(z, { asChild: !0, children: /* @__PURE__ */ s(
154
- me,
160
+ t?.from && !y && /* @__PURE__ */ m(X, { children: [
161
+ /* @__PURE__ */ s(q, { asChild: !0, children: /* @__PURE__ */ s(
162
+ ue,
155
163
  {
156
164
  className: "h-4 w-4 cursor-pointer hover:text-content text-content-muted",
157
- onClick: (n) => {
158
- n.stopPropagation(), A();
165
+ onClick: (e) => {
166
+ e.stopPropagation(), B();
159
167
  }
160
168
  }
161
169
  ) }),
162
- /* @__PURE__ */ s(H, { variant: "tertiary", side: "top", children: S("calendar.clear") })
170
+ /* @__PURE__ */ s(G, { variant: "tertiary", side: "top", children: C("calendar.clear") })
163
171
  ] }),
164
- /* @__PURE__ */ m(O, { children: [
165
- /* @__PURE__ */ s(z, { asChild: !0, children: /* @__PURE__ */ s(he, { className: "h-4 w-4 text-secondary-foreground" }) }),
166
- /* @__PURE__ */ s(H, { variant: "tertiary", side: "top", children: S("datePicker.selectMonthRange") })
172
+ /* @__PURE__ */ m(X, { children: [
173
+ /* @__PURE__ */ s(q, { asChild: !0, children: /* @__PURE__ */ s("button", { type: "button", tabIndex: 0, "aria-label": C("datePicker.selectMonthRange"), onClick: (e) => {
174
+ e.stopPropagation(), u(!r);
175
+ }, onKeyDown: (e) => {
176
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), e.stopPropagation(), I.current = !0, u(!r));
177
+ }, className: "inline-flex items-center justify-center bg-transparent border-none p-0 cursor-pointer", children: /* @__PURE__ */ s(he, { className: "h-4 w-4 text-secondary-foreground" }) }) }),
178
+ /* @__PURE__ */ s(G, { variant: "tertiary", side: "top", children: C("datePicker.selectMonthRange") })
167
179
  ] })
168
180
  ] })
169
181
  ]
170
182
  }
171
183
  ) }),
172
184
  /* @__PURE__ */ s(
173
- be,
185
+ ye,
174
186
  {
175
187
  className: "w-auto p-0",
176
188
  align: "start",
177
- onOpenAutoFocus: (n) => n.preventDefault(),
189
+ onOpenAutoFocus: (e) => {
190
+ I.current || e.preventDefault(), I.current = !1;
191
+ },
178
192
  children: /* @__PURE__ */ s(
179
193
  we,
180
194
  {
181
195
  mode: "range",
182
196
  selected: w,
183
- onSelect: te,
184
- month: ee,
185
- onMonthChange: I,
186
- disabled: { before: G, after: J },
187
- startMonth: K,
188
- endMonth: Q,
189
- showFooter: u,
190
- onApply: ne,
191
- onCancel: oe,
192
- onClear: A,
197
+ onSelect: oe,
198
+ month: ne,
199
+ onMonthChange: S,
200
+ disabled: { before: U, after: W },
201
+ startMonth: Y,
202
+ endMonth: Z,
203
+ showFooter: g,
204
+ onApply: re,
205
+ onCancel: E,
206
+ onClear: B,
193
207
  captionLayout: "dropdown"
194
208
  }
195
209
  )
@@ -197,23 +211,23 @@ const Ne = r.forwardRef(
197
211
  )
198
212
  ] })
199
213
  ] }),
200
- V && /* @__PURE__ */ m("div", { className: C("flex items-center gap-[6px]", D && "text-destructive"), children: [
201
- !D && /* @__PURE__ */ s(ue, { size: 10, className: "shrink-0 text-content-muted" }),
214
+ M && /* @__PURE__ */ m("div", { className: N("flex items-center gap-[6px]", v && "text-destructive"), children: [
215
+ !v && /* @__PURE__ */ s(ge, { size: 10, className: "shrink-0 text-content-muted" }),
202
216
  /* @__PURE__ */ s(
203
217
  "p",
204
218
  {
205
- className: C(
219
+ className: N(
206
220
  "text-[10px] leading-4 text-navigation-muted",
207
- D && "text-destructive"
221
+ v && "text-destructive"
208
222
  ),
209
- children: V
223
+ children: M
210
224
  }
211
225
  )
212
226
  ] })
213
227
  ] });
214
228
  }
215
229
  );
216
- Ne.displayName = "DateRangePicker";
230
+ Pe.displayName = "DateRangePicker";
217
231
  export {
218
- Ne as DateRangePicker
232
+ Pe as DateRangePicker
219
233
  };