@starasia/date 5.2.0 → 5.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/date.es.js +114 -109
- package/dist/date.umd.js +4 -1
- package/package.json +1 -1
package/dist/date.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as Y, jsx as a, Fragment as en } from "react/jsx-runtime";
|
|
2
|
-
import { useState as A, useRef as
|
|
3
|
-
const
|
|
2
|
+
import { useState as A, useRef as R, useEffect as B, forwardRef as K } from "react";
|
|
3
|
+
const J = `@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
|
* {
|
|
6
6
|
margin: 0;
|
|
@@ -127,6 +127,9 @@ const R = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
127
127
|
|
|
128
128
|
.sa-calendar.sa-calendar-no-input {
|
|
129
129
|
position: relative !important;
|
|
130
|
+
/* Reset stacking context so the embedded calendar doesn't compete with
|
|
131
|
+
overlay siblings (e.g. nested Menu lists inside a popover). */
|
|
132
|
+
z-index: auto;
|
|
130
133
|
margin-top: 0px;
|
|
131
134
|
|
|
132
135
|
/* bellow is for input no input */
|
|
@@ -563,7 +566,7 @@ const R = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
|
|
|
563
566
|
"Dec"
|
|
564
567
|
];
|
|
565
568
|
function rn(r) {
|
|
566
|
-
const [e, t] = A(r), o =
|
|
569
|
+
const [e, t] = A(r), o = R(null), l = (c) => {
|
|
567
570
|
o.current && !o.current.contains(c.target) && t(!1);
|
|
568
571
|
};
|
|
569
572
|
return B(() => (document.addEventListener("click", l, !0), () => {
|
|
@@ -576,7 +579,7 @@ const Q = "sa-calendar-input-styles", dn = (r) => {
|
|
|
576
579
|
e.id = Q, e.textContent = r, document.head.appendChild(e);
|
|
577
580
|
}
|
|
578
581
|
};
|
|
579
|
-
dn(
|
|
582
|
+
dn(J);
|
|
580
583
|
const O = (r) => {
|
|
581
584
|
if (r === "sm")
|
|
582
585
|
return 16;
|
|
@@ -592,16 +595,16 @@ const O = (r) => {
|
|
|
592
595
|
clearable: l,
|
|
593
596
|
onClear: c,
|
|
594
597
|
...d
|
|
595
|
-
} = r, u =
|
|
598
|
+
} = r, u = R(null), p = () => {
|
|
596
599
|
u.current && d.onClick && (u.current.focus(), d.onClick(""));
|
|
597
|
-
}, n = t === "disable" || d.disabled, i = !!d.value,
|
|
600
|
+
}, n = t === "disable" || d.disabled, i = !!d.value, m = l && i && !n, k = (C) => {
|
|
598
601
|
C.stopPropagation(), c == null || c();
|
|
599
602
|
};
|
|
600
603
|
return /* @__PURE__ */ Y(
|
|
601
604
|
"div",
|
|
602
605
|
{
|
|
603
606
|
className: `sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${e} `,
|
|
604
|
-
onClick:
|
|
607
|
+
onClick: p,
|
|
605
608
|
children: [
|
|
606
609
|
/* @__PURE__ */ a("div", { className: "sa-calendar-input-container-icon-left", children: /* @__PURE__ */ a(
|
|
607
610
|
"svg",
|
|
@@ -633,7 +636,7 @@ const O = (r) => {
|
|
|
633
636
|
ref: u
|
|
634
637
|
}
|
|
635
638
|
) }),
|
|
636
|
-
|
|
639
|
+
m ? /* @__PURE__ */ a(
|
|
637
640
|
"button",
|
|
638
641
|
{
|
|
639
642
|
type: "button",
|
|
@@ -695,12 +698,12 @@ const O = (r) => {
|
|
|
695
698
|
input: u
|
|
696
699
|
}) => {
|
|
697
700
|
var g, w, $;
|
|
698
|
-
const [
|
|
699
|
-
let i = new Date(r.getFullYear(), r.getMonth(), 1),
|
|
700
|
-
const C = r.getMonth(),
|
|
701
|
+
const [p, n] = A(null);
|
|
702
|
+
let i = new Date(r.getFullYear(), r.getMonth(), 1), m = i.getDay(), k = [];
|
|
703
|
+
const C = r.getMonth(), v = (/* @__PURE__ */ new Date()).toDateString(), h = !!(t.from && !t.to), s = h && p ? p : null;
|
|
701
704
|
for (let f = 0; f < 42; f++) {
|
|
702
|
-
f === 0 &&
|
|
703
|
-
i.getDate() + (f -
|
|
705
|
+
f === 0 && m === 0 ? i.setDate(i.getDate() - 7) : f === 0 ? i.setDate(
|
|
706
|
+
i.getDate() + (f - m)
|
|
704
707
|
) : i.setDate(i.getDate() + 1);
|
|
705
708
|
let b = {
|
|
706
709
|
currentMonth: i.getMonth() === C,
|
|
@@ -708,7 +711,7 @@ const O = (r) => {
|
|
|
708
711
|
month: i.getMonth(),
|
|
709
712
|
number: i.getDate(),
|
|
710
713
|
selected: i.toDateString() === ((g = t.from) == null ? void 0 : g.toDateString()) || i.toDateString() === (((w = t.to) == null ? void 0 : w.toDateString()) || (($ = t.from) == null ? void 0 : $.toDateString())),
|
|
711
|
-
isToday: i.toDateString() ===
|
|
714
|
+
isToday: i.toDateString() === v,
|
|
712
715
|
year: i.getFullYear(),
|
|
713
716
|
isDisabled: c && i < c || d && i > d
|
|
714
717
|
};
|
|
@@ -740,7 +743,7 @@ const O = (r) => {
|
|
|
740
743
|
return !1;
|
|
741
744
|
const z = f.date.getTime(), M = t.from.getTime(), L = s.getTime();
|
|
742
745
|
return L > M ? z > M && z < L : z < M && z > L;
|
|
743
|
-
})(), D =
|
|
746
|
+
})(), D = h && p && f.date.toDateString() === p.toDateString(), F = f.isDisabled, I = () => T || S ? "var(--sa-color-info-alpha-a10, #64b5f61a)" : "", E = () => F ? "var(--sa-color-gray-400, #b7b9be)" : T || S ? "var(--sa-color-gray-500, #8c8f97)" : "";
|
|
744
747
|
return /* @__PURE__ */ a(
|
|
745
748
|
"p",
|
|
746
749
|
{
|
|
@@ -767,7 +770,7 @@ const O = (r) => {
|
|
|
767
770
|
]
|
|
768
771
|
}
|
|
769
772
|
);
|
|
770
|
-
},
|
|
773
|
+
}, pn = ({
|
|
771
774
|
date: r,
|
|
772
775
|
setDate: e,
|
|
773
776
|
filter: t,
|
|
@@ -776,29 +779,29 @@ const O = (r) => {
|
|
|
776
779
|
setDateRange: c,
|
|
777
780
|
onChange: d,
|
|
778
781
|
minDate: u,
|
|
779
|
-
maxDate:
|
|
782
|
+
maxDate: p,
|
|
780
783
|
input: n
|
|
781
784
|
}) => {
|
|
782
|
-
const i = l.from.getFullYear(),
|
|
783
|
-
t ? (C(
|
|
784
|
-
}, C = (
|
|
785
|
+
const i = l.from.getFullYear(), m = r.getFullYear(), k = (v) => {
|
|
786
|
+
t ? (C(v), e(v)) : (o("days"), e(v));
|
|
787
|
+
}, C = (v) => {
|
|
785
788
|
var s;
|
|
786
|
-
let
|
|
787
|
-
if (
|
|
788
|
-
|
|
789
|
+
let h = { ...l };
|
|
790
|
+
if (h.from && h.to)
|
|
791
|
+
h = { from: v, to: null };
|
|
789
792
|
else {
|
|
790
|
-
const x = ((s =
|
|
791
|
-
|
|
793
|
+
const x = ((s = h.from) == null ? void 0 : s.getTime()) || 0;
|
|
794
|
+
v.getTime() > x ? h = { from: h.from, to: v } : h = { from: v, to: h.from };
|
|
792
795
|
}
|
|
793
|
-
c(
|
|
796
|
+
c(h), d(h);
|
|
794
797
|
};
|
|
795
|
-
return /* @__PURE__ */ a("div", { className: "sa-calendar-months-preview", children: W.map((
|
|
798
|
+
return /* @__PURE__ */ a("div", { className: "sa-calendar-months-preview", children: W.map((v, h) => {
|
|
796
799
|
var N, g, w;
|
|
797
|
-
const s = new Date(
|
|
800
|
+
const s = new Date(m, h).getTime() > l.from.getTime() && new Date(m, h).getTime() < (((N = l.to) == null ? void 0 : N.getTime()) || l.from.getTime()), x = u && new Date(m, h) < u || p && new Date(m, h) > p;
|
|
798
801
|
return /* @__PURE__ */ a(
|
|
799
802
|
"p",
|
|
800
803
|
{
|
|
801
|
-
className: i ===
|
|
804
|
+
className: i === m && (h === ((g = l.from) == null ? void 0 : g.getMonth()) || h === ((w = l.to) == null ? void 0 : w.getMonth())) ? "sa-calendar-months-active" : "",
|
|
802
805
|
style: {
|
|
803
806
|
backgroundColor: s ? "var(--sa-color-info-alpha-a10, #64b5f61a)" : "",
|
|
804
807
|
pointerEvents: x ? "none" : void 0,
|
|
@@ -807,17 +810,17 @@ const O = (r) => {
|
|
|
807
810
|
...n ? {} : { width: "100%" }
|
|
808
811
|
},
|
|
809
812
|
onClick: () => {
|
|
810
|
-
x || k(new Date(
|
|
813
|
+
x || k(new Date(m, h));
|
|
811
814
|
},
|
|
812
|
-
children:
|
|
815
|
+
children: v.slice(0, 3)
|
|
813
816
|
},
|
|
814
|
-
|
|
817
|
+
h
|
|
815
818
|
);
|
|
816
819
|
}) });
|
|
817
820
|
}, q = (r) => {
|
|
818
821
|
const e = Math.floor(r / 10) * 10, t = e + 10;
|
|
819
822
|
return { start: e, end: t };
|
|
820
|
-
},
|
|
823
|
+
}, hn = ({
|
|
821
824
|
date: r,
|
|
822
825
|
filter: e,
|
|
823
826
|
setViews: t,
|
|
@@ -826,14 +829,14 @@ const O = (r) => {
|
|
|
826
829
|
setDateRange: c,
|
|
827
830
|
onChange: d,
|
|
828
831
|
minDate: u,
|
|
829
|
-
maxDate:
|
|
832
|
+
maxDate: p,
|
|
830
833
|
input: n
|
|
831
834
|
}) => {
|
|
832
835
|
var N;
|
|
833
836
|
let i = [];
|
|
834
|
-
const
|
|
837
|
+
const m = r.getFullYear(), { start: k, end: C } = q(m), v = l.from.getFullYear(), h = (N = l.to) == null ? void 0 : N.getFullYear();
|
|
835
838
|
for (let g = k; g < C; g++) {
|
|
836
|
-
const w = new Date(g, 0), $ = (!u || w >= u) && (!
|
|
839
|
+
const w = new Date(g, 0), $ = (!u || w >= u) && (!p || w <= p), f = g === v || g === h, b = w > l.from && w < l.to;
|
|
837
840
|
i.push({
|
|
838
841
|
year: g,
|
|
839
842
|
active: f && $,
|
|
@@ -975,7 +978,7 @@ const on = ({
|
|
|
975
978
|
helperText: c,
|
|
976
979
|
errorText: d,
|
|
977
980
|
fullWidth: u,
|
|
978
|
-
children:
|
|
981
|
+
children: p
|
|
979
982
|
}) => {
|
|
980
983
|
const n = [
|
|
981
984
|
"sa-date-field",
|
|
@@ -984,7 +987,7 @@ const on = ({
|
|
|
984
987
|
/* @__PURE__ */ a("span", { className: "sa-date-field-label-text", children: r }),
|
|
985
988
|
o && /* @__PURE__ */ a("span", { className: "sa-date-field-optional-badge", children: "Optional" }),
|
|
986
989
|
t && /* @__PURE__ */ a("span", { className: "sa-date-field-required", children: "*" })
|
|
987
|
-
] }) : null,
|
|
990
|
+
] }) : null, m = /* @__PURE__ */ Y(en, { children: [
|
|
988
991
|
c && !d && /* @__PURE__ */ a("p", { className: "sa-date-field-helper", children: c }),
|
|
989
992
|
d && /* @__PURE__ */ a("p", { className: "sa-date-field-error-msg", children: d })
|
|
990
993
|
] });
|
|
@@ -994,18 +997,18 @@ const on = ({
|
|
|
994
997
|
l && /* @__PURE__ */ a("p", { className: "sa-date-field-helper-top", children: l })
|
|
995
998
|
] }),
|
|
996
999
|
/* @__PURE__ */ Y("div", { className: "sa-date-field-input-wrap", children: [
|
|
997
|
-
|
|
998
|
-
|
|
1000
|
+
p,
|
|
1001
|
+
m
|
|
999
1002
|
] })
|
|
1000
1003
|
] }) : /* @__PURE__ */ Y("div", { className: n, children: [
|
|
1001
1004
|
i,
|
|
1002
1005
|
l && /* @__PURE__ */ a("p", { className: "sa-date-field-helper-top", children: l }),
|
|
1003
|
-
|
|
1004
|
-
|
|
1006
|
+
p,
|
|
1007
|
+
m
|
|
1005
1008
|
] }) : /* @__PURE__ */ Y("div", { className: n, children: [
|
|
1006
1009
|
l && /* @__PURE__ */ a("p", { className: "sa-date-field-helper-top", children: l }),
|
|
1007
|
-
|
|
1008
|
-
|
|
1010
|
+
p,
|
|
1011
|
+
m
|
|
1009
1012
|
] });
|
|
1010
1013
|
}, X = "sa-calendar-styles", fn = (r) => {
|
|
1011
1014
|
if (!document.getElementById(X)) {
|
|
@@ -1013,7 +1016,7 @@ const on = ({
|
|
|
1013
1016
|
e.id = X, e.textContent = r, document.head.appendChild(e);
|
|
1014
1017
|
}
|
|
1015
1018
|
};
|
|
1016
|
-
fn(
|
|
1019
|
+
fn(J);
|
|
1017
1020
|
const bn = K(
|
|
1018
1021
|
({
|
|
1019
1022
|
value: r,
|
|
@@ -1024,21 +1027,21 @@ const bn = K(
|
|
|
1024
1027
|
minDate: c,
|
|
1025
1028
|
maxDate: d,
|
|
1026
1029
|
placeholder: u,
|
|
1027
|
-
size:
|
|
1030
|
+
size: p,
|
|
1028
1031
|
variant: n,
|
|
1029
1032
|
status: i,
|
|
1030
|
-
clearable:
|
|
1033
|
+
clearable: m,
|
|
1031
1034
|
fullWidth: k = !0,
|
|
1032
1035
|
withPadding: C = !0,
|
|
1033
|
-
label:
|
|
1034
|
-
labelPosition:
|
|
1036
|
+
label: v,
|
|
1037
|
+
labelPosition: h,
|
|
1035
1038
|
required: s,
|
|
1036
1039
|
optional: x,
|
|
1037
1040
|
description: N,
|
|
1038
1041
|
helperText: g,
|
|
1039
1042
|
errorText: w
|
|
1040
1043
|
}, $) => {
|
|
1041
|
-
const f = w ? "error" : i, { ref: b, isComponentVisible: T, setIsComponentVisible: S } = rn(!1), D =
|
|
1044
|
+
const f = w ? "error" : i, { ref: b, isComponentVisible: T, setIsComponentVisible: S } = rn(!1), D = R(null), [F, I] = A("days"), [E, z] = A(/* @__PURE__ */ new Date()), [M, L] = A({
|
|
1042
1045
|
from: (r == null ? void 0 : r.from) || /* @__PURE__ */ new Date(),
|
|
1043
1046
|
to: (r == null ? void 0 : r.to) || /* @__PURE__ */ new Date()
|
|
1044
1047
|
});
|
|
@@ -1100,17 +1103,18 @@ const bn = K(
|
|
|
1100
1103
|
},
|
|
1101
1104
|
disabled: l,
|
|
1102
1105
|
placeholder: u,
|
|
1103
|
-
size:
|
|
1106
|
+
size: p,
|
|
1104
1107
|
variant: n,
|
|
1105
1108
|
status: f,
|
|
1106
|
-
clearable:
|
|
1109
|
+
clearable: m,
|
|
1107
1110
|
onClear: () => e(void 0)
|
|
1108
1111
|
}
|
|
1109
1112
|
) : null,
|
|
1110
1113
|
T ? /* @__PURE__ */ Y(
|
|
1111
1114
|
"div",
|
|
1112
1115
|
{
|
|
1113
|
-
className: `sa-calendar sa-calendar-size-${
|
|
1116
|
+
className: `sa-calendar sa-calendar-size-${p || "md"} ${o ? "" : "sa-calendar-no-input"} ${C ? "" : "sa-calendar-no-padding"}`,
|
|
1117
|
+
style: l ? { pointerEvents: "none" } : void 0,
|
|
1114
1118
|
ref: D,
|
|
1115
1119
|
children: [
|
|
1116
1120
|
/* @__PURE__ */ a(
|
|
@@ -1137,7 +1141,7 @@ const bn = K(
|
|
|
1137
1141
|
maxDate: d
|
|
1138
1142
|
}
|
|
1139
1143
|
) : F === "months" ? /* @__PURE__ */ a(
|
|
1140
|
-
|
|
1144
|
+
pn,
|
|
1141
1145
|
{
|
|
1142
1146
|
date: E,
|
|
1143
1147
|
setDate: z,
|
|
@@ -1152,7 +1156,7 @@ const bn = K(
|
|
|
1152
1156
|
maxDate: d
|
|
1153
1157
|
}
|
|
1154
1158
|
) : /* @__PURE__ */ a(
|
|
1155
|
-
|
|
1159
|
+
hn,
|
|
1156
1160
|
{
|
|
1157
1161
|
date: E,
|
|
1158
1162
|
setDate: z,
|
|
@@ -1176,8 +1180,8 @@ const bn = K(
|
|
|
1176
1180
|
return /* @__PURE__ */ a(
|
|
1177
1181
|
on,
|
|
1178
1182
|
{
|
|
1179
|
-
label:
|
|
1180
|
-
labelPosition:
|
|
1183
|
+
label: v,
|
|
1184
|
+
labelPosition: h,
|
|
1181
1185
|
required: s,
|
|
1182
1186
|
optional: x,
|
|
1183
1187
|
description: N,
|
|
@@ -1188,13 +1192,13 @@ const bn = K(
|
|
|
1188
1192
|
}
|
|
1189
1193
|
);
|
|
1190
1194
|
}
|
|
1191
|
-
), _ = "sa-calendar-input-styles",
|
|
1195
|
+
), _ = "sa-calendar-input-styles", vn = (r) => {
|
|
1192
1196
|
if (!document.getElementById(_)) {
|
|
1193
1197
|
const e = document.createElement("style");
|
|
1194
1198
|
e.id = _, e.textContent = r, document.head.appendChild(e);
|
|
1195
1199
|
}
|
|
1196
1200
|
};
|
|
1197
|
-
|
|
1201
|
+
vn(J);
|
|
1198
1202
|
const H = (r) => {
|
|
1199
1203
|
if (r === "sm")
|
|
1200
1204
|
return 16;
|
|
@@ -1202,7 +1206,7 @@ const H = (r) => {
|
|
|
1202
1206
|
return 16;
|
|
1203
1207
|
if (r === "lg")
|
|
1204
1208
|
return 20;
|
|
1205
|
-
},
|
|
1209
|
+
}, mn = (r) => {
|
|
1206
1210
|
const {
|
|
1207
1211
|
size: e = "md",
|
|
1208
1212
|
status: t = "default",
|
|
@@ -1210,16 +1214,16 @@ const H = (r) => {
|
|
|
1210
1214
|
clearable: l,
|
|
1211
1215
|
onClear: c,
|
|
1212
1216
|
...d
|
|
1213
|
-
} = r, u =
|
|
1217
|
+
} = r, u = R(null), p = () => {
|
|
1214
1218
|
u.current && d.onClick && (u.current.focus(), d.onClick(""));
|
|
1215
|
-
}, n = t === "disable" || d.disabled, i = !!d.value,
|
|
1219
|
+
}, n = t === "disable" || d.disabled, i = !!d.value, m = l && i && !n, k = (C) => {
|
|
1216
1220
|
C.stopPropagation(), c == null || c();
|
|
1217
1221
|
};
|
|
1218
1222
|
return /* @__PURE__ */ Y(
|
|
1219
1223
|
"div",
|
|
1220
1224
|
{
|
|
1221
1225
|
className: `sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${e} `,
|
|
1222
|
-
onClick:
|
|
1226
|
+
onClick: p,
|
|
1223
1227
|
children: [
|
|
1224
1228
|
/* @__PURE__ */ a("div", { className: "sa-calendar-input-container-icon-left", children: /* @__PURE__ */ a(
|
|
1225
1229
|
"svg",
|
|
@@ -1251,7 +1255,7 @@ const H = (r) => {
|
|
|
1251
1255
|
ref: u
|
|
1252
1256
|
}
|
|
1253
1257
|
) }),
|
|
1254
|
-
|
|
1258
|
+
m ? /* @__PURE__ */ a(
|
|
1255
1259
|
"button",
|
|
1256
1260
|
{
|
|
1257
1261
|
type: "button",
|
|
@@ -1311,20 +1315,20 @@ const H = (r) => {
|
|
|
1311
1315
|
minDate: c,
|
|
1312
1316
|
maxDate: d,
|
|
1313
1317
|
input: u,
|
|
1314
|
-
onChange:
|
|
1318
|
+
onChange: p
|
|
1315
1319
|
}) => {
|
|
1316
1320
|
let n = new Date(
|
|
1317
1321
|
t.getFullYear(),
|
|
1318
1322
|
t.getMonth(),
|
|
1319
1323
|
1
|
|
1320
|
-
), i = n.getDay(),
|
|
1321
|
-
const k = r.toDateString(), C = (/* @__PURE__ */ new Date()).toDateString(),
|
|
1324
|
+
), i = n.getDay(), m = [];
|
|
1325
|
+
const k = r.toDateString(), C = (/* @__PURE__ */ new Date()).toDateString(), v = t.getMonth();
|
|
1322
1326
|
for (let s = 0; s < 42; s++) {
|
|
1323
1327
|
s === 0 && i === 0 ? n.setDate(n.getDate() - 7) : s === 0 ? n.setDate(
|
|
1324
1328
|
n.getDate() + (s - i)
|
|
1325
1329
|
) : n.setDate(n.getDate() + 1);
|
|
1326
1330
|
let x = {
|
|
1327
|
-
currentMonth: n.getMonth() ===
|
|
1331
|
+
currentMonth: n.getMonth() === v,
|
|
1328
1332
|
date: new Date(n),
|
|
1329
1333
|
month: n.getMonth(),
|
|
1330
1334
|
number: n.getDate(),
|
|
@@ -1333,14 +1337,14 @@ const H = (r) => {
|
|
|
1333
1337
|
year: n.getFullYear(),
|
|
1334
1338
|
isDisabled: c && n < c || d && n > d
|
|
1335
1339
|
};
|
|
1336
|
-
|
|
1340
|
+
m.push(x);
|
|
1337
1341
|
}
|
|
1338
|
-
const
|
|
1339
|
-
(!c || s >= c) && (!d || s <= d) && (e(s),
|
|
1342
|
+
const h = (s) => {
|
|
1343
|
+
(!c || s >= c) && (!d || s <= d) && (e(s), p(s), o(s), u && l(!1));
|
|
1340
1344
|
};
|
|
1341
1345
|
return /* @__PURE__ */ Y("div", { className: "sa-calendar-days-preivew", children: [
|
|
1342
1346
|
/* @__PURE__ */ a("div", { className: "sa-calendar-days-name-preivew", children: an.map((s, x) => /* @__PURE__ */ a("p", { children: s }, x)) }),
|
|
1343
|
-
/* @__PURE__ */ a("div", { className: "sa-calendar-days-number-preivew", children:
|
|
1347
|
+
/* @__PURE__ */ a("div", { className: "sa-calendar-days-number-preivew", children: m.map((s, x) => {
|
|
1344
1348
|
const N = s.isDisabled;
|
|
1345
1349
|
return /* @__PURE__ */ a(
|
|
1346
1350
|
"p",
|
|
@@ -1353,7 +1357,7 @@ const H = (r) => {
|
|
|
1353
1357
|
...u ? {} : { width: "100%" }
|
|
1354
1358
|
},
|
|
1355
1359
|
onClick: () => {
|
|
1356
|
-
N ||
|
|
1360
|
+
N || h(s.date);
|
|
1357
1361
|
},
|
|
1358
1362
|
children: s.number
|
|
1359
1363
|
},
|
|
@@ -1370,18 +1374,18 @@ const H = (r) => {
|
|
|
1370
1374
|
previewDate: c,
|
|
1371
1375
|
setPreviewDate: d,
|
|
1372
1376
|
minDate: u,
|
|
1373
|
-
maxDate:
|
|
1377
|
+
maxDate: p,
|
|
1374
1378
|
input: n
|
|
1375
1379
|
}) => {
|
|
1376
|
-
const i = r.getMonth(),
|
|
1377
|
-
(!u ||
|
|
1380
|
+
const i = r.getMonth(), m = r.getFullYear(), k = c.getFullYear(), C = (v) => {
|
|
1381
|
+
(!u || v >= u) && (!p || v <= p) && (t ? (l(v), e(v), d(v)) : (o("days"), d(v)));
|
|
1378
1382
|
};
|
|
1379
|
-
return /* @__PURE__ */ a("div", { className: "sa-calendar-months-preview", children: W.map((
|
|
1380
|
-
const s = u && new Date(k,
|
|
1383
|
+
return /* @__PURE__ */ a("div", { className: "sa-calendar-months-preview", children: W.map((v, h) => {
|
|
1384
|
+
const s = u && new Date(k, h, 1) < u || p && new Date(k, h + 1, 0) > p;
|
|
1381
1385
|
return /* @__PURE__ */ a(
|
|
1382
1386
|
"p",
|
|
1383
1387
|
{
|
|
1384
|
-
className:
|
|
1388
|
+
className: h === i && k === m ? "sa-calendar-months-active" : "",
|
|
1385
1389
|
style: {
|
|
1386
1390
|
color: s ? "#ccc" : void 0,
|
|
1387
1391
|
pointerEvents: s ? "none" : void 0,
|
|
@@ -1389,11 +1393,11 @@ const H = (r) => {
|
|
|
1389
1393
|
...n ? {} : { width: "100%" }
|
|
1390
1394
|
},
|
|
1391
1395
|
onClick: () => {
|
|
1392
|
-
s || C(new Date(k,
|
|
1396
|
+
s || C(new Date(k, h));
|
|
1393
1397
|
},
|
|
1394
|
-
children:
|
|
1398
|
+
children: v.slice(0, 3)
|
|
1395
1399
|
},
|
|
1396
|
-
|
|
1400
|
+
h
|
|
1397
1401
|
);
|
|
1398
1402
|
}) });
|
|
1399
1403
|
}, Z = (r) => {
|
|
@@ -1408,17 +1412,17 @@ const H = (r) => {
|
|
|
1408
1412
|
previewDate: c,
|
|
1409
1413
|
setPreviewDate: d,
|
|
1410
1414
|
minDate: u,
|
|
1411
|
-
maxDate:
|
|
1415
|
+
maxDate: p,
|
|
1412
1416
|
input: n
|
|
1413
1417
|
}) => {
|
|
1414
1418
|
let i = [];
|
|
1415
|
-
const
|
|
1419
|
+
const m = c.getFullYear(), { start: k, end: C } = Z(m), v = r.getFullYear();
|
|
1416
1420
|
for (let s = k; s < C; s++) {
|
|
1417
|
-
let x = u && new Date(s, 0, 1) < u ||
|
|
1418
|
-
i.push({ year: s, active: s ===
|
|
1421
|
+
let x = u && new Date(s, 0, 1) < u || p && new Date(s, 11, 31) > p;
|
|
1422
|
+
i.push({ year: s, active: s === v, isDisabled: x });
|
|
1419
1423
|
}
|
|
1420
|
-
const
|
|
1421
|
-
(!u || s >= u) && (!
|
|
1424
|
+
const h = (s) => {
|
|
1425
|
+
(!u || s >= u) && (!p || s <= p) && (e ? (l(s), o(s), d(s)) : (t("months"), d(s)));
|
|
1422
1426
|
};
|
|
1423
1427
|
return /* @__PURE__ */ a("div", { className: "sa-calendar-years-preview", children: i.map((s, x) => /* @__PURE__ */ a(
|
|
1424
1428
|
"p",
|
|
@@ -1431,7 +1435,7 @@ const H = (r) => {
|
|
|
1431
1435
|
...n ? {} : { width: "100%" }
|
|
1432
1436
|
},
|
|
1433
1437
|
onClick: () => {
|
|
1434
|
-
s.isDisabled ||
|
|
1438
|
+
s.isDisabled || h(new Date(s.year, 0));
|
|
1435
1439
|
},
|
|
1436
1440
|
children: s.year
|
|
1437
1441
|
},
|
|
@@ -1496,7 +1500,7 @@ const H = (r) => {
|
|
|
1496
1500
|
e.id = nn, e.textContent = r, document.head.appendChild(e);
|
|
1497
1501
|
}
|
|
1498
1502
|
};
|
|
1499
|
-
Dn(
|
|
1503
|
+
Dn(J);
|
|
1500
1504
|
const Mn = K(
|
|
1501
1505
|
({
|
|
1502
1506
|
value: r,
|
|
@@ -1507,21 +1511,21 @@ const Mn = K(
|
|
|
1507
1511
|
minDate: c,
|
|
1508
1512
|
maxDate: d,
|
|
1509
1513
|
placeholder: u,
|
|
1510
|
-
size:
|
|
1514
|
+
size: p,
|
|
1511
1515
|
variant: n,
|
|
1512
1516
|
status: i,
|
|
1513
|
-
clearable:
|
|
1517
|
+
clearable: m,
|
|
1514
1518
|
fullWidth: k = !0,
|
|
1515
1519
|
withPadding: C = !0,
|
|
1516
|
-
label:
|
|
1517
|
-
labelPosition:
|
|
1520
|
+
label: v,
|
|
1521
|
+
labelPosition: h,
|
|
1518
1522
|
required: s,
|
|
1519
1523
|
optional: x,
|
|
1520
1524
|
description: N,
|
|
1521
1525
|
helperText: g,
|
|
1522
1526
|
errorText: w
|
|
1523
1527
|
}, $) => {
|
|
1524
|
-
const f = w ? "error" : i, { ref: b, isComponentVisible: T, setIsComponentVisible: S } = rn(!1), D =
|
|
1528
|
+
const f = w ? "error" : i, { ref: b, isComponentVisible: T, setIsComponentVisible: S } = rn(!1), D = R(null), [F, I] = A("days"), [E, z] = A(/* @__PURE__ */ new Date()), [M, L] = A(/* @__PURE__ */ new Date());
|
|
1525
1529
|
B(() => {
|
|
1526
1530
|
r ? (z(r), L(r)) : (z(/* @__PURE__ */ new Date()), L(/* @__PURE__ */ new Date()));
|
|
1527
1531
|
}, [r]), B(() => {
|
|
@@ -1553,7 +1557,7 @@ const Mn = K(
|
|
|
1553
1557
|
ref: o ? b : null,
|
|
1554
1558
|
children: [
|
|
1555
1559
|
o ? /* @__PURE__ */ a(
|
|
1556
|
-
|
|
1560
|
+
mn,
|
|
1557
1561
|
{
|
|
1558
1562
|
value: G(),
|
|
1559
1563
|
onClick: () => S(!0),
|
|
@@ -1561,18 +1565,19 @@ const Mn = K(
|
|
|
1561
1565
|
},
|
|
1562
1566
|
placeholder: u,
|
|
1563
1567
|
disabled: l,
|
|
1564
|
-
size:
|
|
1568
|
+
size: p,
|
|
1565
1569
|
variant: n,
|
|
1566
1570
|
status: f,
|
|
1567
1571
|
inputMode: "none",
|
|
1568
|
-
clearable:
|
|
1572
|
+
clearable: m,
|
|
1569
1573
|
onClear: () => e(void 0)
|
|
1570
1574
|
}
|
|
1571
1575
|
) : null,
|
|
1572
1576
|
T ? /* @__PURE__ */ Y(
|
|
1573
1577
|
"div",
|
|
1574
1578
|
{
|
|
1575
|
-
className: `sa-calendar sa-calendar-size-${
|
|
1579
|
+
className: `sa-calendar sa-calendar-size-${p || "md"} ${o ? "" : "sa-calendar-no-input"} ${C ? "" : "sa-calendar-no-padding"}`,
|
|
1580
|
+
style: l ? { pointerEvents: "none" } : void 0,
|
|
1576
1581
|
ref: D,
|
|
1577
1582
|
children: [
|
|
1578
1583
|
/* @__PURE__ */ a(
|
|
@@ -1637,8 +1642,8 @@ const Mn = K(
|
|
|
1637
1642
|
return /* @__PURE__ */ a(
|
|
1638
1643
|
on,
|
|
1639
1644
|
{
|
|
1640
|
-
label:
|
|
1641
|
-
labelPosition:
|
|
1645
|
+
label: v,
|
|
1646
|
+
labelPosition: h,
|
|
1642
1647
|
required: s,
|
|
1643
1648
|
optional: x,
|
|
1644
1649
|
description: N,
|
|
@@ -1659,14 +1664,14 @@ const Mn = K(
|
|
|
1659
1664
|
disabled: c,
|
|
1660
1665
|
minDate: d,
|
|
1661
1666
|
maxDate: u,
|
|
1662
|
-
placeholder:
|
|
1667
|
+
placeholder: p,
|
|
1663
1668
|
size: n,
|
|
1664
1669
|
variant: i,
|
|
1665
|
-
status:
|
|
1670
|
+
status: m,
|
|
1666
1671
|
clearable: k,
|
|
1667
1672
|
fullWidth: C,
|
|
1668
|
-
withPadding:
|
|
1669
|
-
label:
|
|
1673
|
+
withPadding: v,
|
|
1674
|
+
label: h,
|
|
1670
1675
|
labelPosition: s,
|
|
1671
1676
|
required: x,
|
|
1672
1677
|
optional: N,
|
|
@@ -1682,14 +1687,14 @@ const Mn = K(
|
|
|
1682
1687
|
disabled: c,
|
|
1683
1688
|
minDate: d,
|
|
1684
1689
|
maxDate: u,
|
|
1685
|
-
placeholder:
|
|
1690
|
+
placeholder: p,
|
|
1686
1691
|
size: n,
|
|
1687
1692
|
variant: i,
|
|
1688
|
-
status:
|
|
1693
|
+
status: m,
|
|
1689
1694
|
clearable: k,
|
|
1690
1695
|
fullWidth: C,
|
|
1691
|
-
withPadding:
|
|
1692
|
-
label:
|
|
1696
|
+
withPadding: v,
|
|
1697
|
+
label: h,
|
|
1693
1698
|
labelPosition: s,
|
|
1694
1699
|
required: x,
|
|
1695
1700
|
optional: N,
|
package/dist/date.umd.js
CHANGED
|
@@ -125,6 +125,9 @@
|
|
|
125
125
|
|
|
126
126
|
.sa-calendar.sa-calendar-no-input {
|
|
127
127
|
position: relative !important;
|
|
128
|
+
/* Reset stacking context so the embedded calendar doesn't compete with
|
|
129
|
+
overlay siblings (e.g. nested Menu lists inside a popover). */
|
|
130
|
+
z-index: auto;
|
|
128
131
|
margin-top: 0px;
|
|
129
132
|
|
|
130
133
|
/* bellow is for input no input */
|
|
@@ -533,4 +536,4 @@
|
|
|
533
536
|
width: 32px;
|
|
534
537
|
height: 32px;
|
|
535
538
|
}
|
|
536
|
-
`,Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A=["January","February","March","April","May","June","July","August","September","October","November","December"],rn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function K(r){const[a,t]=x.useState(r),o=x.useRef(null),l=c=>{o.current&&!o.current.contains(c.target)&&t(!1)};return x.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:t}}const Q="sa-calendar-input-styles";(r=>{if(!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=r,document.head.appendChild(a)}})(P);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},tn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,p=x.useRef(null),h=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:p})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})})]})},sn=({date:r,setDate:a,dateRange:t,setDateRange:o,onChange:l,minDate:c,maxDate:d,input:p})=>{var u,m,Y;const[h,e]=x.useState(null);let i=new Date(r.getFullYear(),r.getMonth(),1),y=i.getDay(),D=[];const N=r.getMonth(),v=new Date().toDateString(),f=!!(t.from&&!t.to),s=f&&h?h:null;for(let g=0;g<42;g++){g===0&&y===0?i.setDate(i.getDate()-7):g===0?i.setDate(i.getDate()+(g-y)):i.setDate(i.getDate()+1);let b={currentMonth:i.getMonth()===N,date:new Date(i),month:i.getMonth(),number:i.getDate(),selected:i.toDateString()===((u=t.from)==null?void 0:u.toDateString())||i.toDateString()===(((m=t.to)==null?void 0:m.toDateString())||((Y=t.from)==null?void 0:Y.toDateString())),isToday:i.toDateString()===v,year:i.getFullYear(),isDisabled:c&&i<c||d&&i>d};D.push(b)}const k=g=>{a(g)},$=g=>{var L;let b={...t};if(b.from&&b.to)b={from:g,to:null};else{const T=((L=b.from)==null?void 0:L.getTime())||0;g.getTime()>T?b={from:b.from,to:g}:b={from:g,to:b.from}}o(b),l(b)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>e(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((g,b)=>n.jsx("p",{children:g},b))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((g,b)=>{const L=t.from&&t.to&&g.date.getTime()>t.from.getTime()&&g.date.getTime()<t.to.getTime(),T=(()=>{if(!s||!t.from)return!1;const z=g.date.getTime(),C=t.from.getTime(),F=s.getTime();return F>C?z>C&&z<F:z<C&&z>F})(),M=f&&h&&g.date.toDateString()===h.toDateString(),E=g.isDisabled,I=()=>L||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",S=()=>E?"var(--sa-color-gray-400, #b7b9be)":L||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${g.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${g.selected||M?"sa-calendar-days-active":""} ${g.isToday&&!g.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:E?"none":void 0,cursor:E?"not-allowed":"pointer",color:S(),opacity:M&&!g.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{E||(k(g.date),$(g.date))},onMouseEnter:()=>{E||e(g.date)},children:g.number},b)})})]})},on=({date:r,setDate:a,filter:t,setViews:o,dateRange:l,setDateRange:c,onChange:d,minDate:p,maxDate:h,input:e})=>{const i=l.from.getFullYear(),y=r.getFullYear(),D=v=>{t?(N(v),a(v)):(o("days"),a(v))},N=v=>{var s;let f={...l};if(f.from&&f.to)f={from:v,to:null};else{const k=((s=f.from)==null?void 0:s.getTime())||0;v.getTime()>k?f={from:f.from,to:v}:f={from:v,to:f.from}}c(f),d(f)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{var $,u,m;const s=new Date(y,f).getTime()>l.from.getTime()&&new Date(y,f).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=p&&new Date(y,f)<p||h&&new Date(y,f)>h;return n.jsx("p",{className:i===y&&(f===((u=l.from)==null?void 0:u.getMonth())||f===((m=l.to)==null?void 0:m.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:s?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:k?"none":void 0,cursor:k?"not-allowed":"pointer",color:k?"var(--sa-color-gray-400, #b7b9be)":s?"var(--sa-color-gray-500, #8c8f97)":"",...e?{}:{width:"100%"}},onClick:()=>{k||D(new Date(y,f))},children:v.slice(0,3)},f)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},ln=({date:r,filter:a,setViews:t,setDate:o,dateRange:l,setDateRange:c,onChange:d,minDate:p,maxDate:h,input:e})=>{var $;let i=[];const y=r.getFullYear(),{start:D,end:N}=J(y),v=l.from.getFullYear(),f=($=l.to)==null?void 0:$.getFullYear();for(let u=D;u<N;u++){const m=new Date(u,0),Y=(!p||m>=p)&&(!h||m<=h),g=u===v||u===f,b=m>l.from&&m<l.to;i.push({year:u,active:g&&Y,highlight:b&&Y,disabled:!Y})}const s=u=>{a?(k(u),o(u)):(o(u),t("months"))},k=u=>{var Y;let m={...l};if(m.from&&m.to)m={from:u,to:null};else{const g=((Y=m.from)==null?void 0:Y.getTime())||0;u.getTime()>g?m={from:m.from,to:u}:m={from:u,to:m.from}}c(m),d(m)};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((u,m)=>n.jsx("p",{className:`${u.active?"sa-calendar-months-active":""} ${u.highlight?"sa-calendar-months-highlight":""} ${u.disabled?"sa-calendar-disabled":""}`,onClick:()=>{u.disabled||s(new Date(u.year,0))},style:{backgroundColor:u.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:u.highlight?"var(--sa-color-gray-500, #8c8f97)":u.active?"":u.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:u.disabled?"not-allowed":"pointer",pointerEvents:u.disbled?"none":"all",...e?{}:{width:"100%"}},children:u.year},m))})},X=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.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"})}),_=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.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"})}),dn=({setViews:r,views:a,filter:t,date:o,setDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},p=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},h=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${J(o.getFullYear()).start} ~ ${J(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:c,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})};function W(r){const a=new Date(r),t=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${rn[o]} ${t}`}const R=({label:r,labelPosition:a="outside-top",required:t,optional:o,description:l,helperText:c,errorText:d,fullWidth:p,children:h})=>{const e=["sa-date-field",p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),i=r?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:r}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,y=n.jsxs(n.Fragment,{children:[c&&!d&&n.jsx("p",{className:"sa-date-field-helper",children:c}),d&&n.jsx("p",{className:"sa-date-field-error-msg",children:d})]});return r?a==="outside-left"?n.jsxs("div",{className:`${e} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[h,y]})]}):n.jsxs("div",{className:e,children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,y]}):n.jsxs("div",{className:e,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),h,y]})},nn="sa-calendar-styles";(r=>{if(!document.getElementById(nn)){const a=document.createElement("style");a.id=nn,a.textContent=r,document.head.appendChild(a)}})(P);const cn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:p,size:h,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});x.useEffect(()=>{r?(z(r.from),F(r)):(z(new Date),F({from:new Date,to:new Date}))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var w,j;if(!r)return"";if(t){if(E==="days")return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`;if(E==="months")return`${A[C.from.getMonth()]} ~ ${C.to?A[C.to.getMonth()]:"-"}`;if(E==="years")return`${(w=C.from)==null?void 0:w.getFullYear()} ~ ${((j=C.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`},B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:p,size:h,variant:e,status:g,clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,ref:M,children:[n.jsx(dn,{setViews:I,views:E,filter:t,date:S,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(sn,{date:S,setDate:z,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:a,minDate:c,maxDate:d}):E==="months"?n.jsx(on,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d}):n.jsx(ln,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(r=>{if(!document.getElementById(en)){const a=document.createElement("style");a.id=en,a.textContent=r,document.head.appendChild(a)}})(P);const H=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},hn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,p=x.useRef(null),h=()=>{p.current&&d.onClick&&(p.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:h,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:p})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})})]})},pn=({date:r,setDate:a,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:c,maxDate:d,input:p,onChange:h})=>{let e=new Date(t.getFullYear(),t.getMonth(),1),i=e.getDay(),y=[];const D=r.toDateString(),N=new Date().toDateString(),v=t.getMonth();for(let s=0;s<42;s++){s===0&&i===0?e.setDate(e.getDate()-7):s===0?e.setDate(e.getDate()+(s-i)):e.setDate(e.getDate()+1);let k={currentMonth:e.getMonth()===v,date:new Date(e),month:e.getMonth(),number:e.getDate(),selected:e.toDateString()===D,isToday:e.toDateString()===N,year:e.getFullYear(),isDisabled:c&&e<c||d&&e>d};y.push(k)}const f=s=>{(!c||s>=c)&&(!d||s<=d)&&(a(s),h(s),o(s),p&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((s,k)=>n.jsx("p",{children:s},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:y.map((s,k)=>{const $=s.isDisabled;return n.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.selected?"sa-calendar-days-active":""} ${s.isToday&&!s.selected?"sa-calendar-days-today":""}`,style:{color:$?"#ccc":void 0,pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{$||f(s.date)},children:s.number},k)})})]})},fn=({date:r,setDate:a,filter:t,setViews:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:p,maxDate:h,input:e})=>{const i=r.getMonth(),y=r.getFullYear(),D=c.getFullYear(),N=v=>{(!p||v>=p)&&(!h||v<=h)&&(t?(l(v),a(v),d(v)):(o("days"),d(v)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{const s=p&&new Date(D,f,1)<p||h&&new Date(D,f+1,0)>h;return n.jsx("p",{className:f===i&&D===y?"sa-calendar-months-active":"",style:{color:s?"#ccc":void 0,pointerEvents:s?"none":void 0,cursor:s?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s||N(new Date(D,f))},children:v.slice(0,3)},f)})})},q=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},un=({date:r,filter:a,setViews:t,setDate:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:p,maxDate:h,input:e})=>{let i=[];const y=c.getFullYear(),{start:D,end:N}=q(y),v=r.getFullYear();for(let s=D;s<N;s++){let k=p&&new Date(s,0,1)<p||h&&new Date(s,11,31)>h;i.push({year:s,active:s===v,isDisabled:k})}const f=s=>{(!p||s>=p)&&(!h||s<=h)&&(a?(l(s),o(s),d(s)):(t("months"),d(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((s,k)=>n.jsx("p",{className:s.active?"sa-calendar-months-active":"",style:{color:s.isDisabled?"#ccc":void 0,pointerEvents:s.isDisabled?"none":void 0,cursor:s.isDisabled?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s.isDisabled||f(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:r,views:a,filter:t,previewDate:o,setPreviewDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},p=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},h=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${q(o.getFullYear()).start} ~ ${q(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:c,children:h()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(r=>{if(!document.getElementById(an)){const a=document.createElement("style");a.id=an,a.textContent=r,document.head.appendChild(a)}})(P);const bn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:p,size:h,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState(new Date);x.useEffect(()=>{r?(z(r),F(r)):(z(new Date),F(new Date))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>r?t==="days"?W(S):t==="months"?`${A[S.getMonth()]} ${S.getFullYear()}`:t==="years"?S.getFullYear():W(S):"",B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(hn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:p,disabled:l,size:h,variant:e,status:g,inputMode:"none",clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,ref:M,children:[n.jsx(gn,{setViews:I,views:E,filter:t,previewDate:C,setPreviewDate:F,isComponentVisible:L}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(pn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,setIsComponentVisible:T,input:o,minDate:c,maxDate:d,onChange:a}):E==="months"?n.jsx(fn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o}):n.jsx(un,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),vn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,rangedDate:l,disabled:c,minDate:d,maxDate:p,placeholder:h,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y},g)=>{const b={onChange:a,value:r,input:o,filter:t,disabled:c,minDate:d,maxDate:p,placeholder:h,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...b,ref:g}):n.jsx(bn,{...b,ref:g})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|
|
539
|
+
`,Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],A=["January","February","March","April","May","June","July","August","September","October","November","December"],rn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function K(r){const[a,t]=x.useState(r),o=x.useRef(null),l=c=>{o.current&&!o.current.contains(c.target)&&t(!1)};return x.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:t}}const Q="sa-calendar-input-styles";(r=>{if(!document.getElementById(Q)){const a=document.createElement("style");a.id=Q,a.textContent=r,document.head.appendChild(a)}})(P);const O=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},tn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,h=x.useRef(null),p=()=>{h.current&&d.onClick&&(h.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:h})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:O(a),height:O(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})})]})},sn=({date:r,setDate:a,dateRange:t,setDateRange:o,onChange:l,minDate:c,maxDate:d,input:h})=>{var u,m,Y;const[p,e]=x.useState(null);let i=new Date(r.getFullYear(),r.getMonth(),1),y=i.getDay(),D=[];const N=r.getMonth(),v=new Date().toDateString(),f=!!(t.from&&!t.to),s=f&&p?p:null;for(let g=0;g<42;g++){g===0&&y===0?i.setDate(i.getDate()-7):g===0?i.setDate(i.getDate()+(g-y)):i.setDate(i.getDate()+1);let b={currentMonth:i.getMonth()===N,date:new Date(i),month:i.getMonth(),number:i.getDate(),selected:i.toDateString()===((u=t.from)==null?void 0:u.toDateString())||i.toDateString()===(((m=t.to)==null?void 0:m.toDateString())||((Y=t.from)==null?void 0:Y.toDateString())),isToday:i.toDateString()===v,year:i.getFullYear(),isDisabled:c&&i<c||d&&i>d};D.push(b)}const k=g=>{a(g)},$=g=>{var L;let b={...t};if(b.from&&b.to)b={from:g,to:null};else{const T=((L=b.from)==null?void 0:L.getTime())||0;g.getTime()>T?b={from:b.from,to:g}:b={from:g,to:b.from}}o(b),l(b)};return n.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>e(null),children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((g,b)=>n.jsx("p",{children:g},b))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:D.map((g,b)=>{const L=t.from&&t.to&&g.date.getTime()>t.from.getTime()&&g.date.getTime()<t.to.getTime(),T=(()=>{if(!s||!t.from)return!1;const z=g.date.getTime(),C=t.from.getTime(),F=s.getTime();return F>C?z>C&&z<F:z<C&&z>F})(),M=f&&p&&g.date.toDateString()===p.toDateString(),E=g.isDisabled,I=()=>L||T?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",S=()=>E?"var(--sa-color-gray-400, #b7b9be)":L||T?"var(--sa-color-gray-500, #8c8f97)":"";return n.jsx("p",{className:`${g.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${g.selected||M?"sa-calendar-days-active":""} ${g.isToday&&!g.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:I(),pointerEvents:E?"none":void 0,cursor:E?"not-allowed":"pointer",color:S(),opacity:M&&!g.selected?.75:1,...h?{}:{width:"100%"}},onClick:()=>{E||(k(g.date),$(g.date))},onMouseEnter:()=>{E||e(g.date)},children:g.number},b)})})]})},on=({date:r,setDate:a,filter:t,setViews:o,dateRange:l,setDateRange:c,onChange:d,minDate:h,maxDate:p,input:e})=>{const i=l.from.getFullYear(),y=r.getFullYear(),D=v=>{t?(N(v),a(v)):(o("days"),a(v))},N=v=>{var s;let f={...l};if(f.from&&f.to)f={from:v,to:null};else{const k=((s=f.from)==null?void 0:s.getTime())||0;v.getTime()>k?f={from:f.from,to:v}:f={from:v,to:f.from}}c(f),d(f)};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{var $,u,m;const s=new Date(y,f).getTime()>l.from.getTime()&&new Date(y,f).getTime()<((($=l.to)==null?void 0:$.getTime())||l.from.getTime()),k=h&&new Date(y,f)<h||p&&new Date(y,f)>p;return n.jsx("p",{className:i===y&&(f===((u=l.from)==null?void 0:u.getMonth())||f===((m=l.to)==null?void 0:m.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:s?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:k?"none":void 0,cursor:k?"not-allowed":"pointer",color:k?"var(--sa-color-gray-400, #b7b9be)":s?"var(--sa-color-gray-500, #8c8f97)":"",...e?{}:{width:"100%"}},onClick:()=>{k||D(new Date(y,f))},children:v.slice(0,3)},f)})})},J=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},ln=({date:r,filter:a,setViews:t,setDate:o,dateRange:l,setDateRange:c,onChange:d,minDate:h,maxDate:p,input:e})=>{var $;let i=[];const y=r.getFullYear(),{start:D,end:N}=J(y),v=l.from.getFullYear(),f=($=l.to)==null?void 0:$.getFullYear();for(let u=D;u<N;u++){const m=new Date(u,0),Y=(!h||m>=h)&&(!p||m<=p),g=u===v||u===f,b=m>l.from&&m<l.to;i.push({year:u,active:g&&Y,highlight:b&&Y,disabled:!Y})}const s=u=>{a?(k(u),o(u)):(o(u),t("months"))},k=u=>{var Y;let m={...l};if(m.from&&m.to)m={from:u,to:null};else{const g=((Y=m.from)==null?void 0:Y.getTime())||0;u.getTime()>g?m={from:m.from,to:u}:m={from:u,to:m.from}}c(m),d(m)};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((u,m)=>n.jsx("p",{className:`${u.active?"sa-calendar-months-active":""} ${u.highlight?"sa-calendar-months-highlight":""} ${u.disabled?"sa-calendar-disabled":""}`,onClick:()=>{u.disabled||s(new Date(u.year,0))},style:{backgroundColor:u.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:u.highlight?"var(--sa-color-gray-500, #8c8f97)":u.active?"":u.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:u.disabled?"not-allowed":"pointer",pointerEvents:u.disbled?"none":"all",...e?{}:{width:"100%"}},children:u.year},m))})},X=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.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"})}),_=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.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"})}),dn=({setViews:r,views:a,filter:t,date:o,setDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},h=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${J(o.getFullYear()).start} ~ ${J(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:c,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:h,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})};function W(r){const a=new Date(r),t=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${rn[o]} ${t}`}const R=({label:r,labelPosition:a="outside-top",required:t,optional:o,description:l,helperText:c,errorText:d,fullWidth:h,children:p})=>{const e=["sa-date-field",h?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),i=r?n.jsxs("div",{className:"sa-date-field-label-row",children:[n.jsx("span",{className:"sa-date-field-label-text",children:r}),o&&n.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,y=n.jsxs(n.Fragment,{children:[c&&!d&&n.jsx("p",{className:"sa-date-field-helper",children:c}),d&&n.jsx("p",{className:"sa-date-field-error-msg",children:d})]});return r?a==="outside-left"?n.jsxs("div",{className:`${e} sa-date-field-left`,children:[n.jsxs("div",{className:"sa-date-field-left-label",children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l})]}),n.jsxs("div",{className:"sa-date-field-input-wrap",children:[p,y]})]}):n.jsxs("div",{className:e,children:[i,l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]}):n.jsxs("div",{className:e,children:[l&&n.jsx("p",{className:"sa-date-field-helper-top",children:l}),p,y]})},nn="sa-calendar-styles";(r=>{if(!document.getElementById(nn)){const a=document.createElement("style");a.id=nn,a.textContent=r,document.head.appendChild(a)}})(P);const cn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:h,size:p,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});x.useEffect(()=>{r?(z(r.from),F(r)):(z(new Date),F({from:new Date,to:new Date}))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>{var w,j;if(!r)return"";if(t){if(E==="days")return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`;if(E==="months")return`${A[C.from.getMonth()]} ~ ${C.to?A[C.to.getMonth()]:"-"}`;if(E==="years")return`${(w=C.from)==null?void 0:w.getFullYear()} ~ ${((j=C.to)==null?void 0:j.getFullYear())||"-"}`}else return`${W(C.from)} ~ ${W(C.to||C.from)||"-"}`},B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(tn,{value:G(),inputMode:"none",onClick:()=>{T(!0)},onChange:()=>{},disabled:l,placeholder:h,size:p,variant:e,status:g,clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:M,children:[n.jsx(dn,{setViews:I,views:E,filter:t,date:S,setDate:z}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(sn,{date:S,setDate:z,setIsComponentVisible:T,dateRange:C,setDateRange:F,input:o,onChange:a,minDate:c,maxDate:d}):E==="months"?n.jsx(on,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d}):n.jsx(ln,{date:S,setDate:z,filter:t,setViews:I,dateRange:C,setDateRange:F,setIsComponentVisible:T,input:o,onChange:a,minDate:c,maxDate:d})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),en="sa-calendar-input-styles";(r=>{if(!document.getElementById(en)){const a=document.createElement("style");a.id=en,a.textContent=r,document.head.appendChild(a)}})(P);const H=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},pn=r=>{const{size:a="md",status:t="default",variant:o="outline",clearable:l,onClear:c,...d}=r,h=x.useRef(null),p=()=>{h.current&&d.onClick&&(h.current.focus(),d.onClick(""))},e=t==="disable"||d.disabled,i=!!d.value,y=l&&i&&!e,D=N=>{N.stopPropagation(),c==null||c()};return n.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${t} ${a} `,onClick:p,children:[n.jsx("div",{className:"sa-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})}),n.jsx("div",{className:"sa-calendar-input-preview-container",children:n.jsx("input",{className:"sa-calendar-input",...d,disabled:e,value:d.value,ref:h})}),y?n.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:D,children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):n.jsx("div",{className:"sa-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:H(a),height:H(a),viewBox:"0 0 20 20",fill:"none",children:n.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"})})})]})},hn=({date:r,setDate:a,previewDate:t,setPreviewDate:o,setIsComponentVisible:l,minDate:c,maxDate:d,input:h,onChange:p})=>{let e=new Date(t.getFullYear(),t.getMonth(),1),i=e.getDay(),y=[];const D=r.toDateString(),N=new Date().toDateString(),v=t.getMonth();for(let s=0;s<42;s++){s===0&&i===0?e.setDate(e.getDate()-7):s===0?e.setDate(e.getDate()+(s-i)):e.setDate(e.getDate()+1);let k={currentMonth:e.getMonth()===v,date:new Date(e),month:e.getMonth(),number:e.getDate(),selected:e.toDateString()===D,isToday:e.toDateString()===N,year:e.getFullYear(),isDisabled:c&&e<c||d&&e>d};y.push(k)}const f=s=>{(!c||s>=c)&&(!d||s<=d)&&(a(s),p(s),o(s),h&&l(!1))};return n.jsxs("div",{className:"sa-calendar-days-preivew",children:[n.jsx("div",{className:"sa-calendar-days-name-preivew",children:Z.map((s,k)=>n.jsx("p",{children:s},k))}),n.jsx("div",{className:"sa-calendar-days-number-preivew",children:y.map((s,k)=>{const $=s.isDisabled;return n.jsx("p",{className:`${s.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${s.selected?"sa-calendar-days-active":""} ${s.isToday&&!s.selected?"sa-calendar-days-today":""}`,style:{color:$?"#ccc":void 0,pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",...h?{}:{width:"100%"}},onClick:()=>{$||f(s.date)},children:s.number},k)})})]})},fn=({date:r,setDate:a,filter:t,setViews:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:h,maxDate:p,input:e})=>{const i=r.getMonth(),y=r.getFullYear(),D=c.getFullYear(),N=v=>{(!h||v>=h)&&(!p||v<=p)&&(t?(l(v),a(v),d(v)):(o("days"),d(v)))};return n.jsx("div",{className:"sa-calendar-months-preview",children:A.map((v,f)=>{const s=h&&new Date(D,f,1)<h||p&&new Date(D,f+1,0)>p;return n.jsx("p",{className:f===i&&D===y?"sa-calendar-months-active":"",style:{color:s?"#ccc":void 0,pointerEvents:s?"none":void 0,cursor:s?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s||N(new Date(D,f))},children:v.slice(0,3)},f)})})},q=r=>{const a=Math.floor(r/10)*10,t=a+10;return{start:a,end:t}},un=({date:r,filter:a,setViews:t,setDate:o,onChange:l,previewDate:c,setPreviewDate:d,minDate:h,maxDate:p,input:e})=>{let i=[];const y=c.getFullYear(),{start:D,end:N}=q(y),v=r.getFullYear();for(let s=D;s<N;s++){let k=h&&new Date(s,0,1)<h||p&&new Date(s,11,31)>p;i.push({year:s,active:s===v,isDisabled:k})}const f=s=>{(!h||s>=h)&&(!p||s<=p)&&(a?(l(s),o(s),d(s)):(t("months"),d(s)))};return n.jsx("div",{className:"sa-calendar-years-preview",children:i.map((s,k)=>n.jsx("p",{className:s.active?"sa-calendar-months-active":"",style:{color:s.isDisabled?"#ccc":void 0,pointerEvents:s.isDisabled?"none":void 0,cursor:s.isDisabled?"not-allowed":"pointer",...e?{}:{width:"100%"}},onClick:()=>{s.isDisabled||f(new Date(s.year,0))},children:s.year},k))})},gn=({setViews:r,views:a,filter:t,previewDate:o,setPreviewDate:l})=>{const c=()=>{t||r(e=>e==="days"?"months":e==="months"?"years":"days")},d=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()+10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()+1,e.getMonth()));return}l(e=>new Date(e.getFullYear(),e.getMonth()+1))},h=()=>{if(a==="years"){l(e=>new Date(e.getFullYear()-10,0));return}if(a==="months"){l(e=>new Date(e.getFullYear()-1,e.getMonth()));return}l(e=>new Date(e.getMonth()===0?e.getFullYear()-1:e.getFullYear(),e.getMonth()===0?11:e.getMonth()-1))},p=()=>{if(a==="days")return`${A[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${q(o.getFullYear()).start} ~ ${q(o.getFullYear()).end}`};return n.jsxs("div",{className:"sa-calendar-header",children:[n.jsx("div",{className:"sa-calendar-header-title",onClick:c,children:p()}),n.jsxs("div",{className:"sa-calendar-header-nav",children:[n.jsx("button",{className:"sa-calendar-nav-btn",onClick:h,children:n.jsx(X,{})}),n.jsx("button",{className:"sa-calendar-nav-btn",onClick:d,children:n.jsx(_,{})})]})]})},an="sa-calendar-styles";(r=>{if(!document.getElementById(an)){const a=document.createElement("style");a.id=an,a.textContent=r,document.head.appendChild(a)}})(P);const bn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,disabled:l,minDate:c,maxDate:d,placeholder:h,size:p,variant:e,status:i,clearable:y,fullWidth:D=!0,withPadding:N=!0,label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m},Y)=>{const g=m?"error":i,{ref:b,isComponentVisible:L,setIsComponentVisible:T}=K(!1),M=x.useRef(null),[E,I]=x.useState("days"),[S,z]=x.useState(new Date),[C,F]=x.useState(new Date);x.useEffect(()=>{r?(z(r),F(r)):(z(new Date),F(new Date))},[r]),x.useEffect(()=>{t&&I(t)},[t]),x.useEffect(()=>{t||I("days")},[L]),x.useEffect(()=>{o||T(!0)},[o]);const G=()=>r?t==="days"?W(S):t==="months"?`${A[S.getMonth()]} ${S.getFullYear()}`:t==="years"?S.getFullYear():W(S):"",B=()=>{if(M.current&&b.current&&o){const w=b.current.getBoundingClientRect(),j=M.current.getBoundingClientRect();window.innerWidth<w.left+j.width?M.current.style.left=`${w.left-j.width+w.width}px`:M.current.style.left=`${w.left}px`,w.top+j.height>window.innerHeight?M.current.style.top=`${w.y-(w.height+j.height-28)}px`:M.current.style.top=`${w.y+w.height}px`}};x.useEffect(()=>{M.current&&b.current&&o&&B()},[M,b,L]),x.useEffect(()=>{const w=Y==null?void 0:Y.current;return w&&w.addEventListener("scroll",B),window.addEventListener("scroll",B),()=>{w&&w.removeEventListener("scroll",B),window.removeEventListener("scroll",B)}},[]);const U=n.jsxs("div",{className:"sa-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(pn,{value:G(),onClick:()=>T(!0),onChange:()=>{},placeholder:h,disabled:l,size:p,variant:e,status:g,inputMode:"none",clearable:y,onClear:()=>a(void 0)}):null,L?n.jsxs("div",{className:`sa-calendar sa-calendar-size-${p||"md"} ${o?"":"sa-calendar-no-input"} ${N?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,ref:M,children:[n.jsx(gn,{setViews:I,views:E,filter:t,previewDate:C,setPreviewDate:F,isComponentVisible:L}),n.jsx("div",{className:"sa-calendar-body",children:E==="days"?n.jsx(hn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,setIsComponentVisible:T,input:o,minDate:c,maxDate:d,onChange:a}):E==="months"?n.jsx(fn,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o}):n.jsx(un,{date:S,setDate:z,previewDate:C,setPreviewDate:F,filter:t,setViews:I,onChange:a,minDate:c,maxDate:d,input:o})})]}):null]});return n.jsx(R,{label:v,labelPosition:f,required:s,optional:k,description:$,helperText:u,errorText:m,fullWidth:D,children:U})}),vn=x.forwardRef(({value:r,onChange:a,filter:t,input:o=!0,rangedDate:l,disabled:c,minDate:d,maxDate:h,placeholder:p,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y},g)=>{const b={onChange:a,value:r,input:o,filter:t,disabled:c,minDate:d,maxDate:h,placeholder:p,size:e,variant:i,status:y,clearable:D,fullWidth:N,withPadding:v,label:f,labelPosition:s,required:k,optional:$,description:u,helperText:m,errorText:Y};return n.jsx(n.Fragment,{children:l?n.jsx(cn,{...b,ref:g}):n.jsx(bn,{...b,ref:g})})});V.StarasiaDate=vn,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
|