@starasia/date 2.0.0 → 2.0.1
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/date.es.js +61 -61
- package/dist/date.umd.js +2 -2
- package/package.json +1 -1
package/dist/date.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as $, jsx as l, Fragment as G } from "react/jsx-runtime";
|
|
2
|
-
import { useState as F, useRef as
|
|
2
|
+
import { useState as F, useRef as T, useEffect as D, forwardRef as j } from "react";
|
|
3
3
|
const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
|
|
4
4
|
|
|
5
5
|
* {
|
|
@@ -254,7 +254,7 @@ const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
254
254
|
.starasia-calendar-input-container-warning {
|
|
255
255
|
border-color: var(--sa-date-border-warning) !important;
|
|
256
256
|
}
|
|
257
|
-
`,
|
|
257
|
+
`, J = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], N = [
|
|
258
258
|
"January",
|
|
259
259
|
"February",
|
|
260
260
|
"March",
|
|
@@ -281,8 +281,8 @@ const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
281
281
|
"Nov",
|
|
282
282
|
"Dec"
|
|
283
283
|
];
|
|
284
|
-
function
|
|
285
|
-
const [e, t] = F(a), s =
|
|
284
|
+
function A(a) {
|
|
285
|
+
const [e, t] = F(a), s = T(null), o = (g) => {
|
|
286
286
|
s.current && !s.current.contains(g.target) && t(!1);
|
|
287
287
|
};
|
|
288
288
|
return D(() => (document.addEventListener("click", o, !0), () => {
|
|
@@ -296,7 +296,7 @@ const z = "starasia-calendar-input-styles", q = (a) => {
|
|
|
296
296
|
}
|
|
297
297
|
};
|
|
298
298
|
q(S);
|
|
299
|
-
const
|
|
299
|
+
const E = (a) => {
|
|
300
300
|
if (a === "sm")
|
|
301
301
|
return 16;
|
|
302
302
|
if (a === "md")
|
|
@@ -304,7 +304,7 @@ const T = (a) => {
|
|
|
304
304
|
if (a === "lg")
|
|
305
305
|
return 20;
|
|
306
306
|
}, K = (a) => {
|
|
307
|
-
const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g =
|
|
307
|
+
const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = T(null), f = () => {
|
|
308
308
|
g.current && o.onClick && (g.current.focus(), o.onClick(""));
|
|
309
309
|
};
|
|
310
310
|
return /* @__PURE__ */ $(
|
|
@@ -317,15 +317,15 @@ const T = (a) => {
|
|
|
317
317
|
"svg",
|
|
318
318
|
{
|
|
319
319
|
xmlns: "http://www.w3.org/2000/svg",
|
|
320
|
-
width:
|
|
321
|
-
height:
|
|
320
|
+
width: E(e),
|
|
321
|
+
height: E(e),
|
|
322
322
|
viewBox: "0 0 20 20",
|
|
323
323
|
fill: "none",
|
|
324
324
|
children: /* @__PURE__ */ l(
|
|
325
325
|
"path",
|
|
326
326
|
{
|
|
327
327
|
d: "M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",
|
|
328
|
-
stroke: "#
|
|
328
|
+
stroke: "var(--sa-color-gray-500, #8c8f97)",
|
|
329
329
|
strokeWidth: "1.5",
|
|
330
330
|
strokeLinecap: "round",
|
|
331
331
|
strokeLinejoin: "round"
|
|
@@ -347,15 +347,15 @@ const T = (a) => {
|
|
|
347
347
|
"svg",
|
|
348
348
|
{
|
|
349
349
|
xmlns: "http://www.w3.org/2000/svg",
|
|
350
|
-
width:
|
|
351
|
-
height:
|
|
350
|
+
width: E(e),
|
|
351
|
+
height: E(e),
|
|
352
352
|
viewBox: "0 0 20 20",
|
|
353
353
|
fill: "none",
|
|
354
354
|
children: /* @__PURE__ */ l(
|
|
355
355
|
"path",
|
|
356
356
|
{
|
|
357
357
|
d: "M3.33331 7.5L9.99998 14.1667L16.6666 7.5",
|
|
358
|
-
stroke: "#
|
|
358
|
+
stroke: "var(--sa-color-gray-500, #8c8f97)",
|
|
359
359
|
strokeWidth: "1.5",
|
|
360
360
|
strokeLinecap: "round",
|
|
361
361
|
strokeLinejoin: "round"
|
|
@@ -383,7 +383,7 @@ const T = (a) => {
|
|
|
383
383
|
c === 0 && n === 0 ? h.setDate(h.getDate() - 7) : c === 0 ? h.setDate(
|
|
384
384
|
h.getDate() + (c - n)
|
|
385
385
|
) : h.setDate(h.getDate() + 1);
|
|
386
|
-
let
|
|
386
|
+
let y = {
|
|
387
387
|
currentMonth: h.getMonth() === b,
|
|
388
388
|
date: new Date(h),
|
|
389
389
|
month: h.getMonth(),
|
|
@@ -392,24 +392,24 @@ const T = (a) => {
|
|
|
392
392
|
year: h.getFullYear(),
|
|
393
393
|
isDisabled: g && h < g || f && h > f
|
|
394
394
|
};
|
|
395
|
-
w.push(
|
|
395
|
+
w.push(y);
|
|
396
396
|
}
|
|
397
397
|
const x = (c) => {
|
|
398
398
|
e(c);
|
|
399
399
|
}, M = (c) => {
|
|
400
400
|
var i;
|
|
401
|
-
let
|
|
402
|
-
if (
|
|
403
|
-
|
|
401
|
+
let y = { ...t };
|
|
402
|
+
if (y.from && y.to)
|
|
403
|
+
y = { from: c, to: null };
|
|
404
404
|
else {
|
|
405
|
-
const p = ((i =
|
|
406
|
-
c.getTime() > p ?
|
|
405
|
+
const p = ((i = y.from) == null ? void 0 : i.getTime()) || 0;
|
|
406
|
+
c.getTime() > p ? y = { from: y.from, to: c } : y = { from: c, to: y.from };
|
|
407
407
|
}
|
|
408
|
-
s(
|
|
408
|
+
s(y), o(y);
|
|
409
409
|
};
|
|
410
410
|
return /* @__PURE__ */ $("div", { className: "starasia-calendar-days-preivew", children: [
|
|
411
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children:
|
|
412
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: w.map((c,
|
|
411
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: J.map((c, y) => /* @__PURE__ */ l("p", { children: c }, y)) }),
|
|
412
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: w.map((c, y) => {
|
|
413
413
|
var C;
|
|
414
414
|
const i = c.date.getTime() > t.from.getTime() && c.date.getTime() < (((C = t.to) == null ? void 0 : C.getTime()) || t.from.getTime()), p = c.isDisabled;
|
|
415
415
|
return /* @__PURE__ */ l(
|
|
@@ -420,7 +420,7 @@ const T = (a) => {
|
|
|
420
420
|
backgroundColor: i ? "rgba(100, 181, 246, 0.1)" : "",
|
|
421
421
|
pointerEvents: p ? "none" : void 0,
|
|
422
422
|
cursor: p ? "not-allowed" : "pointer",
|
|
423
|
-
color: p ? "#
|
|
423
|
+
color: p ? "var(--sa-color-gray-400, #b7b9be)" : i ? "var(--sa-color-gray-500, #8c8f97)" : "",
|
|
424
424
|
...v ? {} : { width: "100%" }
|
|
425
425
|
},
|
|
426
426
|
onClick: () => {
|
|
@@ -428,7 +428,7 @@ const T = (a) => {
|
|
|
428
428
|
},
|
|
429
429
|
children: c.number
|
|
430
430
|
},
|
|
431
|
-
|
|
431
|
+
y
|
|
432
432
|
);
|
|
433
433
|
}) })
|
|
434
434
|
] });
|
|
@@ -458,8 +458,8 @@ const T = (a) => {
|
|
|
458
458
|
g(r), f(r);
|
|
459
459
|
};
|
|
460
460
|
return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u, r) => {
|
|
461
|
-
var
|
|
462
|
-
const d = new Date(b, r).getTime() > o.from.getTime() && new Date(b, r).getTime() < (((
|
|
461
|
+
var y, i, p;
|
|
462
|
+
const d = new Date(b, r).getTime() > o.from.getTime() && new Date(b, r).getTime() < (((y = o.to) == null ? void 0 : y.getTime()) || o.from.getTime()), c = v && new Date(b, r) < v || h && new Date(b, r) > h;
|
|
463
463
|
return /* @__PURE__ */ l(
|
|
464
464
|
"p",
|
|
465
465
|
{
|
|
@@ -468,7 +468,7 @@ const T = (a) => {
|
|
|
468
468
|
backgroundColor: d ? "rgba(100, 181, 246, 0.1)" : "",
|
|
469
469
|
pointerEvents: c ? "none" : void 0,
|
|
470
470
|
cursor: c ? "not-allowed" : "pointer",
|
|
471
|
-
color: c ? "#
|
|
471
|
+
color: c ? "var(--sa-color-gray-400, #b7b9be)" : d ? "var(--sa-color-gray-500, #8c8f97)" : "",
|
|
472
472
|
...n ? {} : { width: "100%" }
|
|
473
473
|
},
|
|
474
474
|
onClick: () => {
|
|
@@ -494,15 +494,15 @@ const T = (a) => {
|
|
|
494
494
|
maxDate: h,
|
|
495
495
|
input: n
|
|
496
496
|
}) => {
|
|
497
|
-
var
|
|
497
|
+
var y;
|
|
498
498
|
let w = [];
|
|
499
|
-
const b = a.getFullYear(), { start: x, end: M } = B(b), u = o.from.getFullYear(), r = (
|
|
499
|
+
const b = a.getFullYear(), { start: x, end: M } = B(b), u = o.from.getFullYear(), r = (y = o.to) == null ? void 0 : y.getFullYear();
|
|
500
500
|
for (let i = x; i < M; i++) {
|
|
501
|
-
const p = new Date(i, 0), C = (!v || p >= v) && (!h || p <= h), k = i === u || i === r,
|
|
501
|
+
const p = new Date(i, 0), C = (!v || p >= v) && (!h || p <= h), k = i === u || i === r, m = p > o.from && p < o.to;
|
|
502
502
|
w.push({
|
|
503
503
|
year: i,
|
|
504
504
|
active: k && C,
|
|
505
|
-
highlight:
|
|
505
|
+
highlight: m && C,
|
|
506
506
|
disabled: !C
|
|
507
507
|
});
|
|
508
508
|
}
|
|
@@ -528,7 +528,7 @@ const T = (a) => {
|
|
|
528
528
|
},
|
|
529
529
|
style: {
|
|
530
530
|
backgroundColor: i.highlight ? "rgba(100, 181, 246, 0.1)" : "",
|
|
531
|
-
color: i.highlight ? "#
|
|
531
|
+
color: i.highlight ? "var(--sa-color-gray-500, #8c8f97)" : i.active ? "" : i.disabled ? "var(--sa-color-gray-400, #b7b9be)" : "",
|
|
532
532
|
cursor: i.disabled ? "not-allowed" : "pointer",
|
|
533
533
|
pointerEvents: i.disbled ? "none" : "all",
|
|
534
534
|
...n ? {} : { width: "100%" }
|
|
@@ -550,7 +550,7 @@ const T = (a) => {
|
|
|
550
550
|
"path",
|
|
551
551
|
{
|
|
552
552
|
d: "M12.5 3.33334L5.83337 10L12.5 16.6667",
|
|
553
|
-
stroke: "#
|
|
553
|
+
stroke: "var(--sa-color-brand-700, #031f43)",
|
|
554
554
|
strokeWidth: "1.5",
|
|
555
555
|
strokeLinecap: "round",
|
|
556
556
|
strokeLinejoin: "round"
|
|
@@ -570,7 +570,7 @@ const T = (a) => {
|
|
|
570
570
|
"path",
|
|
571
571
|
{
|
|
572
572
|
d: "M7.5 16.6667L14.1667 10L7.5 3.33334",
|
|
573
|
-
stroke: "#
|
|
573
|
+
stroke: "var(--sa-color-brand-700, #031f43)",
|
|
574
574
|
strokeWidth: "1.5",
|
|
575
575
|
strokeLinecap: "round",
|
|
576
576
|
strokeLinejoin: "round"
|
|
@@ -649,12 +649,12 @@ const ne = j(
|
|
|
649
649
|
size: h,
|
|
650
650
|
status: n
|
|
651
651
|
}, w) => {
|
|
652
|
-
const { ref: b, isComponentVisible: x, setIsComponentVisible: M } =
|
|
652
|
+
const { ref: b, isComponentVisible: x, setIsComponentVisible: M } = A(!1), u = T(null), [r, d] = F("days"), [c, y] = F(/* @__PURE__ */ new Date()), [i, p] = F({
|
|
653
653
|
from: (a == null ? void 0 : a.from) || /* @__PURE__ */ new Date(),
|
|
654
654
|
to: (a == null ? void 0 : a.to) || /* @__PURE__ */ new Date()
|
|
655
655
|
});
|
|
656
656
|
D(() => {
|
|
657
|
-
a ? (
|
|
657
|
+
a ? (y(a.from), p(a)) : (y(/* @__PURE__ */ new Date()), p({
|
|
658
658
|
from: /* @__PURE__ */ new Date(),
|
|
659
659
|
to: /* @__PURE__ */ new Date()
|
|
660
660
|
}));
|
|
@@ -666,7 +666,7 @@ const ne = j(
|
|
|
666
666
|
s || M(!0);
|
|
667
667
|
}, [s]);
|
|
668
668
|
const C = () => {
|
|
669
|
-
var
|
|
669
|
+
var m, Y;
|
|
670
670
|
if (!a)
|
|
671
671
|
return "";
|
|
672
672
|
if (t) {
|
|
@@ -675,21 +675,21 @@ const ne = j(
|
|
|
675
675
|
if (r === "months")
|
|
676
676
|
return `${N[i.from.getMonth()]} ~ ${i.to ? N[i.to.getMonth()] : "-"}`;
|
|
677
677
|
if (r === "years")
|
|
678
|
-
return `${(
|
|
678
|
+
return `${(m = i.from) == null ? void 0 : m.getFullYear()} ~ ${((Y = i.to) == null ? void 0 : Y.getFullYear()) || "-"}`;
|
|
679
679
|
} else
|
|
680
680
|
return `${L(i.from)} ~ ${L(i.to || i.from) || "-"}`;
|
|
681
681
|
}, k = () => {
|
|
682
682
|
if (u.current && b.current && s) {
|
|
683
|
-
const
|
|
684
|
-
window.innerWidth <
|
|
683
|
+
const m = b.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
|
|
684
|
+
window.innerWidth < m.left + Y.width ? u.current.style.left = `${m.left - Y.width + m.width}px` : u.current.style.left = `${m.left}px`, m.top + Y.height > window.innerHeight ? u.current.style.top = `${m.y - (m.height + Y.height - 28)}px` : u.current.style.top = `${m.y + m.height}px`;
|
|
685
685
|
}
|
|
686
686
|
};
|
|
687
687
|
return D(() => {
|
|
688
688
|
u.current && b.current && s && k();
|
|
689
689
|
}, [u, b, x]), D(() => {
|
|
690
|
-
const
|
|
691
|
-
return
|
|
692
|
-
|
|
690
|
+
const m = w == null ? void 0 : w.current;
|
|
691
|
+
return m && m.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
|
|
692
|
+
m && m.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
|
|
693
693
|
};
|
|
694
694
|
}, []), /* @__PURE__ */ $(
|
|
695
695
|
"div",
|
|
@@ -727,14 +727,14 @@ const ne = j(
|
|
|
727
727
|
views: r,
|
|
728
728
|
filter: t,
|
|
729
729
|
date: c,
|
|
730
|
-
setDate:
|
|
730
|
+
setDate: y
|
|
731
731
|
}
|
|
732
732
|
),
|
|
733
733
|
/* @__PURE__ */ l("div", { className: "starasia-calendar-body", children: r === "days" ? /* @__PURE__ */ l(
|
|
734
734
|
Q,
|
|
735
735
|
{
|
|
736
736
|
date: c,
|
|
737
|
-
setDate:
|
|
737
|
+
setDate: y,
|
|
738
738
|
setIsComponentVisible: M,
|
|
739
739
|
dateRange: i,
|
|
740
740
|
setDateRange: p,
|
|
@@ -747,7 +747,7 @@ const ne = j(
|
|
|
747
747
|
X,
|
|
748
748
|
{
|
|
749
749
|
date: c,
|
|
750
|
-
setDate:
|
|
750
|
+
setDate: y,
|
|
751
751
|
filter: t,
|
|
752
752
|
setViews: d,
|
|
753
753
|
dateRange: i,
|
|
@@ -762,7 +762,7 @@ const ne = j(
|
|
|
762
762
|
Z,
|
|
763
763
|
{
|
|
764
764
|
date: c,
|
|
765
|
-
setDate:
|
|
765
|
+
setDate: y,
|
|
766
766
|
filter: t,
|
|
767
767
|
setViews: d,
|
|
768
768
|
dateRange: i,
|
|
@@ -796,7 +796,7 @@ const I = (a) => {
|
|
|
796
796
|
if (a === "lg")
|
|
797
797
|
return 20;
|
|
798
798
|
}, re = (a) => {
|
|
799
|
-
const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g =
|
|
799
|
+
const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = T(null), f = () => {
|
|
800
800
|
g.current && o.onClick && (g.current.focus(), o.onClick(""));
|
|
801
801
|
};
|
|
802
802
|
return /* @__PURE__ */ $(
|
|
@@ -817,7 +817,7 @@ const I = (a) => {
|
|
|
817
817
|
"path",
|
|
818
818
|
{
|
|
819
819
|
d: "M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",
|
|
820
|
-
stroke: "#
|
|
820
|
+
stroke: "var(--sa-color-gray-500, #8c8f97)",
|
|
821
821
|
strokeWidth: "1.5",
|
|
822
822
|
strokeLinecap: "round",
|
|
823
823
|
strokeLinejoin: "round"
|
|
@@ -847,7 +847,7 @@ const I = (a) => {
|
|
|
847
847
|
"path",
|
|
848
848
|
{
|
|
849
849
|
d: "M3.33331 7.5L9.99998 14.1667L16.6666 7.5",
|
|
850
|
-
stroke: "#
|
|
850
|
+
stroke: "var(--sa-color-gray-500, #8c8f97)",
|
|
851
851
|
strokeWidth: "1.5",
|
|
852
852
|
strokeLinecap: "round",
|
|
853
853
|
strokeLinejoin: "round"
|
|
@@ -894,7 +894,7 @@ const I = (a) => {
|
|
|
894
894
|
(!g || r >= g) && (!f || r <= f) && (e(r), h(r), s(r), v && o(!1));
|
|
895
895
|
};
|
|
896
896
|
return /* @__PURE__ */ $("div", { className: "starasia-calendar-days-preivew", children: [
|
|
897
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children:
|
|
897
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: J.map((r, d) => /* @__PURE__ */ l("p", { children: r }, d)) }),
|
|
898
898
|
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: b.map((r, d) => {
|
|
899
899
|
const c = r.isDisabled;
|
|
900
900
|
return /* @__PURE__ */ l(
|
|
@@ -1063,9 +1063,9 @@ const de = j(
|
|
|
1063
1063
|
size: h,
|
|
1064
1064
|
status: n
|
|
1065
1065
|
}, w) => {
|
|
1066
|
-
const { ref: b, isComponentVisible: x, setIsComponentVisible: M } =
|
|
1066
|
+
const { ref: b, isComponentVisible: x, setIsComponentVisible: M } = A(!1), u = T(null), [r, d] = F("days"), [c, y] = F(/* @__PURE__ */ new Date()), [i, p] = F(/* @__PURE__ */ new Date());
|
|
1067
1067
|
D(() => {
|
|
1068
|
-
a ? (
|
|
1068
|
+
a ? (y(a), p(a)) : (y(/* @__PURE__ */ new Date()), p(/* @__PURE__ */ new Date()));
|
|
1069
1069
|
}, [a]), D(() => {
|
|
1070
1070
|
t && d(t);
|
|
1071
1071
|
}, [t]), D(() => {
|
|
@@ -1075,16 +1075,16 @@ const de = j(
|
|
|
1075
1075
|
}, [s]);
|
|
1076
1076
|
const C = () => a ? t === "days" ? L(c) : t === "months" ? `${N[c.getMonth()]} ${c.getFullYear()}` : t === "years" ? c.getFullYear() : L(c) : "", k = () => {
|
|
1077
1077
|
if (u.current && b.current && s) {
|
|
1078
|
-
const
|
|
1079
|
-
window.innerWidth <
|
|
1078
|
+
const m = b.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
|
|
1079
|
+
window.innerWidth < m.left + Y.width ? u.current.style.left = `${m.left - Y.width + m.width}px` : u.current.style.left = `${m.left}px`, m.top + Y.height > window.innerHeight ? u.current.style.top = `${m.y - (m.height + Y.height - 28)}px` : u.current.style.top = `${m.y + m.height}px`;
|
|
1080
1080
|
}
|
|
1081
1081
|
};
|
|
1082
1082
|
return D(() => {
|
|
1083
1083
|
u.current && b.current && s && k();
|
|
1084
1084
|
}, [u, b, x]), D(() => {
|
|
1085
|
-
const
|
|
1086
|
-
return
|
|
1087
|
-
|
|
1085
|
+
const m = w == null ? void 0 : w.current;
|
|
1086
|
+
return m && m.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
|
|
1087
|
+
m && m.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
|
|
1088
1088
|
};
|
|
1089
1089
|
}, []), /* @__PURE__ */ $(
|
|
1090
1090
|
"div",
|
|
@@ -1128,7 +1128,7 @@ const de = j(
|
|
|
1128
1128
|
te,
|
|
1129
1129
|
{
|
|
1130
1130
|
date: c,
|
|
1131
|
-
setDate:
|
|
1131
|
+
setDate: y,
|
|
1132
1132
|
previewDate: i,
|
|
1133
1133
|
setPreviewDate: p,
|
|
1134
1134
|
setIsComponentVisible: M,
|
|
@@ -1141,7 +1141,7 @@ const de = j(
|
|
|
1141
1141
|
se,
|
|
1142
1142
|
{
|
|
1143
1143
|
date: c,
|
|
1144
|
-
setDate:
|
|
1144
|
+
setDate: y,
|
|
1145
1145
|
previewDate: i,
|
|
1146
1146
|
setPreviewDate: p,
|
|
1147
1147
|
filter: t,
|
|
@@ -1155,7 +1155,7 @@ const de = j(
|
|
|
1155
1155
|
oe,
|
|
1156
1156
|
{
|
|
1157
1157
|
date: c,
|
|
1158
|
-
setDate:
|
|
1158
|
+
setDate: y,
|
|
1159
1159
|
previewDate: i,
|
|
1160
1160
|
setPreviewDate: p,
|
|
1161
1161
|
filter: t,
|
package/dist/date.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,m){"use strict";const
|
|
1
|
+
(function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,m){"use strict";const E=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
|
|
2
2
|
|
|
3
3
|
* {
|
|
4
4
|
margin: 0;
|
|
@@ -252,4 +252,4 @@
|
|
|
252
252
|
.starasia-calendar-input-container-warning {
|
|
253
253
|
border-color: var(--sa-date-border-warning) !important;
|
|
254
254
|
}
|
|
255
|
-
`,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],J=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),i=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="starasia-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(N);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:i,minDate:g,maxDate:p,input:v})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const w=r.getMonth();for(let c=0;c<42;c++){c===0&&n===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===w,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((d=s.from)==null?void 0:d.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=c=>{e(c)},k=c=>{var l;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((l=y.from)==null?void 0:l.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),i(y)};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>a.jsx("p",{children:c},y))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const l=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return a.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:l?"rgba(100, 181, 246, 0.1)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"#ccc":l?"#b0b0b0":"",...v?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{const x=i.from.getFullYear(),w=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...i};if(t.from&&t.to)t={from:h,to:null};else{const c=((d=t.from)==null?void 0:d.getTime())||0;h.getTime()>c?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,l,f;const d=new Date(w,t).getTime()>i.from.getTime()&&new Date(w,t).getTime()<(((y=i.to)==null?void 0:y.getTime())||i.from.getTime()),c=v&&new Date(w,t)<v||u&&new Date(w,t)>u;return a.jsx("p",{className:x===w&&(t===((l=i.from)==null?void 0:l.getMonth())||t===((f=i.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"rgba(100, 181, 246, 0.1)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"#ccc":d?"#b0b0b0":"",...n?{}:{width:"100%"}},onClick:()=>{c||M(new Date(w,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{var y;let x=[];const w=r.getFullYear(),{start:M,end:k}=T(w),h=i.from.getFullYear(),t=(y=i.to)==null?void 0:y.getFullYear();for(let l=M;l<k;l++){const f=new Date(l,0),D=(!v||f>=v)&&(!u||f<=u),C=l===h||l===t,b=f>i.from&&f<i.to;x.push({year:l,active:C&&D,highlight:b&&D,disabled:!D})}const d=l=>{e?(c(l),o(l)):(o(l),s("months"))},c=l=>{var D;let f={...i};if(f.from&&f.to)f={from:l,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;l.getTime()>C?f={from:f.from,to:l}:f={from:l,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((l,f)=>a.jsx("p",{className:`${l.active?"starasia-calendar-months-active":""} ${l.highlight?"starasia-calendar-months-highlight":""} ${l.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{l.disabled||d(new Date(l.year,0))},style:{backgroundColor:l.highlight?"rgba(100, 181, 246, 0.1)":"",color:l.highlight?"#b0b0b0":l.active?"":l.disabled?"#ccc":"",cursor:l.disabled?"not-allowed":"pointer",pointerEvents:l.disbled?"none":"all",...n?{}:{width:"100%"}},children:l.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},v=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function E(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${J[o]} ${s}`}const W="starasia-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(N);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var b,$;if(!r)return"";if(s){if(t==="days")return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`;if(t==="months")return`${F[l.from.getMonth()]} ~ ${l.to?F[l.to.getMonth()]:"-"}`;if(t==="years")return`${(b=l.from)==null?void 0:b.getFullYear()} ~ ${(($=l.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`},C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:i,placeholder:v,size:u,status:n}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:l,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="starasia-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(N);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:i,minDate:g,maxDate:p,input:v,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),w=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let d={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};w.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),v&&i(!1))};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>a.jsx("p",{children:t},d))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:w.map((t,d)=>{const c=t.isDisabled;return a.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...v?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{const x=r.getMonth(),w=r.getFullYear(),M=g.getFullYear(),k=h=>{(!v||h>=v)&&(!u||h<=u)&&(s?(i(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=v&&new Date(M,t,1)<v||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===w?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{let x=[];const w=g.getFullYear(),{start:M,end:k}=I(w),h=r.getFullYear();for(let d=M;d<k;d++){let c=v&&new Date(d,0,1)<v||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!v||d>=v)&&(!u||d<=u)&&(e?(i(d),o(d),p(d)):(s("months"),p(d)))};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>a.jsx("p",{className:d.active?"starasia-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d.isDisabled||t(new Date(d.year,0))},children:d.year},c))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},v=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},A="starasia-calendar-styles";(r=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=r,document.head.appendChild(e)}})(N);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?E(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():E(c):"",C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:v,disabled:i,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:d,views:t,filter:s,previewDate:l,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(Z,{date:c,setDate:y,previewDate:l,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:i,disabled:g,minDate:p,maxDate:v,placeholder:u,size:n,status:x},w)=>a.jsx(a.Fragment,{children:i?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|
|
255
|
+
`,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),l=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="starasia-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(E);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:g,maxDate:p,input:w})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const v=r.getMonth();for(let c=0;c<42;c++){c===0&&n===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===v,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((d=s.from)==null?void 0:d.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=c=>{e(c)},k=c=>{var i;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((i=y.from)==null?void 0:i.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),l(y)};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>a.jsx("p",{children:c},y))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const i=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return a.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:i?"rgba(100, 181, 246, 0.1)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":i?"var(--sa-color-gray-500, #8c8f97)":"",...w?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{const x=l.from.getFullYear(),v=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...l};if(t.from&&t.to)t={from:h,to:null};else{const c=((d=t.from)==null?void 0:d.getTime())||0;h.getTime()>c?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,i,f;const d=new Date(v,t).getTime()>l.from.getTime()&&new Date(v,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),c=w&&new Date(v,t)<w||u&&new Date(v,t)>u;return a.jsx("p",{className:x===v&&(t===((i=l.from)==null?void 0:i.getMonth())||t===((f=l.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"rgba(100, 181, 246, 0.1)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...n?{}:{width:"100%"}},onClick:()=>{c||M(new Date(v,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:n})=>{var y;let x=[];const v=r.getFullYear(),{start:M,end:k}=T(v),h=l.from.getFullYear(),t=(y=l.to)==null?void 0:y.getFullYear();for(let i=M;i<k;i++){const f=new Date(i,0),D=(!w||f>=w)&&(!u||f<=u),C=i===h||i===t,b=f>l.from&&f<l.to;x.push({year:i,active:C&&D,highlight:b&&D,disabled:!D})}const d=i=>{e?(c(i),o(i)):(o(i),s("months"))},c=i=>{var D;let f={...l};if(f.from&&f.to)f={from:i,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;i.getTime()>C?f={from:f.from,to:i}:f={from:i,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((i,f)=>a.jsx("p",{className:`${i.active?"starasia-calendar-months-active":""} ${i.highlight?"starasia-calendar-months-highlight":""} ${i.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{i.disabled||d(new Date(i.year,0))},style:{backgroundColor:i.highlight?"rgba(100, 181, 246, 0.1)":"",color:i.highlight?"var(--sa-color-gray-500, #8c8f97)":i.active?"":i.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:i.disabled?"not-allowed":"pointer",pointerEvents:i.disbled?"none":"all",...n?{}:{width:"100%"}},children:i.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function N(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${A[o]} ${s}`}const W="starasia-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(E);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:v,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var b,$;if(!r)return"";if(s){if(t==="days")return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`;if(t==="months")return`${F[i.from.getMonth()]} ~ ${i.to?F[i.to.getMonth()]:"-"}`;if(t==="years")return`${(b=i.from)==null?void 0:b.getFullYear()} ~ ${(($=i.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`},C=()=>{if(h.current&&v.current&&o){const b=v.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&v.current&&o&&C()},[h,v,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?v:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:n}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:i,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="starasia-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(E);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),v=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let d={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};v.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!1))};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>a.jsx("p",{children:t},d))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:v.map((t,d)=>{const c=t.isDisabled;return a.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{const x=r.getMonth(),v=r.getFullYear(),M=g.getFullYear(),k=h=>{(!w||h>=w)&&(!u||h<=u)&&(s?(l(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=w&&new Date(M,t,1)<w||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===v?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:n})=>{let x=[];const v=g.getFullYear(),{start:M,end:k}=I(v),h=r.getFullYear();for(let d=M;d<k;d++){let c=w&&new Date(d,0,1)<w||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!w||d>=w)&&(!u||d<=u)&&(e?(l(d),o(d),p(d)):(s("months"),p(d)))};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>a.jsx("p",{className:d.active?"starasia-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d.isDisabled||t(new Date(d.year,0))},children:d.year},c))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()+1,n.getMonth()));return}l(n=>new Date(n.getFullYear(),n.getMonth()+1))},w=()=>{if(e==="years"){l(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){l(n=>new Date(n.getFullYear()-1,n.getMonth()));return}l(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>w()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},J="starasia-calendar-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(E);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:n},x)=>{const{ref:v,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?N(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():N(c):"",C=()=>{if(h.current&&v.current&&o){const b=v.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&v.current&&o&&C()},[h,v,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?v:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:d,views:t,filter:s,previewDate:i,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(Z,{date:c,setDate:y,previewDate:i,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:n,status:x},v)=>a.jsx(a.Fragment,{children:l?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:v,minDate:p,maxDate:w,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:v,minDate:p,maxDate:w,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
|