@adamosuiteservices/ui 2.16.1 → 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 t=require("./jsx-runtime-BB_1_6y_.cjs"),
|
|
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,35 +1,40 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { B as
|
|
3
|
-
import { b as
|
|
4
|
-
import { C as
|
|
5
|
-
import { P as w, c as B, b 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:
|
|
10
|
+
function K({
|
|
11
|
+
dateRange: t,
|
|
12
12
|
onDateRangeChange: n,
|
|
13
13
|
labels: u,
|
|
14
|
-
combobox:
|
|
15
|
-
calendar:
|
|
14
|
+
combobox: j,
|
|
15
|
+
calendar: _,
|
|
16
16
|
"aria-invalid": g,
|
|
17
|
-
disabled:
|
|
17
|
+
disabled: k
|
|
18
18
|
}) {
|
|
19
|
-
const f =
|
|
20
|
-
if (!
|
|
21
|
-
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
22
|
{ value: "7_days", days: 7 },
|
|
23
23
|
{ value: "30_days", days: 30 },
|
|
24
24
|
{ value: "90_days", days: 90 }
|
|
25
25
|
];
|
|
26
|
-
for (const r of
|
|
27
|
-
const S =
|
|
28
|
-
if (i(
|
|
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
29
|
return r.value;
|
|
30
30
|
}
|
|
31
31
|
return "custom";
|
|
32
|
-
}, [p,
|
|
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 = { ...{
|
|
33
38
|
last7Days: "Last 7 days",
|
|
34
39
|
last30Days: "Last 30 days",
|
|
35
40
|
last90Days: "Last 90 days",
|
|
@@ -37,31 +42,31 @@ function J({
|
|
|
37
42
|
placeholder: "Date",
|
|
38
43
|
cancel: "Cancel",
|
|
39
44
|
apply: "Apply"
|
|
40
|
-
}, ...u },
|
|
41
|
-
const
|
|
45
|
+
}, ...u }, R = (e) => {
|
|
46
|
+
const l = i(/* @__PURE__ */ new Date()), r = {
|
|
42
47
|
"7_days": 7,
|
|
43
48
|
"30_days": 30,
|
|
44
49
|
"90_days": 90
|
|
45
|
-
}[
|
|
46
|
-
return r ? { from:
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
}, T = (
|
|
50
|
-
if (
|
|
51
|
-
m.current = p,
|
|
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);
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
o(e), n(R(e));
|
|
55
60
|
}, O = () => {
|
|
56
61
|
if (d?.from && d?.to) {
|
|
57
|
-
n(d),
|
|
62
|
+
n(d), o("custom"), c(!1);
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
o(m.current), c(!1);
|
|
61
66
|
};
|
|
62
|
-
return /* @__PURE__ */
|
|
63
|
-
/* @__PURE__ */
|
|
64
|
-
|
|
67
|
+
return /* @__PURE__ */ a.jsxs(a.Fragment, { children: [
|
|
68
|
+
/* @__PURE__ */ a.jsx(
|
|
69
|
+
F,
|
|
65
70
|
{
|
|
66
71
|
alwaysShowPlaceholder: !0,
|
|
67
72
|
selectedFeedback: "check",
|
|
@@ -76,38 +81,38 @@ function J({
|
|
|
76
81
|
value: p,
|
|
77
82
|
onValueChange: T,
|
|
78
83
|
"aria-invalid": g,
|
|
79
|
-
disabled:
|
|
80
|
-
ref: (
|
|
81
|
-
f.current =
|
|
84
|
+
disabled: k,
|
|
85
|
+
ref: (e) => {
|
|
86
|
+
f.current = e;
|
|
82
87
|
},
|
|
83
|
-
...
|
|
88
|
+
...j
|
|
84
89
|
}
|
|
85
90
|
),
|
|
86
|
-
/* @__PURE__ */
|
|
91
|
+
/* @__PURE__ */ a.jsxs(
|
|
87
92
|
w,
|
|
88
93
|
{
|
|
89
|
-
open:
|
|
90
|
-
onOpenChange: (
|
|
91
|
-
!
|
|
94
|
+
open: L,
|
|
95
|
+
onOpenChange: (e) => {
|
|
96
|
+
!e && p === "custom" && h();
|
|
92
97
|
},
|
|
93
98
|
children: [
|
|
94
|
-
/* @__PURE__ */
|
|
95
|
-
/* @__PURE__ */
|
|
96
|
-
/* @__PURE__ */
|
|
97
|
-
|
|
99
|
+
/* @__PURE__ */ a.jsx(B, { virtualRef: f }),
|
|
100
|
+
/* @__PURE__ */ a.jsxs(E, { align: "start", children: [
|
|
101
|
+
/* @__PURE__ */ a.jsx(
|
|
102
|
+
A,
|
|
98
103
|
{
|
|
99
104
|
required: !0,
|
|
100
105
|
mode: "range",
|
|
101
106
|
selected: d,
|
|
102
|
-
onSelect:
|
|
107
|
+
onSelect: P,
|
|
103
108
|
captionLayout: "dropdown",
|
|
104
109
|
classNames: { root: "adm:p-0!" },
|
|
105
|
-
...
|
|
110
|
+
..._
|
|
106
111
|
}
|
|
107
112
|
),
|
|
108
|
-
/* @__PURE__ */
|
|
109
|
-
/* @__PURE__ */
|
|
110
|
-
/* @__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 })
|
|
111
116
|
] })
|
|
112
117
|
] })
|
|
113
118
|
]
|
|
@@ -116,5 +121,5 @@ function J({
|
|
|
116
121
|
] });
|
|
117
122
|
}
|
|
118
123
|
export {
|
|
119
|
-
|
|
124
|
+
K as DatePickerSelector
|
|
120
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:
|