@adamosuiteservices/ui 2.16.0 → 2.16.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BB_1_6y_.cjs"),h=require("./button-DVrteFz9.cjs"),n=require("./calendar-CpUN6BGK.cjs"),L=require("./combobox-BalI1GHE.cjs"),x=require("./popover-cGp_rNLg.cjs"),r=require("react");function D(a,u,m){return n.addDays(a,-u,m)}function T({dateRange:a,onDateRangeChange:u,labels:m,combobox:R,calendar:C,"aria-invalid":g,disabled:E}){const f=r.useRef(null),p=r.useRef(void 0),v=e=>{if(!e.from||!e.to)return;const l=n.startOfDay(new Date),j=[{value:"7_days",days:7},{value:"30_days",days:30},{value:"90_days",days:90}];for(const c of j){const q=D(l,c.days);if(n.startOfDay(e.from).getTime()===q.getTime()&&n.startOfDay(e.to).getTime()===l.getTime())return c.value}return"custom"},[y,o]=r.useState(()=>v(a)),[_,d]=r.useState(!1),[i,S]=r.useState(a);r.useEffect(()=>{const e=v(a);o(e)},[a]);const s={...{last7Days:"Last 7 days",last30Days:"Last 30 days",last90Days:"Last 90 days",custom:"Custom",placeholder:"Date",cancel:"Cancel",apply:"Apply"},...m},k=e=>{const l=n.startOfDay(new Date),c={"7_days":7,"30_days":30,"90_days":90}[e];return c?{from:D(l,c),to:l}:{from:void 0,to:void 0}},b=e=>{o(p.current),d(!1)},O=e=>{if(e==="custom"){p.current=y,o(e),d(!0);return}o(e),u(k(e))},P=()=>{if(i?.from&&i?.to){u(i),o("custom"),d(!1);return}o(p.current),d(!1)};return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(L.Combobox,{alwaysShowPlaceholder:!0,selectedFeedback:"check",icon:"calendar_today",options:[{label:s.last7Days,value:"7_days"},{label:s.last30Days,value:"30_days"},{label:s.last90Days,value:"90_days"},{label:s.custom,value:"custom"}],labels:{placeholder:s.placeholder},value:y,onValueChange:O,"aria-invalid":g,disabled:E,ref:e=>{f.current=e},...R}),t.jsxRuntimeExports.jsxs(x.Popover,{open:_,onOpenChange:e=>{!e&&y==="custom"&&b()},children:[t.jsxRuntimeExports.jsx(x.PopoverAnchor,{virtualRef:f}),t.jsxRuntimeExports.jsxs(x.PopoverContent,{align:"start",children:[t.jsxRuntimeExports.jsx(n.Calendar,{required:!0,mode:"range",selected:i,onSelect:S,captionLayout:"dropdown",classNames:{root:"adm:p-0!"},...C}),t.jsxRuntimeExports.jsxs("div",{className:"adm:mt-2 adm:flex adm:justify-end adm:gap-2",children:[t.jsxRuntimeExports.jsx(h.Button,{variant:"link",onClick:()=>b(),children:s.cancel}),t.jsxRuntimeExports.jsx(h.Button,{variant:"link",onClick:P,children:s.apply})]})]})]})]})}exports.DatePickerSelector=T;
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { B as
|
|
3
|
-
import { b as
|
|
4
|
-
import { C as
|
|
5
|
-
import { P as
|
|
6
|
-
import { useRef as
|
|
7
|
-
function
|
|
8
|
-
return
|
|
1
|
+
import { j as a } from "./jsx-runtime-BzflLqGi.js";
|
|
2
|
+
import { B as x } from "./button-B0lWuG-D.js";
|
|
3
|
+
import { b as V, C as A, s as i } from "./calendar-CfqtuOWv.js";
|
|
4
|
+
import { C as F } from "./combobox-CtSJw4m1.js";
|
|
5
|
+
import { P as w, c as B, b as E } from "./popover-DcQ18EVl.js";
|
|
6
|
+
import { useRef as D, useState as y, useEffect as M } from "react";
|
|
7
|
+
function C(t, n, u) {
|
|
8
|
+
return V(t, -n, u);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
dateRange:
|
|
12
|
-
onDateRangeChange:
|
|
13
|
-
labels:
|
|
14
|
-
combobox:
|
|
15
|
-
calendar:
|
|
16
|
-
"aria-invalid":
|
|
17
|
-
disabled:
|
|
10
|
+
function K({
|
|
11
|
+
dateRange: t,
|
|
12
|
+
onDateRangeChange: n,
|
|
13
|
+
labels: u,
|
|
14
|
+
combobox: j,
|
|
15
|
+
calendar: _,
|
|
16
|
+
"aria-invalid": g,
|
|
17
|
+
disabled: k
|
|
18
18
|
}) {
|
|
19
|
-
const
|
|
19
|
+
const f = D(null), m = D(void 0), v = (e) => {
|
|
20
|
+
if (!e.from || !e.to) return;
|
|
21
|
+
const l = i(/* @__PURE__ */ new Date()), b = [
|
|
22
|
+
{ value: "7_days", days: 7 },
|
|
23
|
+
{ value: "30_days", days: 30 },
|
|
24
|
+
{ value: "90_days", days: 90 }
|
|
25
|
+
];
|
|
26
|
+
for (const r of b) {
|
|
27
|
+
const S = C(l, r.days);
|
|
28
|
+
if (i(e.from).getTime() === S.getTime() && i(e.to).getTime() === l.getTime())
|
|
29
|
+
return r.value;
|
|
30
|
+
}
|
|
31
|
+
return "custom";
|
|
32
|
+
}, [p, o] = y(() => v(t)), [L, c] = y(!1), [d, P] = y(t);
|
|
33
|
+
M(() => {
|
|
34
|
+
const e = v(t);
|
|
35
|
+
o(e);
|
|
36
|
+
}, [t]);
|
|
37
|
+
const s = { ...{
|
|
20
38
|
last7Days: "Last 7 days",
|
|
21
39
|
last30Days: "Last 30 days",
|
|
22
40
|
last90Days: "Last 90 days",
|
|
@@ -24,31 +42,31 @@ function H({
|
|
|
24
42
|
placeholder: "Date",
|
|
25
43
|
cancel: "Cancel",
|
|
26
44
|
apply: "Apply"
|
|
27
|
-
}, ...
|
|
28
|
-
const
|
|
45
|
+
}, ...u }, R = (e) => {
|
|
46
|
+
const l = i(/* @__PURE__ */ new Date()), r = {
|
|
29
47
|
"7_days": 7,
|
|
30
48
|
"30_days": 30,
|
|
31
49
|
"90_days": 90
|
|
32
|
-
}[
|
|
33
|
-
return
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
if (
|
|
38
|
-
|
|
50
|
+
}[e];
|
|
51
|
+
return r ? { from: C(l, r), to: l } : { from: void 0, to: void 0 };
|
|
52
|
+
}, h = (e) => {
|
|
53
|
+
o(m.current), c(!1);
|
|
54
|
+
}, T = (e) => {
|
|
55
|
+
if (e === "custom") {
|
|
56
|
+
m.current = p, o(e), c(!0);
|
|
39
57
|
return;
|
|
40
58
|
}
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
if (
|
|
44
|
-
|
|
59
|
+
o(e), n(R(e));
|
|
60
|
+
}, O = () => {
|
|
61
|
+
if (d?.from && d?.to) {
|
|
62
|
+
n(d), o("custom"), c(!1);
|
|
45
63
|
return;
|
|
46
64
|
}
|
|
47
|
-
|
|
65
|
+
o(m.current), c(!1);
|
|
48
66
|
};
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
/* @__PURE__ */
|
|
51
|
-
|
|
67
|
+
return /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
|
|
68
|
+
/* @__PURE__ */ a.jsx(
|
|
69
|
+
F,
|
|
52
70
|
{
|
|
53
71
|
alwaysShowPlaceholder: !0,
|
|
54
72
|
selectedFeedback: "check",
|
|
@@ -60,41 +78,41 @@ function H({
|
|
|
60
78
|
{ label: s.custom, value: "custom" }
|
|
61
79
|
],
|
|
62
80
|
labels: { placeholder: s.placeholder },
|
|
63
|
-
value:
|
|
64
|
-
onValueChange:
|
|
65
|
-
"aria-invalid":
|
|
66
|
-
disabled:
|
|
67
|
-
ref: (
|
|
68
|
-
|
|
81
|
+
value: p,
|
|
82
|
+
onValueChange: T,
|
|
83
|
+
"aria-invalid": g,
|
|
84
|
+
disabled: k,
|
|
85
|
+
ref: (e) => {
|
|
86
|
+
f.current = e;
|
|
69
87
|
},
|
|
70
|
-
...
|
|
88
|
+
...j
|
|
71
89
|
}
|
|
72
90
|
),
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
-
|
|
91
|
+
/* @__PURE__ */ a.jsxs(
|
|
92
|
+
w,
|
|
75
93
|
{
|
|
76
|
-
open:
|
|
77
|
-
onOpenChange: (
|
|
78
|
-
!
|
|
94
|
+
open: L,
|
|
95
|
+
onOpenChange: (e) => {
|
|
96
|
+
!e && p === "custom" && h();
|
|
79
97
|
},
|
|
80
98
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
82
|
-
/* @__PURE__ */
|
|
83
|
-
/* @__PURE__ */
|
|
84
|
-
|
|
99
|
+
/* @__PURE__ */ a.jsx(B, { virtualRef: f }),
|
|
100
|
+
/* @__PURE__ */ a.jsxs(E, { align: "start", children: [
|
|
101
|
+
/* @__PURE__ */ a.jsx(
|
|
102
|
+
A,
|
|
85
103
|
{
|
|
86
104
|
required: !0,
|
|
87
105
|
mode: "range",
|
|
88
|
-
selected:
|
|
89
|
-
onSelect:
|
|
106
|
+
selected: d,
|
|
107
|
+
onSelect: P,
|
|
90
108
|
captionLayout: "dropdown",
|
|
91
109
|
classNames: { root: "adm:p-0!" },
|
|
92
|
-
...
|
|
110
|
+
..._
|
|
93
111
|
}
|
|
94
112
|
),
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ a.jsxs("div", { className: "adm:mt-2 adm:flex adm:justify-end adm:gap-2", children: [
|
|
114
|
+
/* @__PURE__ */ a.jsx(x, { variant: "link", onClick: () => h(), children: s.cancel }),
|
|
115
|
+
/* @__PURE__ */ a.jsx(x, { variant: "link", onClick: O, children: s.apply })
|
|
98
116
|
] })
|
|
99
117
|
] })
|
|
100
118
|
]
|
|
@@ -103,5 +121,5 @@ function H({
|
|
|
103
121
|
] });
|
|
104
122
|
}
|
|
105
123
|
export {
|
|
106
|
-
|
|
124
|
+
K as DatePickerSelector
|
|
107
125
|
};
|
|
@@ -226,6 +226,48 @@ function MyComponent() {
|
|
|
226
226
|
}
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
+
### Con Botón de Reset
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
import { Button } from "@adamosuiteservices/ui/button";
|
|
233
|
+
import { startOfDay, subDays } from "date-fns";
|
|
234
|
+
|
|
235
|
+
function MyComponent() {
|
|
236
|
+
const today = startOfDay(new Date());
|
|
237
|
+
const [dateRange, setDateRange] = useState<DateRange>({
|
|
238
|
+
from: subDays(today, 30),
|
|
239
|
+
to: today,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const handleReset = () => {
|
|
243
|
+
setDateRange({
|
|
244
|
+
from: undefined,
|
|
245
|
+
to: undefined,
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const hasSelection = dateRange.from || dateRange.to;
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<div className="flex items-center gap-2">
|
|
253
|
+
<DatePickerSelector
|
|
254
|
+
dateRange={dateRange}
|
|
255
|
+
onDateRangeChange={setDateRange}
|
|
256
|
+
/>
|
|
257
|
+
<Button
|
|
258
|
+
variant="outline"
|
|
259
|
+
onClick={handleReset}
|
|
260
|
+
disabled={!hasSelection}
|
|
261
|
+
>
|
|
262
|
+
Reset
|
|
263
|
+
</Button>
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**Comportamiento**: El componente se sincroniza automáticamente con cambios externos en `dateRange` gracias al hook `useEffect` interno. Cuando se resetea el rango externamente, el combobox muestra el placeholder automáticamente.
|
|
270
|
+
|
|
229
271
|
### Validación de Rango
|
|
230
272
|
|
|
231
273
|
```tsx
|
|
@@ -317,6 +359,26 @@ El selector de fechas dentro de un `<fieldset disabled>` automáticamente hereda
|
|
|
317
359
|
|
|
318
360
|
## Comportamiento
|
|
319
361
|
|
|
362
|
+
### Sincronización de Estado
|
|
363
|
+
|
|
364
|
+
El componente sincroniza automáticamente su estado interno con el prop `dateRange` mediante un `useEffect`. Esto significa que:
|
|
365
|
+
|
|
366
|
+
- ✅ Cambios externos a `dateRange` actualizan el combobox automáticamente
|
|
367
|
+
- ✅ Resetear el rango externamente (e.g., botón Reset) actualiza la UI correctamente
|
|
368
|
+
- ✅ Formularios que limpian campos funcionan sin configuración adicional
|
|
369
|
+
- ✅ No requiere controlar manualmente el estado del combobox
|
|
370
|
+
|
|
371
|
+
**Ejemplo de sincronización:**
|
|
372
|
+
```tsx
|
|
373
|
+
// Resetear desde código externo
|
|
374
|
+
setDateRange({ from: undefined, to: undefined });
|
|
375
|
+
// → El combobox mostrará automáticamente el placeholder
|
|
376
|
+
|
|
377
|
+
// Establecer un rango predefinido
|
|
378
|
+
setDateRange({ from: subDays(new Date(), 7), to: new Date() });
|
|
379
|
+
// → El combobox detectará y mostrará "Last 7 days"
|
|
380
|
+
```
|
|
381
|
+
|
|
320
382
|
### Rangos Predefinidos
|
|
321
383
|
|
|
322
384
|
El componente ofrece tres rangos predefinidos:
|