@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"),j=require("./button-DVrteFz9.cjs"),s=require("./calendar-CpUN6BGK.cjs"),L=require("./combobox-BalI1GHE.cjs"),x=require("./popover-cGp_rNLg.cjs"),l=require("react");function R(c,u,m){return s.addDays(c,-u,m)}function T({dateRange:c,onDateRangeChange:u,labels:m,combobox:h,calendar:D,"aria-invalid":g,disabled:C}){const f=l.useRef(null),p=l.useRef(void 0),E=e=>{if(!e.from||!e.to)return;const r=s.startOfDay(new Date),b=[{value:"7_days",days:7},{value:"30_days",days:30},{value:"90_days",days:90}];for(const n of b){const q=R(r,n.days);if(s.startOfDay(e.from).getTime()===q.getTime()&&s.startOfDay(e.to).getTime()===r.getTime())return n.value}return"custom"},[y,o]=l.useState(()=>E(c)),[_,d]=l.useState(!1),[i,S]=l.useState(c),a={...{last7Days:"Last 7 days",last30Days:"Last 30 days",last90Days:"Last 90 days",custom:"Custom",placeholder:"Date",cancel:"Cancel",apply:"Apply"},...m},k=e=>{const r=s.startOfDay(new Date),n={"7_days":7,"30_days":30,"90_days":90}[e];return n?{from:R(r,n),to:r}:{from:void 0,to:void 0}},v=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:a.last7Days,value:"7_days"},{label:a.last30Days,value:"30_days"},{label:a.last90Days,value:"90_days"},{label:a.custom,value:"custom"}],labels:{placeholder:a.placeholder},value:y,onValueChange:O,"aria-invalid":g,disabled:C,ref:e=>{f.current=e},...h}),t.jsxRuntimeExports.jsxs(x.Popover,{open:_,onOpenChange:e=>{!e&&y==="custom"&&v()},children:[t.jsxRuntimeExports.jsx(x.PopoverAnchor,{virtualRef:f}),t.jsxRuntimeExports.jsxs(x.PopoverContent,{align:"start",children:[t.jsxRuntimeExports.jsx(s.Calendar,{required:!0,mode:"range",selected:i,onSelect:S,captionLayout:"dropdown",classNames:{root:"adm:p-0!"},...D}),t.jsxRuntimeExports.jsxs("div",{className:"adm:mt-2 adm:flex adm:justify-end adm:gap-2",children:[t.jsxRuntimeExports.jsx(j.Button,{variant:"link",onClick:()=>v(),children:a.cancel}),t.jsxRuntimeExports.jsx(j.Button,{variant:"link",onClick:P,children:a.apply})]})]})]})]})}exports.DatePickerSelector=T;
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 e } from "./jsx-runtime-BzflLqGi.js";
2
- import { B as b } from "./button-B0lWuG-D.js";
3
- import { b as A, C as F, s as i } from "./calendar-CfqtuOWv.js";
4
- import { C as V } from "./combobox-CtSJw4m1.js";
5
- import { P as w, c as B, b as M } from "./popover-DcQ18EVl.js";
6
- import { useRef as x, useState as y } from "react";
7
- function D(l, n, u) {
8
- return A(l, -n, u);
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 J({
11
- dateRange: l,
10
+ function K({
11
+ dateRange: t,
12
12
  onDateRangeChange: n,
13
13
  labels: u,
14
- combobox: C,
15
- calendar: j,
14
+ combobox: j,
15
+ calendar: _,
16
16
  "aria-invalid": g,
17
- disabled: _
17
+ disabled: k
18
18
  }) {
19
- const f = x(null), m = x(void 0), R = (a) => {
20
- if (!a.from || !a.to) return;
21
- const o = i(/* @__PURE__ */ new Date()), h = [
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 h) {
27
- const S = D(o, r.days);
28
- if (i(a.from).getTime() === S.getTime() && i(a.to).getTime() === o.getTime())
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, t] = y(() => R(l)), [k, c] = y(!1), [d, L] = y(l), s = { ...{
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 }, P = (a) => {
41
- const o = i(/* @__PURE__ */ new Date()), r = {
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
- }[a];
46
- return r ? { from: D(o, r), to: o } : { from: void 0, to: void 0 };
47
- }, v = (a) => {
48
- t(m.current), c(!1);
49
- }, T = (a) => {
50
- if (a === "custom") {
51
- m.current = p, t(a), c(!0);
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
- t(a), n(P(a));
59
+ o(e), n(R(e));
55
60
  }, O = () => {
56
61
  if (d?.from && d?.to) {
57
- n(d), t("custom"), c(!1);
62
+ n(d), o("custom"), c(!1);
58
63
  return;
59
64
  }
60
- t(m.current), c(!1);
65
+ o(m.current), c(!1);
61
66
  };
62
- return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
63
- /* @__PURE__ */ e.jsx(
64
- V,
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: (a) => {
81
- f.current = a;
84
+ disabled: k,
85
+ ref: (e) => {
86
+ f.current = e;
82
87
  },
83
- ...C
88
+ ...j
84
89
  }
85
90
  ),
86
- /* @__PURE__ */ e.jsxs(
91
+ /* @__PURE__ */ a.jsxs(
87
92
  w,
88
93
  {
89
- open: k,
90
- onOpenChange: (a) => {
91
- !a && p === "custom" && v();
94
+ open: L,
95
+ onOpenChange: (e) => {
96
+ !e && p === "custom" && h();
92
97
  },
93
98
  children: [
94
- /* @__PURE__ */ e.jsx(B, { virtualRef: f }),
95
- /* @__PURE__ */ e.jsxs(M, { align: "start", children: [
96
- /* @__PURE__ */ e.jsx(
97
- F,
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: L,
107
+ onSelect: P,
103
108
  captionLayout: "dropdown",
104
109
  classNames: { root: "adm:p-0!" },
105
- ...j
110
+ ..._
106
111
  }
107
112
  ),
108
- /* @__PURE__ */ e.jsxs("div", { className: "adm:mt-2 adm:flex adm:justify-end adm:gap-2", children: [
109
- /* @__PURE__ */ e.jsx(b, { variant: "link", onClick: () => v(), children: s.cancel }),
110
- /* @__PURE__ */ e.jsx(b, { variant: "link", onClick: O, children: s.apply })
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
- J as DatePickerSelector
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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamosuiteservices/ui",
3
- "version": "2.16.1",
3
+ "version": "2.16.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",