@starasia/dropdown 5.5.0 → 5.5.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/dropdown.es.js +101 -94
- package/dist/dropdown.umd.js +11 -5
- package/package.json +1 -1
package/dist/dropdown.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as l, jsx as n, Fragment as
|
|
2
|
-
import ln, { useState as
|
|
1
|
+
import { jsxs as l, jsx as n, Fragment as dn } from "react/jsx-runtime";
|
|
2
|
+
import ln, { useState as W, useRef as M, useEffect as v, forwardRef as yn } from "react";
|
|
3
3
|
const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
* {
|
|
5
5
|
margin: 0;
|
|
@@ -461,17 +461,19 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
461
461
|
.sa-select-field-label-row {
|
|
462
462
|
display: flex;
|
|
463
463
|
align-items: center;
|
|
464
|
-
gap:
|
|
464
|
+
gap: 4px;
|
|
465
465
|
flex-wrap: wrap;
|
|
466
466
|
}
|
|
467
467
|
.sa-select-field-label-text {
|
|
468
468
|
font-size: 14px;
|
|
469
469
|
font-weight: 500;
|
|
470
470
|
color: var(--sa-dropdown-text-primary);
|
|
471
|
-
line-height:
|
|
471
|
+
line-height: normal;
|
|
472
472
|
}
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
/* match Input: xs/sm label drops to 12px */
|
|
474
|
+
.sa-select-field-size-xs .sa-select-field-label-text,
|
|
475
|
+
.sa-select-field-size-sm .sa-select-field-label-text {
|
|
476
|
+
font-size: 12px;
|
|
475
477
|
}
|
|
476
478
|
.sa-select-field-required {
|
|
477
479
|
font-size: 14px;
|
|
@@ -479,6 +481,10 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
479
481
|
color: var(--sa-dropdown-text-error);
|
|
480
482
|
line-height: 1;
|
|
481
483
|
}
|
|
484
|
+
.sa-select-field-size-xs .sa-select-field-required,
|
|
485
|
+
.sa-select-field-size-sm .sa-select-field-required {
|
|
486
|
+
font-size: 12px;
|
|
487
|
+
}
|
|
482
488
|
.sa-select-field-optional-badge {
|
|
483
489
|
display: inline-flex;
|
|
484
490
|
align-items: center;
|
|
@@ -546,12 +552,12 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
546
552
|
|
|
547
553
|
`;
|
|
548
554
|
function En(o) {
|
|
549
|
-
const [p,
|
|
550
|
-
|
|
555
|
+
const [p, s] = W(o), d = M(null), a = (r) => {
|
|
556
|
+
d.current && !d.current.contains(r.target) && s(!1);
|
|
551
557
|
};
|
|
552
|
-
return v(() => (document.addEventListener("click",
|
|
553
|
-
document.removeEventListener("click",
|
|
554
|
-
}), []), { ref:
|
|
558
|
+
return v(() => (document.addEventListener("click", a, !0), () => {
|
|
559
|
+
document.removeEventListener("click", a, !0);
|
|
560
|
+
}), []), { ref: d, isComponentVisible: p, setIsComponentVisible: s };
|
|
555
561
|
}
|
|
556
562
|
const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
557
563
|
"svg",
|
|
@@ -608,9 +614,9 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
608
614
|
({
|
|
609
615
|
positionDropdown: o,
|
|
610
616
|
dropdownLists: p,
|
|
611
|
-
isComponentVisible:
|
|
612
|
-
searchAble:
|
|
613
|
-
hideSearch:
|
|
617
|
+
isComponentVisible: s,
|
|
618
|
+
searchAble: d,
|
|
619
|
+
hideSearch: a,
|
|
614
620
|
onSearch: r,
|
|
615
621
|
value: m,
|
|
616
622
|
handleChangeValue: u,
|
|
@@ -626,7 +632,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
626
632
|
var t;
|
|
627
633
|
y >= 0 && j.current[y] && ((t = j.current[y]) == null || t.scrollIntoView({ block: "nearest" }));
|
|
628
634
|
}, [y]);
|
|
629
|
-
const
|
|
635
|
+
const $ = d && !a ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
630
636
|
/* @__PURE__ */ n(Cn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
631
637
|
/* @__PURE__ */ n(
|
|
632
638
|
"input",
|
|
@@ -640,14 +646,14 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
640
646
|
}
|
|
641
647
|
)
|
|
642
648
|
] }) : null;
|
|
643
|
-
return /* @__PURE__ */ n(
|
|
649
|
+
return /* @__PURE__ */ n(dn, { children: s ? /* @__PURE__ */ l(
|
|
644
650
|
"div",
|
|
645
651
|
{
|
|
646
652
|
className: "sa-input-dropdown-lists-container",
|
|
647
653
|
onClick: (t) => t.stopPropagation(),
|
|
648
654
|
ref: U,
|
|
649
655
|
children: [
|
|
650
|
-
o !== "top" &&
|
|
656
|
+
o !== "top" && $,
|
|
651
657
|
/* @__PURE__ */ l(
|
|
652
658
|
"div",
|
|
653
659
|
{
|
|
@@ -667,14 +673,14 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
667
673
|
)
|
|
668
674
|
] }),
|
|
669
675
|
p.map((t, A) => {
|
|
670
|
-
const
|
|
676
|
+
const H = !!(m != null && m.find((P) => P.value === t.value)), w = !!t.description;
|
|
671
677
|
return /* @__PURE__ */ l(
|
|
672
678
|
"div",
|
|
673
679
|
{
|
|
674
680
|
className: [
|
|
675
681
|
"sa-input-dropdown-item",
|
|
676
682
|
w ? "has-description" : "",
|
|
677
|
-
|
|
683
|
+
H ? "active" : "",
|
|
678
684
|
A === y ? "highlight" : "",
|
|
679
685
|
t.disable ? "sa-input-dropdown-item-disable" : ""
|
|
680
686
|
].filter(Boolean).join(" "),
|
|
@@ -683,7 +689,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
683
689
|
},
|
|
684
690
|
onClick: () => u(t.label, t.value),
|
|
685
691
|
children: [
|
|
686
|
-
R && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children:
|
|
692
|
+
R && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: H && /* @__PURE__ */ n(zn, { width: 16 }) }),
|
|
687
693
|
t.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: ln.cloneElement(t.icon, { width: 16 }) }),
|
|
688
694
|
/* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
|
|
689
695
|
/* @__PURE__ */ n(
|
|
@@ -715,7 +721,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
715
721
|
]
|
|
716
722
|
}
|
|
717
723
|
),
|
|
718
|
-
o === "top" &&
|
|
724
|
+
o === "top" && $,
|
|
719
725
|
F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (t) => t.stopPropagation(), children: F })
|
|
720
726
|
]
|
|
721
727
|
}
|
|
@@ -725,39 +731,39 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
725
731
|
children: o,
|
|
726
732
|
handleChangePosition: p
|
|
727
733
|
}) => {
|
|
728
|
-
const
|
|
734
|
+
const s = M(null);
|
|
729
735
|
v(() => {
|
|
730
736
|
var m;
|
|
731
|
-
const
|
|
732
|
-
if (
|
|
733
|
-
let u =
|
|
734
|
-
for (; u && !
|
|
737
|
+
const a = () => {
|
|
738
|
+
if (s.current) {
|
|
739
|
+
let u = s.current.parentElement;
|
|
740
|
+
for (; u && !d(u); )
|
|
735
741
|
u = u.parentElement;
|
|
736
742
|
u && p();
|
|
737
743
|
}
|
|
738
744
|
};
|
|
739
|
-
let r = (m =
|
|
740
|
-
for (; r && !
|
|
745
|
+
let r = (m = s.current) == null ? void 0 : m.parentElement;
|
|
746
|
+
for (; r && !d(r); )
|
|
741
747
|
r = r.parentElement;
|
|
742
|
-
return r && r.addEventListener("scroll",
|
|
743
|
-
r && r.removeEventListener("scroll",
|
|
748
|
+
return r && r.addEventListener("scroll", a), a(), () => {
|
|
749
|
+
r && r.removeEventListener("scroll", a);
|
|
744
750
|
};
|
|
745
751
|
}, []);
|
|
746
|
-
const
|
|
747
|
-
return /* @__PURE__ */ n("div", { ref:
|
|
752
|
+
const d = (a) => a && (a.scrollHeight > a.clientHeight || a.scrollWidth > a.clientWidth);
|
|
753
|
+
return /* @__PURE__ */ n("div", { ref: s, children: o });
|
|
748
754
|
}, an = "sa-input-dropdown-styles", Bn = (o) => {
|
|
749
|
-
if (!document.getElementById(an)) {
|
|
755
|
+
if (!(typeof document > "u") && !document.getElementById(an)) {
|
|
750
756
|
const p = document.createElement("style");
|
|
751
757
|
p.id = an, p.textContent = o, document.head.appendChild(p);
|
|
752
758
|
}
|
|
753
759
|
};
|
|
754
760
|
Bn(Nn);
|
|
755
|
-
const
|
|
761
|
+
const In = ({
|
|
756
762
|
dropdownLists: o,
|
|
757
763
|
onChange: p,
|
|
758
|
-
defaultValue:
|
|
759
|
-
value:
|
|
760
|
-
size:
|
|
764
|
+
defaultValue: s,
|
|
765
|
+
value: d,
|
|
766
|
+
size: a = "sm",
|
|
761
767
|
multiSelect: r,
|
|
762
768
|
searchAble: m,
|
|
763
769
|
iconLeft: u,
|
|
@@ -769,10 +775,10 @@ const On = ({
|
|
|
769
775
|
disable: N,
|
|
770
776
|
searchValue: U,
|
|
771
777
|
variant: j = "outline",
|
|
772
|
-
footer:
|
|
778
|
+
footer: $,
|
|
773
779
|
groupLabel: t,
|
|
774
780
|
onSelectAll: A,
|
|
775
|
-
fullWidth:
|
|
781
|
+
fullWidth: H = !0,
|
|
776
782
|
triggerInput: w = !1,
|
|
777
783
|
clearOnSelect: P = !1,
|
|
778
784
|
hideChevronIcon: pn = !1,
|
|
@@ -789,54 +795,55 @@ const On = ({
|
|
|
789
795
|
}) => {
|
|
790
796
|
const Z = [
|
|
791
797
|
"sa-select-field",
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
798
|
+
`sa-select-field-size-${a}`,
|
|
799
|
+
H ? "sa-select-field-fullwidth" : ""
|
|
800
|
+
].filter(Boolean).join(" "), E = d !== void 0, Q = M(), un = y || !!h, [c, S] = W(
|
|
801
|
+
E ? d || [] : s || []
|
|
802
|
+
), [hn, en] = W(""), [k, X] = W(-1), [fn, q] = W(
|
|
796
803
|
() => {
|
|
797
|
-
var e,
|
|
798
|
-
return !r && (
|
|
804
|
+
var e, i;
|
|
805
|
+
return !r && (d != null && d.length || s != null && s.length) ? ((e = d == null ? void 0 : d[0]) == null ? void 0 : e.label) ?? ((i = s == null ? void 0 : s[0]) == null ? void 0 : i.label) ?? "" : "";
|
|
799
806
|
}
|
|
800
|
-
), g = M(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1),
|
|
807
|
+
), g = M(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), I = o !== void 0, on = c.length > 0, bn = (e) => {
|
|
801
808
|
e.stopPropagation();
|
|
802
|
-
const
|
|
803
|
-
E || S(
|
|
809
|
+
const i = [];
|
|
810
|
+
E || S(i), p(i), w && q(""), K == null || K();
|
|
804
811
|
}, gn = () => {
|
|
805
|
-
|
|
806
|
-
}, G = (e,
|
|
812
|
+
I && C((e) => !e);
|
|
813
|
+
}, G = (e, i) => {
|
|
807
814
|
if (r) {
|
|
808
|
-
if (c == null ? void 0 : c.find((x) => x.value ===
|
|
809
|
-
const x = c.filter((kn) => kn.value !==
|
|
815
|
+
if (c == null ? void 0 : c.find((x) => x.value === i)) {
|
|
816
|
+
const x = c.filter((kn) => kn.value !== i);
|
|
810
817
|
E || S(x), p(x);
|
|
811
818
|
} else {
|
|
812
|
-
const x = [...c, { label: e, value:
|
|
819
|
+
const x = [...c, { label: e, value: i }];
|
|
813
820
|
E || S(x), p(x);
|
|
814
821
|
}
|
|
815
822
|
w && q("");
|
|
816
823
|
} else {
|
|
817
|
-
const b = [{ label: e, value:
|
|
824
|
+
const b = [{ label: e, value: i }];
|
|
818
825
|
E || S(b), p(b), w && q(P ? "" : e), C(!1);
|
|
819
826
|
}
|
|
820
827
|
};
|
|
821
828
|
v(() => {
|
|
822
|
-
E && S(
|
|
823
|
-
}, [
|
|
824
|
-
E || JSON.stringify(Q.current) === JSON.stringify(
|
|
825
|
-
}, [
|
|
826
|
-
const xn = () => c.length ? r ? c == null ? void 0 : c.map((e,
|
|
829
|
+
E && S(d || []);
|
|
830
|
+
}, [d]), v(() => {
|
|
831
|
+
E || JSON.stringify(Q.current) === JSON.stringify(s) || (Q.current = s, S(Q.current || []));
|
|
832
|
+
}, [s]);
|
|
833
|
+
const xn = () => c.length ? r ? c == null ? void 0 : c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
827
834
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
828
835
|
/* @__PURE__ */ n(
|
|
829
|
-
|
|
836
|
+
sn,
|
|
830
837
|
{
|
|
831
838
|
onClick: (b) => {
|
|
832
839
|
b.stopPropagation(), G(e.label, e.value);
|
|
833
840
|
}
|
|
834
841
|
}
|
|
835
842
|
)
|
|
836
|
-
] },
|
|
843
|
+
] }, i)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: R }), z = () => {
|
|
837
844
|
if (Y.current && g.current) {
|
|
838
|
-
const e = window.innerHeight,
|
|
839
|
-
g.current.style.left = `${
|
|
845
|
+
const e = window.innerHeight, i = Y.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), x = i.bottom + b.height;
|
|
846
|
+
g.current.style.left = `${i.left}px`, g.current.style.width = `${i.width}px`, x >= e - 10 ? (g.current.style.top = `${i.top - b.height - 5}px`, en("top")) : (g.current.style.top = `${i.top + i.height + 4}px`, en("bottom"));
|
|
840
847
|
}
|
|
841
848
|
};
|
|
842
849
|
v(() => (window.addEventListener("scroll", z), window.addEventListener("resize", z), () => {
|
|
@@ -854,7 +861,7 @@ const On = ({
|
|
|
854
861
|
f || X(-1);
|
|
855
862
|
}, [f]);
|
|
856
863
|
const rn = (e) => {
|
|
857
|
-
if (
|
|
864
|
+
if (I) {
|
|
858
865
|
if (!f) {
|
|
859
866
|
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
|
|
860
867
|
return;
|
|
@@ -862,14 +869,14 @@ const On = ({
|
|
|
862
869
|
switch (e.key) {
|
|
863
870
|
case "ArrowDown": {
|
|
864
871
|
e.preventDefault();
|
|
865
|
-
const
|
|
866
|
-
|
|
872
|
+
const i = tn(o, k, 1);
|
|
873
|
+
i !== -1 && X(i);
|
|
867
874
|
break;
|
|
868
875
|
}
|
|
869
876
|
case "ArrowUp": {
|
|
870
877
|
e.preventDefault();
|
|
871
|
-
const
|
|
872
|
-
|
|
878
|
+
const i = tn(o, k, -1);
|
|
879
|
+
i !== -1 && X(i);
|
|
873
880
|
break;
|
|
874
881
|
}
|
|
875
882
|
case "Enter": {
|
|
@@ -884,7 +891,7 @@ const On = ({
|
|
|
884
891
|
break;
|
|
885
892
|
}
|
|
886
893
|
}
|
|
887
|
-
},
|
|
894
|
+
}, O = a === "lg" || a === "xl" ? 20 : a === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
|
|
888
895
|
"button",
|
|
889
896
|
{
|
|
890
897
|
type: "button",
|
|
@@ -894,31 +901,31 @@ const On = ({
|
|
|
894
901
|
tabIndex: -1,
|
|
895
902
|
onClick: bn,
|
|
896
903
|
onMouseDown: (e) => e.preventDefault(),
|
|
897
|
-
children: /* @__PURE__ */ n(Dn, { width:
|
|
904
|
+
children: /* @__PURE__ */ n(Dn, { width: O, height: O })
|
|
898
905
|
}
|
|
899
|
-
) : null, mn = w ? /* @__PURE__ */ l(
|
|
900
|
-
r && c.map((e,
|
|
906
|
+
) : null, mn = w ? /* @__PURE__ */ l(dn, { children: [
|
|
907
|
+
r && c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
901
908
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
902
909
|
/* @__PURE__ */ n(
|
|
903
|
-
|
|
910
|
+
sn,
|
|
904
911
|
{
|
|
905
912
|
onClick: (b) => {
|
|
906
913
|
b.stopPropagation(), G(e.label, e.value);
|
|
907
914
|
}
|
|
908
915
|
}
|
|
909
916
|
)
|
|
910
|
-
] },
|
|
917
|
+
] }, i)),
|
|
911
918
|
/* @__PURE__ */ n(
|
|
912
919
|
"input",
|
|
913
920
|
{
|
|
914
921
|
className: "sa-input-dropdown-trigger-input",
|
|
915
922
|
value: fn,
|
|
916
923
|
onChange: (e) => {
|
|
917
|
-
const
|
|
918
|
-
q(
|
|
924
|
+
const i = e.target.value;
|
|
925
|
+
q(i), L == null || L(i), !f && I && C(!0);
|
|
919
926
|
},
|
|
920
927
|
onFocus: () => {
|
|
921
|
-
!N &&
|
|
928
|
+
!N && I && C(!0);
|
|
922
929
|
},
|
|
923
930
|
onBlur: () => {
|
|
924
931
|
r || setTimeout(() => C(!1), 150);
|
|
@@ -934,7 +941,7 @@ const On = ({
|
|
|
934
941
|
className: [
|
|
935
942
|
"sa-input-dropdown-container",
|
|
936
943
|
j,
|
|
937
|
-
`sa-input-dropdown-size-${
|
|
944
|
+
`sa-input-dropdown-size-${a}`,
|
|
938
945
|
w ? "trigger-input" : "",
|
|
939
946
|
f ? "active" : "",
|
|
940
947
|
un ? "error" : "",
|
|
@@ -949,14 +956,14 @@ const On = ({
|
|
|
949
956
|
children: [
|
|
950
957
|
/* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
951
958
|
u ? ln.cloneElement(u, {
|
|
952
|
-
width:
|
|
959
|
+
width: O,
|
|
953
960
|
style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
|
|
954
961
|
}) : null,
|
|
955
962
|
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : xn() }),
|
|
956
963
|
vn,
|
|
957
|
-
!pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(jn, { width:
|
|
964
|
+
!pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(jn, { width: O }) : /* @__PURE__ */ n(Sn, { width: O }) })
|
|
958
965
|
] }),
|
|
959
|
-
|
|
966
|
+
I && /* @__PURE__ */ n(
|
|
960
967
|
Rn,
|
|
961
968
|
{
|
|
962
969
|
dropdownLists: o,
|
|
@@ -971,7 +978,7 @@ const On = ({
|
|
|
971
978
|
multiSelect: r,
|
|
972
979
|
searchValue: U,
|
|
973
980
|
highlightedIndex: k,
|
|
974
|
-
footer:
|
|
981
|
+
footer: $,
|
|
975
982
|
groupLabel: t,
|
|
976
983
|
onSelectAll: A
|
|
977
984
|
}
|
|
@@ -1009,27 +1016,27 @@ const On = ({
|
|
|
1009
1016
|
D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
|
|
1010
1017
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1011
1018
|
] });
|
|
1012
|
-
}, tn = (o, p,
|
|
1013
|
-
const
|
|
1014
|
-
let
|
|
1015
|
-
for (;
|
|
1016
|
-
if (!o[
|
|
1017
|
-
return
|
|
1018
|
-
|
|
1019
|
+
}, tn = (o, p, s) => {
|
|
1020
|
+
const d = o.length;
|
|
1021
|
+
let a = p + s;
|
|
1022
|
+
for (; a >= 0 && a < d; ) {
|
|
1023
|
+
if (!o[a].disable)
|
|
1024
|
+
return a;
|
|
1025
|
+
a += s;
|
|
1019
1026
|
}
|
|
1020
|
-
if (
|
|
1021
|
-
for (let r = 0; r <
|
|
1027
|
+
if (s === 1) {
|
|
1028
|
+
for (let r = 0; r < d; r++)
|
|
1022
1029
|
if (!o[r].disable)
|
|
1023
1030
|
return r;
|
|
1024
1031
|
} else
|
|
1025
|
-
for (let r =
|
|
1032
|
+
for (let r = d - 1; r >= 0; r--)
|
|
1026
1033
|
if (!o[r].disable)
|
|
1027
1034
|
return r;
|
|
1028
1035
|
return -1;
|
|
1029
1036
|
}, Dn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
|
|
1030
1037
|
/* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
1031
1038
|
/* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1032
|
-
] }),
|
|
1039
|
+
] }), sn = (o) => /* @__PURE__ */ n(
|
|
1033
1040
|
"svg",
|
|
1034
1041
|
{
|
|
1035
1042
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1092,5 +1099,5 @@ const On = ({
|
|
|
1092
1099
|
}
|
|
1093
1100
|
);
|
|
1094
1101
|
export {
|
|
1095
|
-
|
|
1102
|
+
In as Dropdown
|
|
1096
1103
|
};
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -459,17 +459,19 @@
|
|
|
459
459
|
.sa-select-field-label-row {
|
|
460
460
|
display: flex;
|
|
461
461
|
align-items: center;
|
|
462
|
-
gap:
|
|
462
|
+
gap: 4px;
|
|
463
463
|
flex-wrap: wrap;
|
|
464
464
|
}
|
|
465
465
|
.sa-select-field-label-text {
|
|
466
466
|
font-size: 14px;
|
|
467
467
|
font-weight: 500;
|
|
468
468
|
color: var(--sa-dropdown-text-primary);
|
|
469
|
-
line-height:
|
|
469
|
+
line-height: normal;
|
|
470
470
|
}
|
|
471
|
-
|
|
472
|
-
|
|
471
|
+
/* match Input: xs/sm label drops to 12px */
|
|
472
|
+
.sa-select-field-size-xs .sa-select-field-label-text,
|
|
473
|
+
.sa-select-field-size-sm .sa-select-field-label-text {
|
|
474
|
+
font-size: 12px;
|
|
473
475
|
}
|
|
474
476
|
.sa-select-field-required {
|
|
475
477
|
font-size: 14px;
|
|
@@ -477,6 +479,10 @@
|
|
|
477
479
|
color: var(--sa-dropdown-text-error);
|
|
478
480
|
line-height: 1;
|
|
479
481
|
}
|
|
482
|
+
.sa-select-field-size-xs .sa-select-field-required,
|
|
483
|
+
.sa-select-field-size-sm .sa-select-field-required {
|
|
484
|
+
font-size: 12px;
|
|
485
|
+
}
|
|
480
486
|
.sa-select-field-optional-badge {
|
|
481
487
|
display: inline-flex;
|
|
482
488
|
align-items: center;
|
|
@@ -542,4 +548,4 @@
|
|
|
542
548
|
display: none;
|
|
543
549
|
}
|
|
544
550
|
|
|
545
|
-
`;function dn(o){const[p,d]=l.useState(o),t=l.useRef(null),s=r=>{t.current&&!t.current.contains(r.target)&&d(!1)};return l.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:d}}const tn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),ln=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),pn=l.forwardRef(({positionDropdown:o,dropdownLists:p,isComponentVisible:d,searchAble:t,hideSearch:s,onSearch:r,value:k,handleChangeValue:h,multiSelect:L,searchValue:B,highlightedIndex:y,footer:I,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var i;y>=0&&P.current[y]&&((i=P.current[y])==null||i.scrollIntoView({block:"nearest"}))},[y]);const T=t&&!s?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(tn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:i=>{r&&r(i.target.value)},value:B,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:i=>i.stopPropagation(),ref:G,children:[o!=="top"&&T,n.jsxs("div",{className:`sa-input-dropdown-item-container ${L?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),L&&N&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:i=>{i.stopPropagation(),N()},children:"Select all"})]}),p.map((i,A)=>{const H=!!(k!=null&&k.find(O=>O.value===i.value)),w=!!i.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",H?"active":"",A===y?"highlight":"",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>h(i.label,i.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:H&&n.jsx(ln,{width:16})}),i.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(i.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.label}),i.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.description})]})]},A)})]}),o==="top"&&T,I&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:i=>i.stopPropagation(),children:I})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const d=l.useRef(null);l.useEffect(()=>{var k;const s=()=>{if(d.current){let h=d.current.parentElement;for(;h&&!t(h);)h=h.parentElement;h&&p()}};let r=(k=d.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",s),s(),()=>{r&&r.removeEventListener("scroll",s)}},[]);const t=s=>s&&(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);return n.jsx("div",{ref:d,children:o})},_="sa-input-dropdown-styles";(o=>{if(!document.getElementById(_)){const p=document.createElement("style");p.id=_,p.textContent=o,document.head.appendChild(p)}})(sn);const wn=({dropdownLists:o,onChange:p,defaultValue:d,value:t,size:s="sm",multiSelect:r,searchAble:k,iconLeft:h,placeholder:L,onSearch:B,error:y,onBlur:I,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:i,onSelectAll:A,fullWidth:H=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:S,helperText:D,errorText:f})=>{const J=["sa-select-field",H?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),vn=y||!!f,[c,j]=l.useState(E?t||[]:d||[]),[kn,on]=l.useState(""),[m,Q]=l.useState(-1),[mn,$]=l.useState(()=>{var e,a;return!r&&(t!=null&&t.length||d!=null&&d.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((a=d==null?void 0:d[0])==null?void 0:a.label)??"":""}),g=l.useRef(null),{isComponentVisible:u,ref:X,setIsComponentVisible:C}=dn(!1),M=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&$(""),U==null||U()},Nn=()=>{M&&C(e=>!e)},q=(e,a)=>{if(r){if(c==null?void 0:c.find(x=>x.value===a)){const x=c.filter(Ln=>Ln.value!==a);E||j(x),p(x)}else{const x=[...c,{label:e,value:a}];E||j(x),p(x)}w&&$("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&$(O?"":e),C(!1)}};l.useEffect(()=>{E&&j(t||[])},[t]),l.useEffect(()=>{E||JSON.stringify(Z.current)===JSON.stringify(d)||(Z.current=d,j(Z.current||[]))},[d]);const En=()=>c.length?r?c==null?void 0:c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(R,{onClick:b=>{b.stopPropagation(),q(e.label,e.value)}})]},a)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),x=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,x>=e-10?(g.current.style.top=`${a.top-b.height-5}px`,on("top")):(g.current.style.top=`${a.top+a.height+4}px`,on("bottom"))}};l.useEffect(()=>(window.addEventListener("scroll",z),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",z),window.removeEventListener("resize",z)}),[]),l.useEffect(()=>{z()},[u]),l.useEffect(()=>{if(!u||!g.current)return;const e=new ResizeObserver(()=>{z()});return e.observe(g.current),()=>e.disconnect()},[u]),l.useEffect(()=>{u||Q(-1)},[u]);const an=e=>{if(M){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,m,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,m,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&q(o[m].label,o[m].value);break}case"Escape":C(!1);break}}},W=s==="lg"||s==="xl"?20:s==="xs"?14:16,Cn=gn&&!N?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${rn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!rn,tabIndex:-1,onClick:yn,onMouseDown:e=>e.preventDefault(),children:n.jsx(hn,{width:W,height:W})}):null,zn=w?n.jsxs(n.Fragment,{children:[r&&c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(R,{onClick:b=>{b.stopPropagation(),q(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const a=e.target.value;$(a),B==null||B(a),!u&&M&&C(!0)},onFocus:()=>{!N&&M&&C(!0)},onBlur:()=>{r||setTimeout(()=>C(!1),150)},onKeyDown:an,placeholder:c.length===0||r?L:void 0,disabled:N})]}):null,Y=n.jsx(cn,{handleChangePosition:z,children:n.jsxs("div",{className:["sa-input-dropdown-container",P,`sa-input-dropdown-size-${s}`,w?"trigger-input":"",u?"active":"",vn?"error":"",N?"disable":""].filter(Boolean).join(" "),ref:X,onClick:w?void 0:Nn,onKeyDown:w?void 0:an,tabIndex:w?void 0:0,onBlur:w?void 0:I,onFocus:w?void 0:F,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[h?l.cloneElement(h,{width:W,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?zn:En()}),Cn,!bn&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(un,{width:W}):n.jsx(fn,{width:W})})]}),M&&n.jsx(pn,{dropdownLists:o,handleChangeValue:q,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:m,footer:T,groupLabel:i,onSelectAll:A})]})});return K?xn==="outside-left"?n.jsxs("div",{className:`${J} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:J,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:J,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},V=(o,p,d)=>{const t=o.length;let s=p+d;for(;s>=0&&s<t;){if(!o[s].disable)return s;s+=d}if(d===1){for(let r=0;r<t;r++)if(!o[r].disable)return r}else for(let r=t-1;r>=0;r--)if(!o[r].disable)return r;return-1},hn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),fn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),un=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});v.Dropdown=wn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
551
|
+
`;function dn(o){const[p,d]=l.useState(o),t=l.useRef(null),s=r=>{t.current&&!t.current.contains(r.target)&&d(!1)};return l.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:d}}const tn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),ln=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),pn=l.forwardRef(({positionDropdown:o,dropdownLists:p,isComponentVisible:d,searchAble:t,hideSearch:s,onSearch:r,value:k,handleChangeValue:f,multiSelect:L,searchValue:B,highlightedIndex:y,footer:W,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var i;y>=0&&P.current[y]&&((i=P.current[y])==null||i.scrollIntoView({block:"nearest"}))},[y]);const T=t&&!s?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(tn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:i=>{r&&r(i.target.value)},value:B,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:i=>i.stopPropagation(),ref:G,children:[o!=="top"&&T,n.jsxs("div",{className:`sa-input-dropdown-item-container ${L?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),L&&N&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:i=>{i.stopPropagation(),N()},children:"Select all"})]}),p.map((i,A)=>{const $=!!(k!=null&&k.find(O=>O.value===i.value)),w=!!i.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",$?"active":"",A===y?"highlight":"",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>f(i.label,i.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:$&&n.jsx(ln,{width:16})}),i.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(i.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.label}),i.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.description})]})]},A)})]}),o==="top"&&T,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:i=>i.stopPropagation(),children:W})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const d=l.useRef(null);l.useEffect(()=>{var k;const s=()=>{if(d.current){let f=d.current.parentElement;for(;f&&!t(f);)f=f.parentElement;f&&p()}};let r=(k=d.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",s),s(),()=>{r&&r.removeEventListener("scroll",s)}},[]);const t=s=>s&&(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);return n.jsx("div",{ref:d,children:o})},_="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(_)){const p=document.createElement("style");p.id=_,p.textContent=o,document.head.appendChild(p)}})(sn);const wn=({dropdownLists:o,onChange:p,defaultValue:d,value:t,size:s="sm",multiSelect:r,searchAble:k,iconLeft:f,placeholder:L,onSearch:B,error:y,onBlur:W,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:i,onSelectAll:A,fullWidth:$=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:S,helperText:D,errorText:h})=>{const J=["sa-select-field",`sa-select-field-size-${s}`,$?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),vn=y||!!h,[c,j]=l.useState(E?t||[]:d||[]),[kn,on]=l.useState(""),[m,Q]=l.useState(-1),[mn,q]=l.useState(()=>{var e,a;return!r&&(t!=null&&t.length||d!=null&&d.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((a=d==null?void 0:d[0])==null?void 0:a.label)??"":""}),g=l.useRef(null),{isComponentVisible:u,ref:X,setIsComponentVisible:C}=dn(!1),I=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&q(""),U==null||U()},Nn=()=>{I&&C(e=>!e)},H=(e,a)=>{if(r){if(c==null?void 0:c.find(x=>x.value===a)){const x=c.filter(Ln=>Ln.value!==a);E||j(x),p(x)}else{const x=[...c,{label:e,value:a}];E||j(x),p(x)}w&&q("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&q(O?"":e),C(!1)}};l.useEffect(()=>{E&&j(t||[])},[t]),l.useEffect(()=>{E||JSON.stringify(Z.current)===JSON.stringify(d)||(Z.current=d,j(Z.current||[]))},[d]);const En=()=>c.length?r?c==null?void 0:c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(R,{onClick:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),x=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,x>=e-10?(g.current.style.top=`${a.top-b.height-5}px`,on("top")):(g.current.style.top=`${a.top+a.height+4}px`,on("bottom"))}};l.useEffect(()=>(window.addEventListener("scroll",z),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",z),window.removeEventListener("resize",z)}),[]),l.useEffect(()=>{z()},[u]),l.useEffect(()=>{if(!u||!g.current)return;const e=new ResizeObserver(()=>{z()});return e.observe(g.current),()=>e.disconnect()},[u]),l.useEffect(()=>{u||Q(-1)},[u]);const an=e=>{if(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,m,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,m,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&H(o[m].label,o[m].value);break}case"Escape":C(!1);break}}},M=s==="lg"||s==="xl"?20:s==="xs"?14:16,Cn=gn&&!N?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${rn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!rn,tabIndex:-1,onClick:yn,onMouseDown:e=>e.preventDefault(),children:n.jsx(fn,{width:M,height:M})}):null,zn=w?n.jsxs(n.Fragment,{children:[r&&c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(R,{onClick:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const a=e.target.value;q(a),B==null||B(a),!u&&I&&C(!0)},onFocus:()=>{!N&&I&&C(!0)},onBlur:()=>{r||setTimeout(()=>C(!1),150)},onKeyDown:an,placeholder:c.length===0||r?L:void 0,disabled:N})]}):null,Y=n.jsx(cn,{handleChangePosition:z,children:n.jsxs("div",{className:["sa-input-dropdown-container",P,`sa-input-dropdown-size-${s}`,w?"trigger-input":"",u?"active":"",vn?"error":"",N?"disable":""].filter(Boolean).join(" "),ref:X,onClick:w?void 0:Nn,onKeyDown:w?void 0:an,tabIndex:w?void 0:0,onBlur:w?void 0:W,onFocus:w?void 0:F,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?l.cloneElement(f,{width:M,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?zn:En()}),Cn,!bn&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(un,{width:M}):n.jsx(hn,{width:M})})]}),I&&n.jsx(pn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:m,footer:T,groupLabel:i,onSelectAll:A})]})});return K?xn==="outside-left"?n.jsxs("div",{className:`${J} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):n.jsxs("div",{className:J,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:J,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},V=(o,p,d)=>{const t=o.length;let s=p+d;for(;s>=0&&s<t;){if(!o[s].disable)return s;s+=d}if(d===1){for(let r=0;r<t;r++)if(!o[r].disable)return r}else for(let r=t-1;r>=0;r--)if(!o[r].disable)return r;return-1},fn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),hn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),un=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});v.Dropdown=wn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|