@starasia/date 1.0.2 → 1.0.4
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 +158 -170
- package/dist/date.umd.js +6 -18
- package/package.json +6 -6
package/dist/date.es.js
CHANGED
|
@@ -48,23 +48,11 @@ const I = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
48
48
|
#f9fafb
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
/*
|
|
52
|
-
--starasia-ui-date-color-primary-blue: var(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
-
--starasia-ui-date-color-secondary-blue: var(
|
|
57
|
-
--starasia-ui-color-blue-500,
|
|
58
|
-
#3b82f6
|
|
59
|
-
);
|
|
60
|
-
--starasia-ui-date-color-tertiary-blue: var(
|
|
61
|
-
--starasia-ui-color-blue-300,
|
|
62
|
-
#93c5fd
|
|
63
|
-
);
|
|
64
|
-
--starasia-ui-date-color-quaternary-blue: var(
|
|
65
|
-
--starasia-ui-color-blue-50,
|
|
66
|
-
#eff6ff
|
|
67
|
-
);
|
|
51
|
+
/* brand */
|
|
52
|
+
--starasia-ui-date-color-primary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
|
|
53
|
+
--starasia-ui-date-color-secondary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
|
|
54
|
+
--starasia-ui-date-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary, rgba(144, 176, 218, 1));
|
|
55
|
+
--starasia-ui-date-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
|
|
68
56
|
|
|
69
57
|
/* spacing */
|
|
70
58
|
--starasia-ui-date-spacing-xs: var(--starasia-ui-spacing-xs, 4px);
|
|
@@ -256,7 +244,7 @@ const I = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
256
244
|
|
|
257
245
|
.starasia-calendar-input-container:has(input:focus) {
|
|
258
246
|
border-color: var(--starasia-ui-date-color-primary-blue);
|
|
259
|
-
box-shadow: 0px 0px 0px 2px rgba(
|
|
247
|
+
box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.2);
|
|
260
248
|
}
|
|
261
249
|
.starasia-calendar-input-container:has(input:disabled) {
|
|
262
250
|
/* border-color: var(--starasia-ui-input-color-tertiary-gray); */
|
|
@@ -360,30 +348,30 @@ const I = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
360
348
|
"Nov",
|
|
361
349
|
"Dec"
|
|
362
350
|
];
|
|
363
|
-
function J(
|
|
364
|
-
const [a, t] = F(
|
|
351
|
+
function J(e) {
|
|
352
|
+
const [a, t] = F(e), s = E(null), i = (g) => {
|
|
365
353
|
s.current && !s.current.contains(g.target) && t(!1);
|
|
366
354
|
};
|
|
367
355
|
return D(() => (document.addEventListener("click", i, !0), () => {
|
|
368
356
|
document.removeEventListener("click", i, !0);
|
|
369
357
|
}), []), { ref: s, isComponentVisible: a, setIsComponentVisible: t };
|
|
370
358
|
}
|
|
371
|
-
const j = "starasia-calendar-input-styles", U = (
|
|
359
|
+
const j = "starasia-calendar-input-styles", U = (e) => {
|
|
372
360
|
if (!document.getElementById(j)) {
|
|
373
361
|
const a = document.createElement("style");
|
|
374
|
-
a.id = j, a.textContent =
|
|
362
|
+
a.id = j, a.textContent = e, document.head.appendChild(a);
|
|
375
363
|
}
|
|
376
364
|
};
|
|
377
365
|
U(I);
|
|
378
|
-
const T = (
|
|
379
|
-
if (
|
|
366
|
+
const T = (e) => {
|
|
367
|
+
if (e === "sm")
|
|
380
368
|
return 16;
|
|
381
|
-
if (
|
|
369
|
+
if (e === "md")
|
|
382
370
|
return 16;
|
|
383
|
-
if (
|
|
371
|
+
if (e === "lg")
|
|
384
372
|
return 20;
|
|
385
|
-
}, K = (
|
|
386
|
-
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } =
|
|
373
|
+
}, K = (e) => {
|
|
374
|
+
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } = e, g = E(null), f = () => {
|
|
387
375
|
g.current && i.onClick && (g.current.focus(), i.onClick(""));
|
|
388
376
|
};
|
|
389
377
|
return /* @__PURE__ */ $(
|
|
@@ -446,7 +434,7 @@ const T = (n) => {
|
|
|
446
434
|
}
|
|
447
435
|
);
|
|
448
436
|
}, Q = ({
|
|
449
|
-
date:
|
|
437
|
+
date: e,
|
|
450
438
|
setDate: a,
|
|
451
439
|
dateRange: t,
|
|
452
440
|
setDateRange: s,
|
|
@@ -455,19 +443,19 @@ const T = (n) => {
|
|
|
455
443
|
maxDate: f,
|
|
456
444
|
input: v
|
|
457
445
|
}) => {
|
|
458
|
-
var u,
|
|
459
|
-
let h = new Date(
|
|
460
|
-
const b =
|
|
446
|
+
var u, n, c;
|
|
447
|
+
let h = new Date(e.getFullYear(), e.getMonth(), 1), r = h.getDay(), w = [];
|
|
448
|
+
const b = e.getMonth();
|
|
461
449
|
for (let d = 0; d < 42; d++) {
|
|
462
|
-
d === 0 &&
|
|
463
|
-
h.getDate() + (d -
|
|
450
|
+
d === 0 && r === 0 ? h.setDate(h.getDate() - 7) : d === 0 ? h.setDate(
|
|
451
|
+
h.getDate() + (d - r)
|
|
464
452
|
) : h.setDate(h.getDate() + 1);
|
|
465
453
|
let y = {
|
|
466
454
|
currentMonth: h.getMonth() === b,
|
|
467
455
|
date: new Date(h),
|
|
468
456
|
month: h.getMonth(),
|
|
469
457
|
number: h.getDate(),
|
|
470
|
-
selected: h.toDateString() === ((u = t.from) == null ? void 0 : u.toDateString()) || h.toDateString() === (((
|
|
458
|
+
selected: h.toDateString() === ((u = t.from) == null ? void 0 : u.toDateString()) || h.toDateString() === (((n = t.to) == null ? void 0 : n.toDateString()) || ((c = t.from) == null ? void 0 : c.toDateString())),
|
|
471
459
|
year: h.getFullYear(),
|
|
472
460
|
isDisabled: g && h < g || f && h > f
|
|
473
461
|
};
|
|
@@ -512,7 +500,7 @@ const T = (n) => {
|
|
|
512
500
|
}) })
|
|
513
501
|
] });
|
|
514
502
|
}, X = ({
|
|
515
|
-
date:
|
|
503
|
+
date: e,
|
|
516
504
|
setDate: a,
|
|
517
505
|
filter: t,
|
|
518
506
|
setViews: s,
|
|
@@ -521,48 +509,48 @@ const T = (n) => {
|
|
|
521
509
|
onChange: f,
|
|
522
510
|
minDate: v,
|
|
523
511
|
maxDate: h,
|
|
524
|
-
input:
|
|
512
|
+
input: r
|
|
525
513
|
}) => {
|
|
526
|
-
const w = i.from.getFullYear(), b =
|
|
514
|
+
const w = i.from.getFullYear(), b = e.getFullYear(), k = (u) => {
|
|
527
515
|
t ? (M(u), a(u)) : (s("days"), a(u));
|
|
528
516
|
}, M = (u) => {
|
|
529
517
|
var c;
|
|
530
|
-
let
|
|
531
|
-
if (
|
|
532
|
-
|
|
518
|
+
let n = { ...i };
|
|
519
|
+
if (n.from && n.to)
|
|
520
|
+
n = { from: u, to: null };
|
|
533
521
|
else {
|
|
534
|
-
const d = ((c =
|
|
535
|
-
u.getTime() > d ?
|
|
522
|
+
const d = ((c = n.from) == null ? void 0 : c.getTime()) || 0;
|
|
523
|
+
u.getTime() > d ? n = { from: n.from, to: u } : n = { from: u, to: n.from };
|
|
536
524
|
}
|
|
537
|
-
g(
|
|
525
|
+
g(n), f(n);
|
|
538
526
|
};
|
|
539
|
-
return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u,
|
|
527
|
+
return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u, n) => {
|
|
540
528
|
var y, o, p;
|
|
541
|
-
const c = new Date(b,
|
|
529
|
+
const c = new Date(b, n).getTime() > i.from.getTime() && new Date(b, n).getTime() < (((y = i.to) == null ? void 0 : y.getTime()) || i.from.getTime()), d = v && new Date(b, n) < v || h && new Date(b, n) > h;
|
|
542
530
|
return /* @__PURE__ */ l(
|
|
543
531
|
"p",
|
|
544
532
|
{
|
|
545
|
-
className: w === b && (
|
|
533
|
+
className: w === b && (n === ((o = i.from) == null ? void 0 : o.getMonth()) || n === ((p = i.to) == null ? void 0 : p.getMonth())) ? "starasia-calendar-months-active" : "",
|
|
546
534
|
style: {
|
|
547
535
|
backgroundColor: c ? "rgba(100, 181, 246, 0.1)" : "",
|
|
548
536
|
pointerEvents: d ? "none" : void 0,
|
|
549
537
|
cursor: d ? "not-allowed" : "pointer",
|
|
550
538
|
color: d ? "#ccc" : c ? "#b0b0b0" : "",
|
|
551
|
-
...
|
|
539
|
+
...r ? {} : { width: "100%" }
|
|
552
540
|
},
|
|
553
541
|
onClick: () => {
|
|
554
|
-
d || k(new Date(b,
|
|
542
|
+
d || k(new Date(b, n));
|
|
555
543
|
},
|
|
556
544
|
children: u.slice(0, 3)
|
|
557
545
|
},
|
|
558
|
-
|
|
546
|
+
n
|
|
559
547
|
);
|
|
560
548
|
}) });
|
|
561
|
-
}, B = (
|
|
562
|
-
const a = Math.floor(
|
|
549
|
+
}, B = (e) => {
|
|
550
|
+
const a = Math.floor(e / 10) * 10, t = a + 10;
|
|
563
551
|
return { start: a, end: t };
|
|
564
552
|
}, Z = ({
|
|
565
|
-
date:
|
|
553
|
+
date: e,
|
|
566
554
|
filter: a,
|
|
567
555
|
setViews: t,
|
|
568
556
|
setDate: s,
|
|
@@ -571,13 +559,13 @@ const T = (n) => {
|
|
|
571
559
|
onChange: f,
|
|
572
560
|
minDate: v,
|
|
573
561
|
maxDate: h,
|
|
574
|
-
input:
|
|
562
|
+
input: r
|
|
575
563
|
}) => {
|
|
576
564
|
var y;
|
|
577
565
|
let w = [];
|
|
578
|
-
const b =
|
|
566
|
+
const b = e.getFullYear(), { start: k, end: M } = B(b), u = i.from.getFullYear(), n = (y = i.to) == null ? void 0 : y.getFullYear();
|
|
579
567
|
for (let o = k; o < M; o++) {
|
|
580
|
-
const p = new Date(o, 0), C = (!v || p >= v) && (!h || p <= h), x = o === u || o ===
|
|
568
|
+
const p = new Date(o, 0), C = (!v || p >= v) && (!h || p <= h), x = o === u || o === n, m = p > i.from && p < i.to;
|
|
581
569
|
w.push({
|
|
582
570
|
year: o,
|
|
583
571
|
active: x && C,
|
|
@@ -610,13 +598,13 @@ const T = (n) => {
|
|
|
610
598
|
color: o.highlight ? "#b0b0b0" : o.active ? "" : o.disabled ? "#ccc" : "",
|
|
611
599
|
cursor: o.disabled ? "not-allowed" : "pointer",
|
|
612
600
|
pointerEvents: o.disbled ? "none" : "all",
|
|
613
|
-
...
|
|
601
|
+
...r ? {} : { width: "100%" }
|
|
614
602
|
},
|
|
615
603
|
children: o.year
|
|
616
604
|
},
|
|
617
605
|
p
|
|
618
606
|
)) });
|
|
619
|
-
}, q = ({ ...
|
|
607
|
+
}, q = ({ ...e }) => /* @__PURE__ */ l(
|
|
620
608
|
"svg",
|
|
621
609
|
{
|
|
622
610
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -624,7 +612,7 @@ const T = (n) => {
|
|
|
624
612
|
height: "20",
|
|
625
613
|
viewBox: "0 0 20 20",
|
|
626
614
|
fill: "none",
|
|
627
|
-
...
|
|
615
|
+
...e,
|
|
628
616
|
children: /* @__PURE__ */ l(
|
|
629
617
|
"path",
|
|
630
618
|
{
|
|
@@ -636,7 +624,7 @@ const T = (n) => {
|
|
|
636
624
|
}
|
|
637
625
|
)
|
|
638
626
|
}
|
|
639
|
-
), P = ({ ...
|
|
627
|
+
), P = ({ ...e }) => /* @__PURE__ */ l(
|
|
640
628
|
"svg",
|
|
641
629
|
{
|
|
642
630
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -644,7 +632,7 @@ const T = (n) => {
|
|
|
644
632
|
height: "20",
|
|
645
633
|
viewBox: "0 0 20 20",
|
|
646
634
|
fill: "none",
|
|
647
|
-
...
|
|
635
|
+
...e,
|
|
648
636
|
children: /* @__PURE__ */ l(
|
|
649
637
|
"path",
|
|
650
638
|
{
|
|
@@ -657,37 +645,37 @@ const T = (n) => {
|
|
|
657
645
|
)
|
|
658
646
|
}
|
|
659
647
|
), _ = ({
|
|
660
|
-
setViews:
|
|
648
|
+
setViews: e,
|
|
661
649
|
views: a,
|
|
662
650
|
filter: t,
|
|
663
651
|
date: s,
|
|
664
652
|
setDate: i
|
|
665
653
|
}) => {
|
|
666
654
|
const g = () => {
|
|
667
|
-
t ||
|
|
655
|
+
t || e((r) => r === "days" ? "months" : r === "months" ? "years" : "days");
|
|
668
656
|
}, f = () => {
|
|
669
657
|
if (a === "years") {
|
|
670
|
-
i((
|
|
658
|
+
i((r) => new Date(r.getFullYear() + 10, 0));
|
|
671
659
|
return;
|
|
672
660
|
}
|
|
673
661
|
if (a === "months") {
|
|
674
|
-
i((
|
|
662
|
+
i((r) => new Date(r.getFullYear() + 1, r.getMonth()));
|
|
675
663
|
return;
|
|
676
664
|
}
|
|
677
|
-
i((
|
|
665
|
+
i((r) => new Date(r.getFullYear(), r.getMonth() + 1));
|
|
678
666
|
}, v = () => {
|
|
679
667
|
if (a === "years") {
|
|
680
|
-
i((
|
|
668
|
+
i((r) => new Date(r.getFullYear() - 10, 0));
|
|
681
669
|
return;
|
|
682
670
|
}
|
|
683
671
|
if (a === "months") {
|
|
684
|
-
i((
|
|
672
|
+
i((r) => new Date(r.getFullYear() - 1, r.getMonth()));
|
|
685
673
|
return;
|
|
686
674
|
}
|
|
687
675
|
i(
|
|
688
|
-
(
|
|
689
|
-
|
|
690
|
-
|
|
676
|
+
(r) => new Date(
|
|
677
|
+
r.getMonth() === 0 ? r.getFullYear() - 1 : r.getFullYear(),
|
|
678
|
+
r.getMonth() === 0 ? 11 : r.getMonth() - 1
|
|
691
679
|
)
|
|
692
680
|
);
|
|
693
681
|
};
|
|
@@ -704,20 +692,20 @@ const T = (n) => {
|
|
|
704
692
|
/* @__PURE__ */ l(P, { onClick: () => f() })
|
|
705
693
|
] });
|
|
706
694
|
};
|
|
707
|
-
function L(
|
|
708
|
-
const a = new Date(
|
|
695
|
+
function L(e) {
|
|
696
|
+
const a = new Date(e), t = a.getFullYear(), s = a.getMonth();
|
|
709
697
|
return `${a.getDate().toString().padStart(2, "0")} ${G[s]} ${t}`;
|
|
710
698
|
}
|
|
711
|
-
const z = "starasia-calendar-styles", aa = (
|
|
699
|
+
const z = "starasia-calendar-styles", aa = (e) => {
|
|
712
700
|
if (!document.getElementById(z)) {
|
|
713
701
|
const a = document.createElement("style");
|
|
714
|
-
a.id = z, a.textContent =
|
|
702
|
+
a.id = z, a.textContent = e, document.head.appendChild(a);
|
|
715
703
|
}
|
|
716
704
|
};
|
|
717
705
|
aa(I);
|
|
718
|
-
const
|
|
706
|
+
const ra = W(
|
|
719
707
|
({
|
|
720
|
-
value:
|
|
708
|
+
value: e,
|
|
721
709
|
onChange: a,
|
|
722
710
|
filter: t,
|
|
723
711
|
input: s = !0,
|
|
@@ -726,18 +714,18 @@ const ea = W(
|
|
|
726
714
|
maxDate: f,
|
|
727
715
|
placeholder: v,
|
|
728
716
|
size: h,
|
|
729
|
-
status:
|
|
717
|
+
status: r
|
|
730
718
|
}, w) => {
|
|
731
|
-
const { ref: b, isComponentVisible: k, setIsComponentVisible: M } = J(!1), u = E(null), [
|
|
732
|
-
from: (
|
|
733
|
-
to: (
|
|
719
|
+
const { ref: b, isComponentVisible: k, setIsComponentVisible: M } = J(!1), u = E(null), [n, c] = F("days"), [d, y] = F(/* @__PURE__ */ new Date()), [o, p] = F({
|
|
720
|
+
from: (e == null ? void 0 : e.from) || /* @__PURE__ */ new Date(),
|
|
721
|
+
to: (e == null ? void 0 : e.to) || /* @__PURE__ */ new Date()
|
|
734
722
|
});
|
|
735
723
|
D(() => {
|
|
736
|
-
|
|
724
|
+
e ? (y(e.from), p(e)) : (y(/* @__PURE__ */ new Date()), p({
|
|
737
725
|
from: /* @__PURE__ */ new Date(),
|
|
738
726
|
to: /* @__PURE__ */ new Date()
|
|
739
727
|
}));
|
|
740
|
-
}, [
|
|
728
|
+
}, [e]), D(() => {
|
|
741
729
|
t && c(t);
|
|
742
730
|
}, [t]), D(() => {
|
|
743
731
|
t || c("days");
|
|
@@ -746,14 +734,14 @@ const ea = W(
|
|
|
746
734
|
}, [s]);
|
|
747
735
|
const C = () => {
|
|
748
736
|
var m, Y;
|
|
749
|
-
if (!
|
|
737
|
+
if (!e)
|
|
750
738
|
return "";
|
|
751
739
|
if (t) {
|
|
752
|
-
if (
|
|
740
|
+
if (n === "days")
|
|
753
741
|
return `${L(o.from)} ~ ${L(o.to || o.from) || "-"}`;
|
|
754
|
-
if (
|
|
742
|
+
if (n === "months")
|
|
755
743
|
return `${N[o.from.getMonth()]} ~ ${o.to ? N[o.to.getMonth()] : "-"}`;
|
|
756
|
-
if (
|
|
744
|
+
if (n === "years")
|
|
757
745
|
return `${(m = o.from) == null ? void 0 : m.getFullYear()} ~ ${((Y = o.to) == null ? void 0 : Y.getFullYear()) || "-"}`;
|
|
758
746
|
} else
|
|
759
747
|
return `${L(o.from)} ~ ${L(o.to || o.from) || "-"}`;
|
|
@@ -790,7 +778,7 @@ const ea = W(
|
|
|
790
778
|
disabled: i,
|
|
791
779
|
placeholder: v,
|
|
792
780
|
size: h,
|
|
793
|
-
status:
|
|
781
|
+
status: r
|
|
794
782
|
}
|
|
795
783
|
) : null,
|
|
796
784
|
k ? /* @__PURE__ */ $(
|
|
@@ -803,13 +791,13 @@ const ea = W(
|
|
|
803
791
|
_,
|
|
804
792
|
{
|
|
805
793
|
setViews: c,
|
|
806
|
-
views:
|
|
794
|
+
views: n,
|
|
807
795
|
filter: t,
|
|
808
796
|
date: d,
|
|
809
797
|
setDate: y
|
|
810
798
|
}
|
|
811
799
|
),
|
|
812
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-body", children:
|
|
800
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-body", children: n === "days" ? /* @__PURE__ */ l(
|
|
813
801
|
Q,
|
|
814
802
|
{
|
|
815
803
|
date: d,
|
|
@@ -822,7 +810,7 @@ const ea = W(
|
|
|
822
810
|
minDate: g,
|
|
823
811
|
maxDate: f
|
|
824
812
|
}
|
|
825
|
-
) :
|
|
813
|
+
) : n === "months" ? /* @__PURE__ */ l(
|
|
826
814
|
X,
|
|
827
815
|
{
|
|
828
816
|
date: d,
|
|
@@ -860,22 +848,22 @@ const ea = W(
|
|
|
860
848
|
}
|
|
861
849
|
);
|
|
862
850
|
}
|
|
863
|
-
), O = "starasia-calendar-input-styles",
|
|
851
|
+
), O = "starasia-calendar-input-styles", ea = (e) => {
|
|
864
852
|
if (!document.getElementById(O)) {
|
|
865
853
|
const a = document.createElement("style");
|
|
866
|
-
a.id = O, a.textContent =
|
|
854
|
+
a.id = O, a.textContent = e, document.head.appendChild(a);
|
|
867
855
|
}
|
|
868
856
|
};
|
|
869
|
-
|
|
870
|
-
const S = (
|
|
871
|
-
if (
|
|
857
|
+
ea(I);
|
|
858
|
+
const S = (e) => {
|
|
859
|
+
if (e === "sm")
|
|
872
860
|
return 16;
|
|
873
|
-
if (
|
|
861
|
+
if (e === "md")
|
|
874
862
|
return 16;
|
|
875
|
-
if (
|
|
863
|
+
if (e === "lg")
|
|
876
864
|
return 20;
|
|
877
|
-
},
|
|
878
|
-
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } =
|
|
865
|
+
}, na = (e) => {
|
|
866
|
+
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } = e, g = E(null), f = () => {
|
|
879
867
|
g.current && i.onClick && (g.current.focus(), i.onClick(""));
|
|
880
868
|
};
|
|
881
869
|
return /* @__PURE__ */ $(
|
|
@@ -938,7 +926,7 @@ const S = (n) => {
|
|
|
938
926
|
}
|
|
939
927
|
);
|
|
940
928
|
}, ta = ({
|
|
941
|
-
date:
|
|
929
|
+
date: e,
|
|
942
930
|
setDate: a,
|
|
943
931
|
previewDate: t,
|
|
944
932
|
setPreviewDate: s,
|
|
@@ -948,38 +936,38 @@ const S = (n) => {
|
|
|
948
936
|
input: v,
|
|
949
937
|
onChange: h
|
|
950
938
|
}) => {
|
|
951
|
-
let
|
|
939
|
+
let r = new Date(
|
|
952
940
|
t.getFullYear(),
|
|
953
941
|
t.getMonth(),
|
|
954
942
|
1
|
|
955
|
-
), w =
|
|
956
|
-
const k =
|
|
957
|
-
for (let
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
) :
|
|
943
|
+
), w = r.getDay(), b = [];
|
|
944
|
+
const k = e.toDateString(), M = t.getMonth();
|
|
945
|
+
for (let n = 0; n < 42; n++) {
|
|
946
|
+
n === 0 && w === 0 ? r.setDate(r.getDate() - 7) : n === 0 ? r.setDate(
|
|
947
|
+
r.getDate() + (n - w)
|
|
948
|
+
) : r.setDate(r.getDate() + 1);
|
|
961
949
|
let c = {
|
|
962
|
-
currentMonth:
|
|
963
|
-
date: new Date(
|
|
964
|
-
month:
|
|
965
|
-
number:
|
|
966
|
-
selected:
|
|
967
|
-
year:
|
|
968
|
-
isDisabled: g &&
|
|
950
|
+
currentMonth: r.getMonth() === M,
|
|
951
|
+
date: new Date(r),
|
|
952
|
+
month: r.getMonth(),
|
|
953
|
+
number: r.getDate(),
|
|
954
|
+
selected: r.toDateString() === k,
|
|
955
|
+
year: r.getFullYear(),
|
|
956
|
+
isDisabled: g && r < g || f && r > f
|
|
969
957
|
};
|
|
970
958
|
b.push(c);
|
|
971
959
|
}
|
|
972
|
-
const u = (
|
|
973
|
-
(!g ||
|
|
960
|
+
const u = (n) => {
|
|
961
|
+
(!g || n >= g) && (!f || n <= f) && (a(n), h(n), s(n), v && i(!1));
|
|
974
962
|
};
|
|
975
963
|
return /* @__PURE__ */ $("div", { className: "starasia-calendar-days-preivew", children: [
|
|
976
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: A.map((
|
|
977
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: b.map((
|
|
978
|
-
const d =
|
|
964
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: A.map((n, c) => /* @__PURE__ */ l("p", { children: n }, c)) }),
|
|
965
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: b.map((n, c) => {
|
|
966
|
+
const d = n.isDisabled;
|
|
979
967
|
return /* @__PURE__ */ l(
|
|
980
968
|
"p",
|
|
981
969
|
{
|
|
982
|
-
className: `${
|
|
970
|
+
className: `${n.currentMonth ? "starasia-calendar-days-current" : "starasia-calendar-days"} ${n.selected ? "starasia-calendar-days-active" : ""}`,
|
|
983
971
|
style: {
|
|
984
972
|
color: d ? "#ccc" : void 0,
|
|
985
973
|
pointerEvents: d ? "none" : void 0,
|
|
@@ -987,16 +975,16 @@ const S = (n) => {
|
|
|
987
975
|
...v ? {} : { width: "100%" }
|
|
988
976
|
},
|
|
989
977
|
onClick: () => {
|
|
990
|
-
d || u(
|
|
978
|
+
d || u(n.date);
|
|
991
979
|
},
|
|
992
|
-
children:
|
|
980
|
+
children: n.number
|
|
993
981
|
},
|
|
994
982
|
c
|
|
995
983
|
);
|
|
996
984
|
}) })
|
|
997
985
|
] });
|
|
998
986
|
}, sa = ({
|
|
999
|
-
date:
|
|
987
|
+
date: e,
|
|
1000
988
|
setDate: a,
|
|
1001
989
|
filter: t,
|
|
1002
990
|
setViews: s,
|
|
@@ -1005,36 +993,36 @@ const S = (n) => {
|
|
|
1005
993
|
setPreviewDate: f,
|
|
1006
994
|
minDate: v,
|
|
1007
995
|
maxDate: h,
|
|
1008
|
-
input:
|
|
996
|
+
input: r
|
|
1009
997
|
}) => {
|
|
1010
|
-
const w =
|
|
998
|
+
const w = e.getMonth(), b = e.getFullYear(), k = g.getFullYear(), M = (u) => {
|
|
1011
999
|
(!v || u >= v) && (!h || u <= h) && (t ? (i(u), a(u), f(u)) : (s("days"), f(u)));
|
|
1012
1000
|
};
|
|
1013
|
-
return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u,
|
|
1014
|
-
const c = v && new Date(k,
|
|
1001
|
+
return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u, n) => {
|
|
1002
|
+
const c = v && new Date(k, n, 1) < v || h && new Date(k, n + 1, 0) > h;
|
|
1015
1003
|
return /* @__PURE__ */ l(
|
|
1016
1004
|
"p",
|
|
1017
1005
|
{
|
|
1018
|
-
className:
|
|
1006
|
+
className: n === w && k === b ? "starasia-calendar-months-active" : "",
|
|
1019
1007
|
style: {
|
|
1020
1008
|
color: c ? "#ccc" : void 0,
|
|
1021
1009
|
pointerEvents: c ? "none" : void 0,
|
|
1022
1010
|
cursor: c ? "not-allowed" : "pointer",
|
|
1023
|
-
...
|
|
1011
|
+
...r ? {} : { width: "100%" }
|
|
1024
1012
|
},
|
|
1025
1013
|
onClick: () => {
|
|
1026
|
-
c || M(new Date(k,
|
|
1014
|
+
c || M(new Date(k, n));
|
|
1027
1015
|
},
|
|
1028
1016
|
children: u.slice(0, 3)
|
|
1029
1017
|
},
|
|
1030
|
-
|
|
1018
|
+
n
|
|
1031
1019
|
);
|
|
1032
1020
|
}) });
|
|
1033
|
-
}, V = (
|
|
1034
|
-
const a = Math.floor(
|
|
1021
|
+
}, V = (e) => {
|
|
1022
|
+
const a = Math.floor(e / 10) * 10, t = a + 10;
|
|
1035
1023
|
return { start: a, end: t };
|
|
1036
1024
|
}, ia = ({
|
|
1037
|
-
date:
|
|
1025
|
+
date: e,
|
|
1038
1026
|
filter: a,
|
|
1039
1027
|
setViews: t,
|
|
1040
1028
|
setDate: s,
|
|
@@ -1043,15 +1031,15 @@ const S = (n) => {
|
|
|
1043
1031
|
setPreviewDate: f,
|
|
1044
1032
|
minDate: v,
|
|
1045
1033
|
maxDate: h,
|
|
1046
|
-
input:
|
|
1034
|
+
input: r
|
|
1047
1035
|
}) => {
|
|
1048
1036
|
let w = [];
|
|
1049
|
-
const b = g.getFullYear(), { start: k, end: M } = V(b), u =
|
|
1037
|
+
const b = g.getFullYear(), { start: k, end: M } = V(b), u = e.getFullYear();
|
|
1050
1038
|
for (let c = k; c < M; c++) {
|
|
1051
1039
|
let d = v && new Date(c, 0, 1) < v || h && new Date(c, 11, 31) > h;
|
|
1052
1040
|
w.push({ year: c, active: c === u, isDisabled: d });
|
|
1053
1041
|
}
|
|
1054
|
-
const
|
|
1042
|
+
const n = (c) => {
|
|
1055
1043
|
(!v || c >= v) && (!h || c <= h) && (a ? (i(c), s(c), f(c)) : (t("months"), f(c)));
|
|
1056
1044
|
};
|
|
1057
1045
|
return /* @__PURE__ */ l("div", { className: "starasia-calendar-years-preview", children: w.map((c, d) => /* @__PURE__ */ l(
|
|
@@ -1062,51 +1050,51 @@ const S = (n) => {
|
|
|
1062
1050
|
color: c.isDisabled ? "#ccc" : void 0,
|
|
1063
1051
|
pointerEvents: c.isDisabled ? "none" : void 0,
|
|
1064
1052
|
cursor: c.isDisabled ? "not-allowed" : "pointer",
|
|
1065
|
-
...
|
|
1053
|
+
...r ? {} : { width: "100%" }
|
|
1066
1054
|
},
|
|
1067
1055
|
onClick: () => {
|
|
1068
|
-
c.isDisabled ||
|
|
1056
|
+
c.isDisabled || n(new Date(c.year, 0));
|
|
1069
1057
|
},
|
|
1070
1058
|
children: c.year
|
|
1071
1059
|
},
|
|
1072
1060
|
d
|
|
1073
1061
|
)) });
|
|
1074
1062
|
}, oa = ({
|
|
1075
|
-
setViews:
|
|
1063
|
+
setViews: e,
|
|
1076
1064
|
views: a,
|
|
1077
1065
|
filter: t,
|
|
1078
1066
|
previewDate: s,
|
|
1079
1067
|
setPreviewDate: i
|
|
1080
1068
|
}) => {
|
|
1081
1069
|
const g = () => {
|
|
1082
|
-
t ||
|
|
1070
|
+
t || e((r) => r === "days" ? "months" : r === "months" ? "years" : "days");
|
|
1083
1071
|
}, f = () => {
|
|
1084
1072
|
if (a === "years") {
|
|
1085
|
-
i((
|
|
1073
|
+
i((r) => new Date(r.getFullYear() + 10, 0));
|
|
1086
1074
|
return;
|
|
1087
1075
|
}
|
|
1088
1076
|
if (a === "months") {
|
|
1089
1077
|
i(
|
|
1090
|
-
(
|
|
1078
|
+
(r) => new Date(r.getFullYear() + 1, r.getMonth())
|
|
1091
1079
|
);
|
|
1092
1080
|
return;
|
|
1093
1081
|
}
|
|
1094
|
-
i((
|
|
1082
|
+
i((r) => new Date(r.getFullYear(), r.getMonth() + 1));
|
|
1095
1083
|
}, v = () => {
|
|
1096
1084
|
if (a === "years") {
|
|
1097
|
-
i((
|
|
1085
|
+
i((r) => new Date(r.getFullYear() - 10, 0));
|
|
1098
1086
|
return;
|
|
1099
1087
|
}
|
|
1100
1088
|
if (a === "months") {
|
|
1101
1089
|
i(
|
|
1102
|
-
(
|
|
1090
|
+
(r) => new Date(r.getFullYear() - 1, r.getMonth())
|
|
1103
1091
|
);
|
|
1104
1092
|
return;
|
|
1105
1093
|
}
|
|
1106
1094
|
i(
|
|
1107
|
-
(
|
|
1108
|
-
|
|
1109
|
-
|
|
1095
|
+
(r) => new Date(
|
|
1096
|
+
r.getMonth() === 0 ? r.getFullYear() - 1 : r.getFullYear(),
|
|
1097
|
+
r.getMonth() === 0 ? 11 : r.getMonth() - 1
|
|
1110
1098
|
)
|
|
1111
1099
|
);
|
|
1112
1100
|
};
|
|
@@ -1122,16 +1110,16 @@ const S = (n) => {
|
|
|
1122
1110
|
})() }),
|
|
1123
1111
|
/* @__PURE__ */ l(P, { onClick: () => f() })
|
|
1124
1112
|
] });
|
|
1125
|
-
}, H = "starasia-calendar-styles", la = (
|
|
1113
|
+
}, H = "starasia-calendar-styles", la = (e) => {
|
|
1126
1114
|
if (!document.getElementById(H)) {
|
|
1127
1115
|
const a = document.createElement("style");
|
|
1128
|
-
a.id = H, a.textContent =
|
|
1116
|
+
a.id = H, a.textContent = e, document.head.appendChild(a);
|
|
1129
1117
|
}
|
|
1130
1118
|
};
|
|
1131
1119
|
la(I);
|
|
1132
1120
|
const ca = W(
|
|
1133
1121
|
({
|
|
1134
|
-
value:
|
|
1122
|
+
value: e,
|
|
1135
1123
|
onChange: a,
|
|
1136
1124
|
filter: t,
|
|
1137
1125
|
input: s = !0,
|
|
@@ -1140,19 +1128,19 @@ const ca = W(
|
|
|
1140
1128
|
maxDate: f,
|
|
1141
1129
|
placeholder: v,
|
|
1142
1130
|
size: h,
|
|
1143
|
-
status:
|
|
1131
|
+
status: r
|
|
1144
1132
|
}, w) => {
|
|
1145
|
-
const { ref: b, isComponentVisible: k, setIsComponentVisible: M } = J(!1), u = E(null), [
|
|
1133
|
+
const { ref: b, isComponentVisible: k, setIsComponentVisible: M } = J(!1), u = E(null), [n, c] = F("days"), [d, y] = F(/* @__PURE__ */ new Date()), [o, p] = F(/* @__PURE__ */ new Date());
|
|
1146
1134
|
D(() => {
|
|
1147
|
-
|
|
1148
|
-
}, [
|
|
1135
|
+
e ? (y(e), p(e)) : (y(/* @__PURE__ */ new Date()), p(/* @__PURE__ */ new Date()));
|
|
1136
|
+
}, [e]), D(() => {
|
|
1149
1137
|
t && c(t);
|
|
1150
1138
|
}, [t]), D(() => {
|
|
1151
1139
|
t || c("days");
|
|
1152
1140
|
}, [k]), D(() => {
|
|
1153
1141
|
s || M(!0);
|
|
1154
1142
|
}, [s]);
|
|
1155
|
-
const C = () =>
|
|
1143
|
+
const C = () => e ? t === "days" ? L(d) : t === "months" ? `${N[d.getMonth()]} ${d.getFullYear()}` : t === "years" ? d.getFullYear() : L(d) : "", x = () => {
|
|
1156
1144
|
if (u.current && b.current && s) {
|
|
1157
1145
|
const m = b.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
|
|
1158
1146
|
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`;
|
|
@@ -1173,7 +1161,7 @@ const ca = W(
|
|
|
1173
1161
|
ref: s ? b : null,
|
|
1174
1162
|
children: [
|
|
1175
1163
|
s ? /* @__PURE__ */ l(
|
|
1176
|
-
|
|
1164
|
+
na,
|
|
1177
1165
|
{
|
|
1178
1166
|
value: C(),
|
|
1179
1167
|
onClick: () => M(!0),
|
|
@@ -1182,7 +1170,7 @@ const ca = W(
|
|
|
1182
1170
|
placeholder: v,
|
|
1183
1171
|
disabled: i,
|
|
1184
1172
|
size: h,
|
|
1185
|
-
status:
|
|
1173
|
+
status: r,
|
|
1186
1174
|
inputMode: "none"
|
|
1187
1175
|
}
|
|
1188
1176
|
) : null,
|
|
@@ -1196,14 +1184,14 @@ const ca = W(
|
|
|
1196
1184
|
oa,
|
|
1197
1185
|
{
|
|
1198
1186
|
setViews: c,
|
|
1199
|
-
views:
|
|
1187
|
+
views: n,
|
|
1200
1188
|
filter: t,
|
|
1201
1189
|
previewDate: o,
|
|
1202
1190
|
setPreviewDate: p,
|
|
1203
1191
|
isComponentVisible: k
|
|
1204
1192
|
}
|
|
1205
1193
|
),
|
|
1206
|
-
/* @__PURE__ */ l("div", { className: "starasia-calendar-body", children:
|
|
1194
|
+
/* @__PURE__ */ l("div", { className: "starasia-calendar-body", children: n === "days" ? /* @__PURE__ */ l(
|
|
1207
1195
|
ta,
|
|
1208
1196
|
{
|
|
1209
1197
|
date: d,
|
|
@@ -1216,7 +1204,7 @@ const ca = W(
|
|
|
1216
1204
|
maxDate: f,
|
|
1217
1205
|
onChange: a
|
|
1218
1206
|
}
|
|
1219
|
-
) :
|
|
1207
|
+
) : n === "months" ? /* @__PURE__ */ l(
|
|
1220
1208
|
sa,
|
|
1221
1209
|
{
|
|
1222
1210
|
date: d,
|
|
@@ -1254,7 +1242,7 @@ const ca = W(
|
|
|
1254
1242
|
}
|
|
1255
1243
|
), ha = W(
|
|
1256
1244
|
({
|
|
1257
|
-
value:
|
|
1245
|
+
value: e,
|
|
1258
1246
|
onChange: a,
|
|
1259
1247
|
filter: t,
|
|
1260
1248
|
input: s = !0,
|
|
@@ -1263,13 +1251,13 @@ const ca = W(
|
|
|
1263
1251
|
minDate: f,
|
|
1264
1252
|
maxDate: v,
|
|
1265
1253
|
placeholder: h,
|
|
1266
|
-
size:
|
|
1254
|
+
size: r,
|
|
1267
1255
|
status: w
|
|
1268
1256
|
}, b) => /* @__PURE__ */ l(R, { children: i ? /* @__PURE__ */ l(
|
|
1269
|
-
|
|
1257
|
+
ra,
|
|
1270
1258
|
{
|
|
1271
1259
|
onChange: a,
|
|
1272
|
-
value:
|
|
1260
|
+
value: e,
|
|
1273
1261
|
input: s,
|
|
1274
1262
|
filter: t,
|
|
1275
1263
|
disabled: g,
|
|
@@ -1277,14 +1265,14 @@ const ca = W(
|
|
|
1277
1265
|
minDate: f,
|
|
1278
1266
|
maxDate: v,
|
|
1279
1267
|
placeholder: h,
|
|
1280
|
-
size:
|
|
1268
|
+
size: r,
|
|
1281
1269
|
status: w
|
|
1282
1270
|
}
|
|
1283
1271
|
) : /* @__PURE__ */ l(
|
|
1284
1272
|
ca,
|
|
1285
1273
|
{
|
|
1286
1274
|
onChange: a,
|
|
1287
|
-
value:
|
|
1275
|
+
value: e,
|
|
1288
1276
|
input: s,
|
|
1289
1277
|
filter: t,
|
|
1290
1278
|
disabled: g,
|
|
@@ -1292,7 +1280,7 @@ const ca = W(
|
|
|
1292
1280
|
minDate: f,
|
|
1293
1281
|
maxDate: v,
|
|
1294
1282
|
placeholder: h,
|
|
1295
|
-
size:
|
|
1283
|
+
size: r,
|
|
1296
1284
|
status: w
|
|
1297
1285
|
}
|
|
1298
1286
|
) })
|
package/dist/date.umd.js
CHANGED
|
@@ -46,23 +46,11 @@
|
|
|
46
46
|
#f9fafb
|
|
47
47
|
);
|
|
48
48
|
|
|
49
|
-
/*
|
|
50
|
-
--starasia-ui-date-color-primary-blue: var(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
--starasia-ui-date-color-secondary-blue: var(
|
|
55
|
-
--starasia-ui-color-blue-500,
|
|
56
|
-
#3b82f6
|
|
57
|
-
);
|
|
58
|
-
--starasia-ui-date-color-tertiary-blue: var(
|
|
59
|
-
--starasia-ui-color-blue-300,
|
|
60
|
-
#93c5fd
|
|
61
|
-
);
|
|
62
|
-
--starasia-ui-date-color-quaternary-blue: var(
|
|
63
|
-
--starasia-ui-color-blue-50,
|
|
64
|
-
#eff6ff
|
|
65
|
-
);
|
|
49
|
+
/* brand */
|
|
50
|
+
--starasia-ui-date-color-primary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
|
|
51
|
+
--starasia-ui-date-color-secondary-blue: var(--starasia-ui-brand-primary-default, rgba(74, 106, 148, 1));
|
|
52
|
+
--starasia-ui-date-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary, rgba(144, 176, 218, 1));
|
|
53
|
+
--starasia-ui-date-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary, rgba(227, 237, 248, 1));
|
|
66
54
|
|
|
67
55
|
/* spacing */
|
|
68
56
|
--starasia-ui-date-spacing-xs: var(--starasia-ui-spacing-xs, 4px);
|
|
@@ -254,7 +242,7 @@
|
|
|
254
242
|
|
|
255
243
|
.starasia-calendar-input-container:has(input:focus) {
|
|
256
244
|
border-color: var(--starasia-ui-date-color-primary-blue);
|
|
257
|
-
box-shadow: 0px 0px 0px 2px rgba(
|
|
245
|
+
box-shadow: 0px 0px 0px 2px rgba(var(--starasia-ui-raw-color-brand-secondary, 144, 176, 218), 0.2);
|
|
258
246
|
}
|
|
259
247
|
.starasia-calendar-input-container:has(input:disabled) {
|
|
260
248
|
/* border-color: var(--starasia-ui-input-color-tertiary-gray); */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starasia/date",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "date component for starasia UI",
|
|
5
5
|
"author": "Prawito Hudoro",
|
|
6
6
|
"main": "dist/date.umd.js",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"dist/*.map",
|
|
13
13
|
"dist/*.css"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "vite --config vite.config.ts --port 3000",
|
|
17
|
+
"build": "vite build --config vite.config.ts"
|
|
18
|
+
},
|
|
15
19
|
"keywords": [],
|
|
16
20
|
"license": "ISC",
|
|
17
21
|
"type": "module",
|
|
@@ -33,9 +37,5 @@
|
|
|
33
37
|
"react-dom": "^18.2.0",
|
|
34
38
|
"@types/react": "^18.2.55",
|
|
35
39
|
"@types/react-dom": "^18.2.19"
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"dev": "vite --config vite.config.ts --port 3000",
|
|
39
|
-
"build": "vite build --config vite.config.ts"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|