@starasia/date 1.0.2 → 1.0.3
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 +113 -125
- 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);
|
|
53
|
+
--starasia-ui-date-color-secondary-blue: var(--starasia-ui-brand-primary-default);
|
|
54
|
+
--starasia-ui-date-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary);
|
|
55
|
+
--starasia-ui-date-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary);
|
|
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), 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(r) {
|
|
352
|
+
const [a, t] = F(r), 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 = (r) => {
|
|
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 = r, document.head.appendChild(a);
|
|
375
363
|
}
|
|
376
364
|
};
|
|
377
365
|
U(I);
|
|
378
|
-
const T = (
|
|
379
|
-
if (
|
|
366
|
+
const T = (r) => {
|
|
367
|
+
if (r === "sm")
|
|
380
368
|
return 16;
|
|
381
|
-
if (
|
|
369
|
+
if (r === "md")
|
|
382
370
|
return 16;
|
|
383
|
-
if (
|
|
371
|
+
if (r === "lg")
|
|
384
372
|
return 20;
|
|
385
|
-
}, K = (
|
|
386
|
-
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } =
|
|
373
|
+
}, K = (r) => {
|
|
374
|
+
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } = r, 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: r,
|
|
450
438
|
setDate: a,
|
|
451
439
|
dateRange: t,
|
|
452
440
|
setDateRange: s,
|
|
@@ -455,9 +443,9 @@ 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(r.getFullYear(), r.getMonth(), 1), e = h.getDay(), w = [];
|
|
448
|
+
const b = r.getMonth();
|
|
461
449
|
for (let d = 0; d < 42; d++) {
|
|
462
450
|
d === 0 && e === 0 ? h.setDate(h.getDate() - 7) : d === 0 ? h.setDate(
|
|
463
451
|
h.getDate() + (d - e)
|
|
@@ -467,7 +455,7 @@ const T = (n) => {
|
|
|
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: r,
|
|
516
504
|
setDate: a,
|
|
517
505
|
filter: t,
|
|
518
506
|
setViews: s,
|
|
@@ -523,26 +511,26 @@ const T = (n) => {
|
|
|
523
511
|
maxDate: h,
|
|
524
512
|
input: e
|
|
525
513
|
}) => {
|
|
526
|
-
const w = i.from.getFullYear(), b =
|
|
514
|
+
const w = i.from.getFullYear(), b = r.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,
|
|
@@ -551,18 +539,18 @@ const T = (n) => {
|
|
|
551
539
|
...e ? {} : { 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 = (r) => {
|
|
550
|
+
const a = Math.floor(r / 10) * 10, t = a + 10;
|
|
563
551
|
return { start: a, end: t };
|
|
564
552
|
}, Z = ({
|
|
565
|
-
date:
|
|
553
|
+
date: r,
|
|
566
554
|
filter: a,
|
|
567
555
|
setViews: t,
|
|
568
556
|
setDate: s,
|
|
@@ -575,9 +563,9 @@ const T = (n) => {
|
|
|
575
563
|
}) => {
|
|
576
564
|
var y;
|
|
577
565
|
let w = [];
|
|
578
|
-
const b =
|
|
566
|
+
const b = r.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,
|
|
@@ -616,7 +604,7 @@ const T = (n) => {
|
|
|
616
604
|
},
|
|
617
605
|
p
|
|
618
606
|
)) });
|
|
619
|
-
}, q = ({ ...
|
|
607
|
+
}, q = ({ ...r }) => /* @__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
|
+
...r,
|
|
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 = ({ ...r }) => /* @__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
|
+
...r,
|
|
648
636
|
children: /* @__PURE__ */ l(
|
|
649
637
|
"path",
|
|
650
638
|
{
|
|
@@ -657,14 +645,14 @@ const T = (n) => {
|
|
|
657
645
|
)
|
|
658
646
|
}
|
|
659
647
|
), _ = ({
|
|
660
|
-
setViews:
|
|
648
|
+
setViews: r,
|
|
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 || r((e) => e === "days" ? "months" : e === "months" ? "years" : "days");
|
|
668
656
|
}, f = () => {
|
|
669
657
|
if (a === "years") {
|
|
670
658
|
i((e) => new Date(e.getFullYear() + 10, 0));
|
|
@@ -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(r) {
|
|
696
|
+
const a = new Date(r), 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 = (r) => {
|
|
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 = r, document.head.appendChild(a);
|
|
715
703
|
}
|
|
716
704
|
};
|
|
717
705
|
aa(I);
|
|
718
706
|
const ea = W(
|
|
719
707
|
({
|
|
720
|
-
value:
|
|
708
|
+
value: r,
|
|
721
709
|
onChange: a,
|
|
722
710
|
filter: t,
|
|
723
711
|
input: s = !0,
|
|
@@ -728,16 +716,16 @@ const ea = W(
|
|
|
728
716
|
size: h,
|
|
729
717
|
status: e
|
|
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: (r == null ? void 0 : r.from) || /* @__PURE__ */ new Date(),
|
|
721
|
+
to: (r == null ? void 0 : r.to) || /* @__PURE__ */ new Date()
|
|
734
722
|
});
|
|
735
723
|
D(() => {
|
|
736
|
-
|
|
724
|
+
r ? (y(r.from), p(r)) : (y(/* @__PURE__ */ new Date()), p({
|
|
737
725
|
from: /* @__PURE__ */ new Date(),
|
|
738
726
|
to: /* @__PURE__ */ new Date()
|
|
739
727
|
}));
|
|
740
|
-
}, [
|
|
728
|
+
}, [r]), 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 (!r)
|
|
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) || "-"}`;
|
|
@@ -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", ra = (r) => {
|
|
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 = r, document.head.appendChild(a);
|
|
867
855
|
}
|
|
868
856
|
};
|
|
869
|
-
|
|
870
|
-
const S = (
|
|
871
|
-
if (
|
|
857
|
+
ra(I);
|
|
858
|
+
const S = (r) => {
|
|
859
|
+
if (r === "sm")
|
|
872
860
|
return 16;
|
|
873
|
-
if (
|
|
861
|
+
if (r === "md")
|
|
874
862
|
return 16;
|
|
875
|
-
if (
|
|
863
|
+
if (r === "lg")
|
|
876
864
|
return 20;
|
|
877
|
-
},
|
|
878
|
-
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } =
|
|
865
|
+
}, na = (r) => {
|
|
866
|
+
const { size: a = "md", status: t = "default", variant: s = "outline", ...i } = r, 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: r,
|
|
942
930
|
setDate: a,
|
|
943
931
|
previewDate: t,
|
|
944
932
|
setPreviewDate: s,
|
|
@@ -953,10 +941,10 @@ const S = (n) => {
|
|
|
953
941
|
t.getMonth(),
|
|
954
942
|
1
|
|
955
943
|
), w = e.getDay(), b = [];
|
|
956
|
-
const k =
|
|
957
|
-
for (let
|
|
958
|
-
|
|
959
|
-
e.getDate() + (
|
|
944
|
+
const k = r.toDateString(), M = t.getMonth();
|
|
945
|
+
for (let n = 0; n < 42; n++) {
|
|
946
|
+
n === 0 && w === 0 ? e.setDate(e.getDate() - 7) : n === 0 ? e.setDate(
|
|
947
|
+
e.getDate() + (n - w)
|
|
960
948
|
) : e.setDate(e.getDate() + 1);
|
|
961
949
|
let c = {
|
|
962
950
|
currentMonth: e.getMonth() === M,
|
|
@@ -969,17 +957,17 @@ const S = (n) => {
|
|
|
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: r,
|
|
1000
988
|
setDate: a,
|
|
1001
989
|
filter: t,
|
|
1002
990
|
setViews: s,
|
|
@@ -1007,15 +995,15 @@ const S = (n) => {
|
|
|
1007
995
|
maxDate: h,
|
|
1008
996
|
input: e
|
|
1009
997
|
}) => {
|
|
1010
|
-
const w =
|
|
998
|
+
const w = r.getMonth(), b = r.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,
|
|
@@ -1023,18 +1011,18 @@ const S = (n) => {
|
|
|
1023
1011
|
...e ? {} : { 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 = (r) => {
|
|
1022
|
+
const a = Math.floor(r / 10) * 10, t = a + 10;
|
|
1035
1023
|
return { start: a, end: t };
|
|
1036
1024
|
}, ia = ({
|
|
1037
|
-
date:
|
|
1025
|
+
date: r,
|
|
1038
1026
|
filter: a,
|
|
1039
1027
|
setViews: t,
|
|
1040
1028
|
setDate: s,
|
|
@@ -1046,12 +1034,12 @@ const S = (n) => {
|
|
|
1046
1034
|
input: e
|
|
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 = r.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(
|
|
@@ -1065,21 +1053,21 @@ const S = (n) => {
|
|
|
1065
1053
|
...e ? {} : { 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: r,
|
|
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 || r((e) => e === "days" ? "months" : e === "months" ? "years" : "days");
|
|
1083
1071
|
}, f = () => {
|
|
1084
1072
|
if (a === "years") {
|
|
1085
1073
|
i((e) => new Date(e.getFullYear() + 10, 0));
|
|
@@ -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 = (r) => {
|
|
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 = r, document.head.appendChild(a);
|
|
1129
1117
|
}
|
|
1130
1118
|
};
|
|
1131
1119
|
la(I);
|
|
1132
1120
|
const ca = W(
|
|
1133
1121
|
({
|
|
1134
|
-
value:
|
|
1122
|
+
value: r,
|
|
1135
1123
|
onChange: a,
|
|
1136
1124
|
filter: t,
|
|
1137
1125
|
input: s = !0,
|
|
@@ -1142,17 +1130,17 @@ const ca = W(
|
|
|
1142
1130
|
size: h,
|
|
1143
1131
|
status: e
|
|
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
|
+
r ? (y(r), p(r)) : (y(/* @__PURE__ */ new Date()), p(/* @__PURE__ */ new Date()));
|
|
1136
|
+
}, [r]), 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 = () => r ? 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),
|
|
@@ -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: r,
|
|
1258
1246
|
onChange: a,
|
|
1259
1247
|
filter: t,
|
|
1260
1248
|
input: s = !0,
|
|
@@ -1269,7 +1257,7 @@ const ca = W(
|
|
|
1269
1257
|
ea,
|
|
1270
1258
|
{
|
|
1271
1259
|
onChange: a,
|
|
1272
|
-
value:
|
|
1260
|
+
value: r,
|
|
1273
1261
|
input: s,
|
|
1274
1262
|
filter: t,
|
|
1275
1263
|
disabled: g,
|
|
@@ -1284,7 +1272,7 @@ const ca = W(
|
|
|
1284
1272
|
ca,
|
|
1285
1273
|
{
|
|
1286
1274
|
onChange: a,
|
|
1287
|
-
value:
|
|
1275
|
+
value: r,
|
|
1288
1276
|
input: s,
|
|
1289
1277
|
filter: t,
|
|
1290
1278
|
disabled: g,
|
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);
|
|
51
|
+
--starasia-ui-date-color-secondary-blue: var(--starasia-ui-brand-primary-default);
|
|
52
|
+
--starasia-ui-date-color-tertiary-blue: var(--starasia-ui-brand-primary-secondary);
|
|
53
|
+
--starasia-ui-date-color-quaternary-blue: var(--starasia-ui-brand-primary-tertiary);
|
|
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), 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.3",
|
|
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
|
+
}
|