@starasia/dropdown 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DropdownList.d.ts +1 -0
- package/dist/dropdown.es.js +255 -235
- package/dist/dropdown.umd.js +2 -2
- package/package.json +1 -1
package/dist/DropdownList.d.ts
CHANGED
package/dist/dropdown.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsxs as l, jsx as n, Fragment as tn } from "react/jsx-runtime";
|
|
2
|
+
import dn, { useState as A, useRef as K, useEffect as g, forwardRef as En } from "react";
|
|
3
|
+
const zn = `* {
|
|
4
4
|
margin: 0;
|
|
5
5
|
padding: 0;
|
|
6
6
|
font-family: var(--sa-font-family, "Inter", sans-serif);
|
|
@@ -578,15 +578,15 @@ const Cn = `* {
|
|
|
578
578
|
}
|
|
579
579
|
|
|
580
580
|
`;
|
|
581
|
-
function
|
|
582
|
-
const [t, i] =
|
|
583
|
-
|
|
581
|
+
function Rn(o) {
|
|
582
|
+
const [t, i] = A(o), p = K(null), c = (d) => {
|
|
583
|
+
p.current && !p.current.contains(d.target) && i(!1);
|
|
584
584
|
};
|
|
585
|
-
return
|
|
586
|
-
document.removeEventListener("click",
|
|
587
|
-
}), []), { ref:
|
|
585
|
+
return g(() => (document.addEventListener("click", c, !0), () => {
|
|
586
|
+
document.removeEventListener("click", c, !0);
|
|
587
|
+
}), []), { ref: p, isComponentVisible: t, setIsComponentVisible: i };
|
|
588
588
|
}
|
|
589
|
-
const
|
|
589
|
+
const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
590
590
|
"svg",
|
|
591
591
|
{
|
|
592
592
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -618,7 +618,7 @@ const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
618
618
|
)
|
|
619
619
|
]
|
|
620
620
|
}
|
|
621
|
-
),
|
|
621
|
+
), Dn = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
622
622
|
"svg",
|
|
623
623
|
{
|
|
624
624
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -637,44 +637,45 @@ const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
637
637
|
}
|
|
638
638
|
)
|
|
639
639
|
}
|
|
640
|
-
),
|
|
640
|
+
), Ln = En(
|
|
641
641
|
({
|
|
642
642
|
positionDropdown: o,
|
|
643
643
|
dropdownLists: t,
|
|
644
644
|
isComponentVisible: i,
|
|
645
|
-
searchAble:
|
|
646
|
-
hideSearch:
|
|
647
|
-
onSearch:
|
|
648
|
-
value:
|
|
649
|
-
handleChangeValue:
|
|
650
|
-
multiSelect:
|
|
651
|
-
searchValue:
|
|
652
|
-
highlightedIndex:
|
|
645
|
+
searchAble: p,
|
|
646
|
+
hideSearch: c,
|
|
647
|
+
onSearch: d,
|
|
648
|
+
value: M,
|
|
649
|
+
handleChangeValue: F,
|
|
650
|
+
multiSelect: y,
|
|
651
|
+
searchValue: k,
|
|
652
|
+
highlightedIndex: N,
|
|
653
|
+
listboxId: O,
|
|
653
654
|
footer: $,
|
|
654
|
-
groupLabel:
|
|
655
|
-
onSelectAll:
|
|
656
|
-
emptyState:
|
|
657
|
-
},
|
|
658
|
-
const
|
|
659
|
-
|
|
655
|
+
groupLabel: C,
|
|
656
|
+
onSelectAll: T,
|
|
657
|
+
emptyState: X
|
|
658
|
+
}, Y) => {
|
|
659
|
+
const S = K([]), q = k !== void 0, [Z, Q] = A(""), s = q ? k : Z, H = !t || t.length === 0;
|
|
660
|
+
g(() => {
|
|
660
661
|
var a;
|
|
661
|
-
|
|
662
|
-
}, [
|
|
663
|
-
const
|
|
664
|
-
/* @__PURE__ */ n(
|
|
662
|
+
N >= 0 && S.current[N] && ((a = S.current[N]) == null || a.scrollIntoView({ block: "nearest" }));
|
|
663
|
+
}, [N]);
|
|
664
|
+
const _ = p && !c ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
665
|
+
/* @__PURE__ */ n(Bn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
665
666
|
/* @__PURE__ */ n(
|
|
666
667
|
"input",
|
|
667
668
|
{
|
|
668
669
|
onChange: (a) => {
|
|
669
|
-
|
|
670
|
+
q || Q(a.target.value), d && d(a.target.value);
|
|
670
671
|
},
|
|
671
|
-
value:
|
|
672
|
+
value: s,
|
|
672
673
|
autoFocus: !0,
|
|
673
674
|
placeholder: "Search..."
|
|
674
675
|
}
|
|
675
676
|
)
|
|
676
677
|
] }) : null;
|
|
677
|
-
return /* @__PURE__ */ n(
|
|
678
|
+
return /* @__PURE__ */ n(tn, { children: i ? /* @__PURE__ */ l(
|
|
678
679
|
"div",
|
|
679
680
|
{
|
|
680
681
|
className: [
|
|
@@ -687,56 +688,63 @@ const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
687
688
|
o === "top" ? "search-bottom" : ""
|
|
688
689
|
].filter(Boolean).join(" "),
|
|
689
690
|
onClick: (a) => a.stopPropagation(),
|
|
690
|
-
ref:
|
|
691
|
+
ref: Y,
|
|
691
692
|
children: [
|
|
692
|
-
|
|
693
|
-
/* @__PURE__ */
|
|
693
|
+
_,
|
|
694
|
+
/* @__PURE__ */ l(
|
|
694
695
|
"div",
|
|
695
696
|
{
|
|
696
|
-
className: `sa-input-dropdown-item-container ${
|
|
697
|
+
className: `sa-input-dropdown-item-container ${y ? "multi" : ""}`,
|
|
698
|
+
role: "listbox",
|
|
699
|
+
id: O,
|
|
700
|
+
"aria-multiselectable": y || void 0,
|
|
697
701
|
children: [
|
|
698
|
-
|
|
702
|
+
H && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: X ?? (s ? /* @__PURE__ */ l(tn, { children: [
|
|
699
703
|
"No results for",
|
|
700
704
|
" ",
|
|
701
|
-
/* @__PURE__ */
|
|
705
|
+
/* @__PURE__ */ l("span", { className: "sa-input-dropdown-empty-query", children: [
|
|
702
706
|
"“",
|
|
703
|
-
|
|
707
|
+
s,
|
|
704
708
|
"”"
|
|
705
709
|
] })
|
|
706
710
|
] }) : "No data available") }),
|
|
707
|
-
|
|
708
|
-
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children:
|
|
709
|
-
|
|
711
|
+
C && !H && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
|
|
712
|
+
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: C }),
|
|
713
|
+
y && T && /* @__PURE__ */ n(
|
|
710
714
|
"button",
|
|
711
715
|
{
|
|
712
716
|
className: "sa-input-dropdown-section-select-all",
|
|
713
717
|
onClick: (a) => {
|
|
714
|
-
a.stopPropagation(),
|
|
718
|
+
a.stopPropagation(), T();
|
|
715
719
|
},
|
|
716
720
|
children: "Select all"
|
|
717
721
|
}
|
|
718
722
|
)
|
|
719
723
|
] }),
|
|
720
|
-
t == null ? void 0 : t.map((a,
|
|
721
|
-
const
|
|
722
|
-
return /* @__PURE__ */
|
|
724
|
+
t == null ? void 0 : t.map((a, m) => {
|
|
725
|
+
const E = !!(M != null && M.find((B) => B.value === a.value)), V = !!a.description;
|
|
726
|
+
return /* @__PURE__ */ l(
|
|
723
727
|
"div",
|
|
724
728
|
{
|
|
725
729
|
className: [
|
|
726
730
|
"sa-input-dropdown-item",
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
731
|
+
V ? "has-description" : "",
|
|
732
|
+
E ? "active" : "",
|
|
733
|
+
m === N ? "highlight" : "",
|
|
730
734
|
a.disable ? "sa-input-dropdown-item-disable" : ""
|
|
731
735
|
].filter(Boolean).join(" "),
|
|
732
|
-
|
|
733
|
-
|
|
736
|
+
id: O ? `${O}-opt-${m}` : void 0,
|
|
737
|
+
role: "option",
|
|
738
|
+
"aria-selected": E,
|
|
739
|
+
"aria-disabled": a.disable || void 0,
|
|
740
|
+
ref: (B) => {
|
|
741
|
+
S.current[m] = B;
|
|
734
742
|
},
|
|
735
|
-
onClick: () =>
|
|
743
|
+
onClick: () => F(a.label, a.value),
|
|
736
744
|
children: [
|
|
737
|
-
|
|
738
|
-
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children:
|
|
739
|
-
/* @__PURE__ */
|
|
745
|
+
y && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: E && /* @__PURE__ */ n(Dn, { width: 16 }) }),
|
|
746
|
+
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: dn.cloneElement(a.icon, { width: 16 }) }),
|
|
747
|
+
/* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
|
|
740
748
|
/* @__PURE__ */ n(
|
|
741
749
|
"p",
|
|
742
750
|
{
|
|
@@ -760,7 +768,7 @@ const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
760
768
|
] })
|
|
761
769
|
]
|
|
762
770
|
},
|
|
763
|
-
|
|
771
|
+
m
|
|
764
772
|
);
|
|
765
773
|
})
|
|
766
774
|
]
|
|
@@ -771,176 +779,176 @@ const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
771
779
|
}
|
|
772
780
|
) : null });
|
|
773
781
|
}
|
|
774
|
-
),
|
|
782
|
+
), jn = ({
|
|
775
783
|
children: o,
|
|
776
784
|
handleChangePosition: t,
|
|
777
785
|
enabled: i = !0
|
|
778
|
-
}) => (
|
|
786
|
+
}) => (g(() => {
|
|
779
787
|
if (i)
|
|
780
788
|
return window.addEventListener("scroll", t, !0), () => {
|
|
781
789
|
window.removeEventListener("scroll", t, !0);
|
|
782
790
|
};
|
|
783
|
-
}, [i, t]), /* @__PURE__ */ n("div", { children: o })),
|
|
784
|
-
if (!(typeof document > "u") && !document.getElementById(
|
|
791
|
+
}, [i, t]), /* @__PURE__ */ n("div", { children: o })), hn = "sa-input-dropdown-styles", An = (o) => {
|
|
792
|
+
if (!(typeof document > "u") && !document.getElementById(hn)) {
|
|
785
793
|
const t = document.createElement("style");
|
|
786
|
-
t.id =
|
|
794
|
+
t.id = hn, t.textContent = o, document.head.appendChild(t);
|
|
787
795
|
}
|
|
788
796
|
};
|
|
789
|
-
|
|
790
|
-
const
|
|
797
|
+
An(zn);
|
|
798
|
+
const Pn = ({
|
|
791
799
|
dropdownLists: o,
|
|
792
800
|
onChange: t,
|
|
793
801
|
defaultValue: i,
|
|
794
|
-
value:
|
|
795
|
-
size:
|
|
796
|
-
multiSelect:
|
|
797
|
-
searchAble:
|
|
798
|
-
iconLeft:
|
|
799
|
-
placeholder:
|
|
800
|
-
onSearch:
|
|
801
|
-
error:
|
|
802
|
-
onBlur:
|
|
803
|
-
onFocus:
|
|
804
|
-
disable:
|
|
805
|
-
searchValue:
|
|
802
|
+
value: p,
|
|
803
|
+
size: c = "sm",
|
|
804
|
+
multiSelect: d,
|
|
805
|
+
searchAble: M,
|
|
806
|
+
iconLeft: F,
|
|
807
|
+
placeholder: y,
|
|
808
|
+
onSearch: k,
|
|
809
|
+
error: N,
|
|
810
|
+
onBlur: O,
|
|
811
|
+
onFocus: $,
|
|
812
|
+
disable: C,
|
|
813
|
+
searchValue: T,
|
|
806
814
|
variant: X = "outline",
|
|
807
|
-
footer:
|
|
808
|
-
groupLabel:
|
|
809
|
-
onSelectAll:
|
|
815
|
+
footer: Y,
|
|
816
|
+
groupLabel: S,
|
|
817
|
+
onSelectAll: q,
|
|
810
818
|
emptyState: Z,
|
|
811
|
-
fullWidth:
|
|
812
|
-
triggerInput:
|
|
813
|
-
clearOnSelect:
|
|
814
|
-
hideChevronIcon:
|
|
815
|
-
clearable:
|
|
816
|
-
onClear:
|
|
819
|
+
fullWidth: Q = !0,
|
|
820
|
+
triggerInput: s = !1,
|
|
821
|
+
clearOnSelect: H = !1,
|
|
822
|
+
hideChevronIcon: _ = !1,
|
|
823
|
+
clearable: a = !1,
|
|
824
|
+
onClear: m,
|
|
817
825
|
/* field wrapper */
|
|
818
|
-
label:
|
|
819
|
-
labelPosition:
|
|
820
|
-
required:
|
|
821
|
-
optional:
|
|
822
|
-
description:
|
|
823
|
-
helperText:
|
|
826
|
+
label: E,
|
|
827
|
+
labelPosition: V = "outside-top",
|
|
828
|
+
required: B,
|
|
829
|
+
optional: sn,
|
|
830
|
+
description: D,
|
|
831
|
+
helperText: L,
|
|
824
832
|
errorText: h
|
|
825
833
|
}) => {
|
|
826
|
-
const
|
|
834
|
+
const nn = [
|
|
827
835
|
"sa-select-field",
|
|
828
|
-
`sa-select-field-size-${
|
|
829
|
-
|
|
830
|
-
].filter(Boolean).join(" "),
|
|
831
|
-
|
|
832
|
-
), [
|
|
836
|
+
`sa-select-field-size-${c}`,
|
|
837
|
+
Q ? "sa-select-field-fullwidth" : ""
|
|
838
|
+
].filter(Boolean).join(" "), z = p !== void 0, en = K(), vn = N || !!h, [u, j] = A(
|
|
839
|
+
z ? p || [] : i || []
|
|
840
|
+
), [xn, ln] = A(""), [f, on] = A(-1), G = dn.useId(), pn = f >= 0 ? `${G}-opt-${f}` : void 0, [cn, U] = A(
|
|
833
841
|
() => {
|
|
834
842
|
var e, r;
|
|
835
|
-
return !
|
|
843
|
+
return !d && (p != null && p.length || i != null && i.length) ? ((e = p == null ? void 0 : p[0]) == null ? void 0 : e.label) ?? ((r = i == null ? void 0 : i[0]) == null ? void 0 : r.label) ?? "" : "";
|
|
836
844
|
}
|
|
837
|
-
),
|
|
845
|
+
), v = K(null), { isComponentVisible: w, ref: rn, setIsComponentVisible: R } = Rn(!1), I = o !== void 0, un = u.length > 0, gn = (e) => {
|
|
838
846
|
e.stopPropagation();
|
|
839
847
|
const r = [];
|
|
840
|
-
|
|
841
|
-
},
|
|
842
|
-
|
|
843
|
-
},
|
|
844
|
-
if (
|
|
845
|
-
if (u == null ? void 0 : u.find((
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
+
z || j(r), t(r), s && U(""), m == null || m();
|
|
849
|
+
}, mn = () => {
|
|
850
|
+
I && R((e) => !e);
|
|
851
|
+
}, J = (e, r) => {
|
|
852
|
+
if (d) {
|
|
853
|
+
if (u == null ? void 0 : u.find((x) => x.value === r)) {
|
|
854
|
+
const x = u.filter((Cn) => Cn.value !== r);
|
|
855
|
+
z || j(x), t(x);
|
|
848
856
|
} else {
|
|
849
|
-
const
|
|
850
|
-
|
|
857
|
+
const x = [...u, { label: e, value: r }];
|
|
858
|
+
z || j(x), t(x);
|
|
851
859
|
}
|
|
852
|
-
|
|
860
|
+
s && U("");
|
|
853
861
|
} else {
|
|
854
|
-
const
|
|
855
|
-
|
|
862
|
+
const b = [{ label: e, value: r }];
|
|
863
|
+
z || j(b), t(b), s && U(H ? "" : e), R(!1);
|
|
856
864
|
}
|
|
857
865
|
};
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}, [
|
|
861
|
-
|
|
866
|
+
g(() => {
|
|
867
|
+
z && j(p || []);
|
|
868
|
+
}, [p]), g(() => {
|
|
869
|
+
z || JSON.stringify(en.current) === JSON.stringify(i) || (en.current = i, j(en.current || []));
|
|
862
870
|
}, [i]);
|
|
863
|
-
const
|
|
871
|
+
const yn = () => u.length ? d ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
864
872
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
865
873
|
/* @__PURE__ */ n(
|
|
866
|
-
|
|
874
|
+
bn,
|
|
867
875
|
{
|
|
868
|
-
onClick: (
|
|
869
|
-
|
|
876
|
+
onClick: (b) => {
|
|
877
|
+
b.stopPropagation(), J(e.label, e.value);
|
|
870
878
|
}
|
|
871
879
|
}
|
|
872
880
|
)
|
|
873
|
-
] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: u == null ? void 0 : u[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children:
|
|
874
|
-
if (
|
|
875
|
-
const e = window.innerHeight, r =
|
|
876
|
-
|
|
881
|
+
] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: u == null ? void 0 : u[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: y }), W = () => {
|
|
882
|
+
if (rn.current && v.current) {
|
|
883
|
+
const e = window.innerHeight, r = rn.current.getBoundingClientRect(), b = v.current.getBoundingClientRect(), x = r.bottom + b.height;
|
|
884
|
+
v.current.style.left = `${r.left}px`, v.current.style.width = `${r.width}px`, x >= e - 10 ? (v.current.style.top = `${r.top - b.height - 5}px`, ln("top")) : (v.current.style.top = `${r.top + r.height + 4}px`, ln("bottom"));
|
|
877
885
|
}
|
|
878
886
|
};
|
|
879
|
-
|
|
880
|
-
window.removeEventListener("resize",
|
|
881
|
-
}), []),
|
|
882
|
-
|
|
883
|
-
}, [w]),
|
|
884
|
-
if (!w || !
|
|
887
|
+
g(() => (window.addEventListener("resize", W), () => {
|
|
888
|
+
window.removeEventListener("resize", W);
|
|
889
|
+
}), []), g(() => {
|
|
890
|
+
W();
|
|
891
|
+
}, [w]), g(() => {
|
|
892
|
+
if (!w || !v.current)
|
|
885
893
|
return;
|
|
886
894
|
const e = new ResizeObserver(() => {
|
|
887
|
-
|
|
895
|
+
W();
|
|
888
896
|
});
|
|
889
|
-
return e.observe(
|
|
890
|
-
}, [w]),
|
|
891
|
-
w ||
|
|
897
|
+
return e.observe(v.current), () => e.disconnect();
|
|
898
|
+
}, [w]), g(() => {
|
|
899
|
+
w || on(-1);
|
|
892
900
|
}, [w]);
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
901
|
+
const wn = (e) => {
|
|
902
|
+
if (I) {
|
|
895
903
|
if (!w) {
|
|
896
|
-
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(),
|
|
904
|
+
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), R(!0));
|
|
897
905
|
return;
|
|
898
906
|
}
|
|
899
907
|
switch (e.key) {
|
|
900
908
|
case "ArrowDown": {
|
|
901
909
|
e.preventDefault();
|
|
902
|
-
const r =
|
|
903
|
-
r !== -1 &&
|
|
910
|
+
const r = fn(o, f, 1);
|
|
911
|
+
r !== -1 && on(r);
|
|
904
912
|
break;
|
|
905
913
|
}
|
|
906
914
|
case "ArrowUp": {
|
|
907
915
|
e.preventDefault();
|
|
908
|
-
const r =
|
|
909
|
-
r !== -1 &&
|
|
916
|
+
const r = fn(o, f, -1);
|
|
917
|
+
r !== -1 && on(r);
|
|
910
918
|
break;
|
|
911
919
|
}
|
|
912
920
|
case "Enter": {
|
|
913
|
-
e.preventDefault(),
|
|
914
|
-
o[
|
|
915
|
-
o[
|
|
921
|
+
e.preventDefault(), f >= 0 && o[f] && !o[f].disable && J(
|
|
922
|
+
o[f].label,
|
|
923
|
+
o[f].value
|
|
916
924
|
);
|
|
917
925
|
break;
|
|
918
926
|
}
|
|
919
927
|
case "Escape":
|
|
920
|
-
|
|
928
|
+
R(!1);
|
|
921
929
|
break;
|
|
922
930
|
}
|
|
923
931
|
}
|
|
924
|
-
},
|
|
932
|
+
}, P = c === "lg" || c === "xl" ? 20 : c === "xs" ? 14 : 16, kn = a && !C ? /* @__PURE__ */ n(
|
|
925
933
|
"button",
|
|
926
934
|
{
|
|
927
935
|
type: "button",
|
|
928
|
-
className: `sa-input-dropdown-clear${
|
|
936
|
+
className: `sa-input-dropdown-clear${un ? "" : " sa-input-dropdown-clear-hidden"}`,
|
|
929
937
|
"aria-label": "Clear selection",
|
|
930
|
-
"aria-hidden": !
|
|
938
|
+
"aria-hidden": !un,
|
|
931
939
|
tabIndex: -1,
|
|
932
940
|
onClick: gn,
|
|
933
941
|
onMouseDown: (e) => e.preventDefault(),
|
|
934
|
-
children: /* @__PURE__ */ n(
|
|
942
|
+
children: /* @__PURE__ */ n(Mn, { width: P, height: P })
|
|
935
943
|
}
|
|
936
|
-
) : null,
|
|
937
|
-
|
|
944
|
+
) : null, Nn = s ? /* @__PURE__ */ l(tn, { children: [
|
|
945
|
+
d && u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
938
946
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
939
947
|
/* @__PURE__ */ n(
|
|
940
|
-
|
|
948
|
+
bn,
|
|
941
949
|
{
|
|
942
|
-
onClick: (
|
|
943
|
-
|
|
950
|
+
onClick: (b) => {
|
|
951
|
+
b.stopPropagation(), J(e.label, e.value);
|
|
944
952
|
}
|
|
945
953
|
}
|
|
946
954
|
)
|
|
@@ -949,73 +957,85 @@ const Sn = ({
|
|
|
949
957
|
"input",
|
|
950
958
|
{
|
|
951
959
|
className: "sa-input-dropdown-trigger-input",
|
|
952
|
-
|
|
960
|
+
role: "combobox",
|
|
961
|
+
"aria-expanded": w,
|
|
962
|
+
"aria-haspopup": "listbox",
|
|
963
|
+
"aria-controls": G,
|
|
964
|
+
"aria-activedescendant": pn,
|
|
965
|
+
"aria-autocomplete": "list",
|
|
966
|
+
value: cn,
|
|
953
967
|
onChange: (e) => {
|
|
954
968
|
const r = e.target.value;
|
|
955
|
-
|
|
969
|
+
U(r), k == null || k(r), !w && I && R(!0);
|
|
956
970
|
},
|
|
957
971
|
onFocus: () => {
|
|
958
|
-
!
|
|
972
|
+
!C && I && R(!0);
|
|
959
973
|
},
|
|
960
974
|
onBlur: () => {
|
|
961
|
-
|
|
975
|
+
d || setTimeout(() => R(!1), 150);
|
|
962
976
|
},
|
|
963
|
-
onKeyDown:
|
|
964
|
-
placeholder: u.length === 0 ||
|
|
965
|
-
disabled:
|
|
977
|
+
onKeyDown: wn,
|
|
978
|
+
placeholder: u.length === 0 || d ? y : void 0,
|
|
979
|
+
disabled: C
|
|
966
980
|
}
|
|
967
981
|
)
|
|
968
|
-
] }) : null,
|
|
969
|
-
|
|
982
|
+
] }) : null, an = /* @__PURE__ */ n(
|
|
983
|
+
jn,
|
|
970
984
|
{
|
|
971
|
-
handleChangePosition:
|
|
985
|
+
handleChangePosition: W,
|
|
972
986
|
enabled: w,
|
|
973
|
-
children: /* @__PURE__ */
|
|
987
|
+
children: /* @__PURE__ */ l(
|
|
974
988
|
"div",
|
|
975
989
|
{
|
|
976
990
|
className: [
|
|
977
991
|
"sa-input-dropdown-container",
|
|
978
992
|
X,
|
|
979
|
-
`sa-input-dropdown-size-${
|
|
980
|
-
|
|
993
|
+
`sa-input-dropdown-size-${c}`,
|
|
994
|
+
s ? "trigger-input" : "",
|
|
981
995
|
w ? "active" : "",
|
|
982
|
-
|
|
983
|
-
|
|
996
|
+
vn ? "error" : "",
|
|
997
|
+
C ? "disable" : ""
|
|
984
998
|
].filter(Boolean).join(" "),
|
|
985
|
-
ref:
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
999
|
+
ref: rn,
|
|
1000
|
+
role: s ? void 0 : "combobox",
|
|
1001
|
+
"aria-haspopup": s ? void 0 : "listbox",
|
|
1002
|
+
"aria-expanded": s ? void 0 : w,
|
|
1003
|
+
"aria-controls": s ? void 0 : G,
|
|
1004
|
+
"aria-activedescendant": s ? void 0 : pn,
|
|
1005
|
+
onClick: s ? void 0 : mn,
|
|
1006
|
+
onKeyDown: s ? void 0 : wn,
|
|
1007
|
+
tabIndex: s ? void 0 : 0,
|
|
1008
|
+
onBlur: s ? void 0 : O,
|
|
1009
|
+
onFocus: s ? void 0 : $,
|
|
991
1010
|
children: [
|
|
992
|
-
/* @__PURE__ */
|
|
993
|
-
|
|
994
|
-
width:
|
|
1011
|
+
/* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
1012
|
+
F ? dn.cloneElement(F, {
|
|
1013
|
+
width: P,
|
|
995
1014
|
style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
|
|
996
1015
|
}) : null,
|
|
997
|
-
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children:
|
|
998
|
-
|
|
999
|
-
!
|
|
1016
|
+
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: s ? Nn : yn() }),
|
|
1017
|
+
kn,
|
|
1018
|
+
!_ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(Sn, { width: P }) : /* @__PURE__ */ n(On, { width: P }) })
|
|
1000
1019
|
] }),
|
|
1001
|
-
|
|
1002
|
-
|
|
1020
|
+
I && /* @__PURE__ */ n(
|
|
1021
|
+
Ln,
|
|
1003
1022
|
{
|
|
1004
1023
|
dropdownLists: o,
|
|
1005
|
-
handleChangeValue:
|
|
1024
|
+
handleChangeValue: J,
|
|
1006
1025
|
isComponentVisible: w,
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1026
|
+
listboxId: G,
|
|
1027
|
+
positionDropdown: xn,
|
|
1028
|
+
searchAble: !!M,
|
|
1029
|
+
hideSearch: s,
|
|
1010
1030
|
value: u,
|
|
1011
|
-
onSearch:
|
|
1012
|
-
ref:
|
|
1013
|
-
multiSelect:
|
|
1014
|
-
searchValue:
|
|
1015
|
-
highlightedIndex:
|
|
1016
|
-
footer:
|
|
1017
|
-
groupLabel:
|
|
1018
|
-
onSelectAll:
|
|
1031
|
+
onSearch: k,
|
|
1032
|
+
ref: v,
|
|
1033
|
+
multiSelect: d,
|
|
1034
|
+
searchValue: s ? cn : T,
|
|
1035
|
+
highlightedIndex: f,
|
|
1036
|
+
footer: Y,
|
|
1037
|
+
groupLabel: S,
|
|
1038
|
+
onSelectAll: q,
|
|
1019
1039
|
emptyState: Z
|
|
1020
1040
|
}
|
|
1021
1041
|
)
|
|
@@ -1024,57 +1044,57 @@ const Sn = ({
|
|
|
1024
1044
|
)
|
|
1025
1045
|
}
|
|
1026
1046
|
);
|
|
1027
|
-
return
|
|
1028
|
-
/* @__PURE__ */
|
|
1029
|
-
/* @__PURE__ */
|
|
1030
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
1031
|
-
|
|
1032
|
-
|
|
1047
|
+
return E ? V === "outside-left" ? /* @__PURE__ */ l("div", { className: `${nn} sa-select-field-left`, children: [
|
|
1048
|
+
/* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
|
|
1049
|
+
/* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
|
|
1050
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: E }),
|
|
1051
|
+
sn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1052
|
+
B && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
1033
1053
|
] }),
|
|
1034
|
-
|
|
1054
|
+
D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D })
|
|
1035
1055
|
] }),
|
|
1036
|
-
/* @__PURE__ */
|
|
1037
|
-
|
|
1038
|
-
|
|
1056
|
+
/* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
|
|
1057
|
+
an,
|
|
1058
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
1039
1059
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1040
1060
|
] })
|
|
1041
|
-
] }) : /* @__PURE__ */
|
|
1042
|
-
/* @__PURE__ */
|
|
1043
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
1044
|
-
|
|
1045
|
-
|
|
1061
|
+
] }) : /* @__PURE__ */ l("div", { className: nn, children: [
|
|
1062
|
+
/* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
|
|
1063
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: E }),
|
|
1064
|
+
sn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1065
|
+
B && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
1046
1066
|
] }),
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1067
|
+
D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
|
|
1068
|
+
an,
|
|
1069
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
1050
1070
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1051
|
-
] }) : /* @__PURE__ */
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1071
|
+
] }) : /* @__PURE__ */ l("div", { className: nn, children: [
|
|
1072
|
+
D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
|
|
1073
|
+
an,
|
|
1074
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
1055
1075
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1056
1076
|
] });
|
|
1057
|
-
},
|
|
1058
|
-
const
|
|
1059
|
-
let
|
|
1060
|
-
for (;
|
|
1061
|
-
if (!o[
|
|
1062
|
-
return
|
|
1063
|
-
|
|
1077
|
+
}, fn = (o, t, i) => {
|
|
1078
|
+
const p = o.length;
|
|
1079
|
+
let c = t + i;
|
|
1080
|
+
for (; c >= 0 && c < p; ) {
|
|
1081
|
+
if (!o[c].disable)
|
|
1082
|
+
return c;
|
|
1083
|
+
c += i;
|
|
1064
1084
|
}
|
|
1065
1085
|
if (i === 1) {
|
|
1066
|
-
for (let
|
|
1067
|
-
if (!o[
|
|
1068
|
-
return
|
|
1086
|
+
for (let d = 0; d < p; d++)
|
|
1087
|
+
if (!o[d].disable)
|
|
1088
|
+
return d;
|
|
1069
1089
|
} else
|
|
1070
|
-
for (let
|
|
1071
|
-
if (!o[
|
|
1072
|
-
return
|
|
1090
|
+
for (let d = p - 1; d >= 0; d--)
|
|
1091
|
+
if (!o[d].disable)
|
|
1092
|
+
return d;
|
|
1073
1093
|
return -1;
|
|
1074
|
-
},
|
|
1094
|
+
}, Mn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
|
|
1075
1095
|
/* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
1076
1096
|
/* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1077
|
-
] }),
|
|
1097
|
+
] }), bn = (o) => /* @__PURE__ */ n(
|
|
1078
1098
|
"svg",
|
|
1079
1099
|
{
|
|
1080
1100
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1095,7 +1115,7 @@ const Sn = ({
|
|
|
1095
1115
|
}
|
|
1096
1116
|
)
|
|
1097
1117
|
}
|
|
1098
|
-
),
|
|
1118
|
+
), On = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
1099
1119
|
"svg",
|
|
1100
1120
|
{
|
|
1101
1121
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1115,7 +1135,7 @@ const Sn = ({
|
|
|
1115
1135
|
}
|
|
1116
1136
|
)
|
|
1117
1137
|
}
|
|
1118
|
-
),
|
|
1138
|
+
), Sn = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
1119
1139
|
"svg",
|
|
1120
1140
|
{
|
|
1121
1141
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1137,5 +1157,5 @@ const Sn = ({
|
|
|
1137
1157
|
}
|
|
1138
1158
|
);
|
|
1139
1159
|
export {
|
|
1140
|
-
|
|
1160
|
+
Pn as Dropdown
|
|
1141
1161
|
};
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const hn=`* {
|
|
2
2
|
margin: 0;
|
|
3
3
|
padding: 0;
|
|
4
4
|
font-family: var(--sa-font-family, "Inter", sans-serif);
|
|
@@ -575,4 +575,4 @@
|
|
|
575
575
|
display: none;
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
`;function wn(o){const[t,d]=s.useState(o),l=s.useRef(null),p=i=>{l.current&&!l.current.contains(i.target)&&d(!1)};return s.useEffect(()=>(document.addEventListener("click",p,!0),()=>{document.removeEventListener("click",p,!0)}),[]),{ref:l,isComponentVisible:t,setIsComponentVisible:d}}const hn=({...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"})]}),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",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),un=s.forwardRef(({positionDropdown:o,dropdownLists:t,isComponentVisible:d,searchAble:l,hideSearch:p,onSearch:i,value:L,handleChangeValue:T,multiSelect:C,searchValue:m,highlightedIndex:y,footer:q,groupLabel:$,onSelectAll:k,emptyState:J},K)=>{const j=s.useRef([]),H=m!==void 0,[X,Y]=s.useState(""),I=H?m:X,c=!t||t.length===0;s.useEffect(()=>{var a;y>=0&&j.current[y]&&((a=j.current[y])==null||a.scrollIntoView({block:"nearest"}))},[y]);const Z=l&&!p?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(hn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{H||Y(a.target.value),i&&i(a.target.value)},value:I,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:K,children:[Z,n.jsxs("div",{className:`sa-input-dropdown-item-container ${C?"multi":""}`,children:[c&&n.jsx("div",{className:"sa-input-dropdown-empty",children:J??(I?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",I,"”"]})]}):"No data available")}),$&&!c&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:$}),C&&k&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),k()},children:"Select all"})]}),t==null?void 0:t.map((a,A)=>{const z=!!(L!=null&&L.find(O=>O.value===a.value)),M=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",M?"has-description":"",z?"active":"",A===y?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{j.current[A]=O},onClick:()=>T(a.label,a.value),children:[C&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:z&&n.jsx(fn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},A)})]}),q&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:q})]}):null})}),bn=({children:o,handleChangePosition:t,enabled:d=!0})=>(s.useEffect(()=>{if(d)return window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("scroll",t,!0)}},[d,t]),n.jsx("div",{children:o})),en="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(en)){const t=document.createElement("style");t.id=en,t.textContent=o,document.head.appendChild(t)}})(cn);const gn=({dropdownLists:o,onChange:t,defaultValue:d,value:l,size:p="sm",multiSelect:i,searchAble:L,iconLeft:T,placeholder:C,onSearch:m,error:y,onBlur:q,onFocus:$,disable:k,searchValue:J,variant:K="outline",footer:j,groupLabel:H,onSelectAll:X,emptyState:Y,fullWidth:I=!0,triggerInput:c=!1,clearOnSelect:Z=!1,hideChevronIcon:a=!1,clearable:A=!1,onClear:z,label:M,labelPosition:O="outside-top",required:an,optional:sn,description:B,helperText:D,errorText:f})=>{const Q=["sa-select-field",`sa-select-field-size-${p}`,I?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),N=l!==void 0,_=s.useRef(),yn=y||!!f,[w,S]=s.useState(N?l||[]:d||[]),[kn,tn]=s.useState(""),[x,V]=s.useState(-1),[dn,G]=s.useState(()=>{var e,r;return!i&&(l!=null&&l.length||d!=null&&d.length)?((e=l==null?void 0:l[0])==null?void 0:e.label)??((r=d==null?void 0:d[0])==null?void 0:r.label)??"":""}),b=s.useRef(null),{isComponentVisible:h,ref:R,setIsComponentVisible:E}=wn(!1),F=o!==void 0,ln=w.length>0,Nn=e=>{e.stopPropagation();const r=[];N||S(r),t(r),c&&G(""),z==null||z()},En=()=>{F&&E(e=>!e)},U=(e,r)=>{if(i){if(w==null?void 0:w.find(g=>g.value===r)){const g=w.filter(Dn=>Dn.value!==r);N||S(g),t(g)}else{const g=[...w,{label:e,value:r}];N||S(g),t(g)}c&&G("")}else{const u=[{label:e,value:r}];N||S(u),t(u),c&&G(Z?"":e),E(!1)}};s.useEffect(()=>{N&&S(l||[])},[l]),s.useEffect(()=>{N||JSON.stringify(_.current)===JSON.stringify(d)||(_.current=d,S(_.current||[]))},[d]);const Cn=()=>w.length?i?w==null?void 0:w.map((e,r)=>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(rn,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:C}),P=()=>{if(R.current&&b.current){const e=window.innerHeight,r=R.current.getBoundingClientRect(),u=b.current.getBoundingClientRect(),g=r.bottom+u.height;b.current.style.left=`${r.left}px`,b.current.style.width=`${r.width}px`,g>=e-10?(b.current.style.top=`${r.top-u.height-5}px`,tn("top")):(b.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P)}),[]),s.useEffect(()=>{P()},[h]),s.useEffect(()=>{if(!h||!b.current)return;const e=new ResizeObserver(()=>{P()});return e.observe(b.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||V(-1)},[h]);const pn=e=>{if(F){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=on(o,x,1);r!==-1&&V(r);break}case"ArrowUp":{e.preventDefault();const r=on(o,x,-1);r!==-1&&V(r);break}case"Enter":{e.preventDefault(),x>=0&&o[x]&&!o[x].disable&&U(o[x].label,o[x].value);break}case"Escape":E(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,zn=A&&!k?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${ln?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!ln,tabIndex:-1,onClick:Nn,onMouseDown:e=>e.preventDefault(),children:n.jsx(vn,{width:W,height:W})}):null,Bn=c?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>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(rn,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:dn,onChange:e=>{const r=e.target.value;G(r),m==null||m(r),!h&&F&&E(!0)},onFocus:()=>{!k&&F&&E(!0)},onBlur:()=>{i||setTimeout(()=>E(!1),150)},onKeyDown:pn,placeholder:w.length===0||i?C:void 0,disabled:k})]}):null,nn=n.jsx(bn,{handleChangePosition:P,enabled:h,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${p}`,c?"trigger-input":"",h?"active":"",yn?"error":"",k?"disable":""].filter(Boolean).join(" "),ref:R,onClick:c?void 0:En,onKeyDown:c?void 0:pn,tabIndex:c?void 0:0,onBlur:c?void 0:q,onFocus:c?void 0:$,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[T?s.cloneElement(T,{width:W,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:c?Bn:Cn()}),zn,!a&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:h?n.jsx(mn,{width:W}):n.jsx(xn,{width:W})})]}),F&&n.jsx(un,{dropdownLists:o,handleChangeValue:U,isComponentVisible:h,positionDropdown:kn,searchAble:!!L,hideSearch:c,value:w,onSearch:m,ref:b,multiSelect:i,searchValue:c?dn:J,highlightedIndex:x,footer:j,groupLabel:H,onSelectAll:X,emptyState:Y})]})});return M?O==="outside-left"?n.jsxs("div",{className:`${Q} 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:M}),sn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),an&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[nn,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:Q,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:M}),sn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),an&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),nn,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:Q,children:[B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),nn,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},on=(o,t,d)=>{const l=o.length;let p=t+d;for(;p>=0&&p<l;){if(!o[p].disable)return p;p+=d}if(d===1){for(let i=0;i<l;i++)if(!o[i].disable)return i}else for(let i=l-1;i>=0;i--)if(!o[i].disable)return i;return-1},vn=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"})]}),rn=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"})}),xn=({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"})}),mn=({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=gn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
578
|
+
`;function fn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const un=({...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"})]}),bn=({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"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue:W,multiSelect:y,searchValue:k,highlightedIndex:N,listboxId:M,footer:T,groupLabel:E,onSelectAll:$,emptyState:K},X)=>{const O=s.useRef([]),q=k!==void 0,[Y,Z]=s.useState(""),l=q?k:Y,H=!d||d.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(un,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(D=>D.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:D=>{O.current[m]=D},onClick:()=>W(a.label,a.value),children:[y&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),T&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:T})]}):null})}),xn=({children:o,handleChangePosition:d,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",d,!0),()=>{window.removeEventListener("scroll",d,!0)}},[t,d]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const d=document.createElement("style");d.id=rn,d.textContent=o,document.head.appendChild(d)}})(hn);const gn=({dropdownLists:o,onChange:d,defaultValue:t,value:p,size:c="sm",multiSelect:i,searchAble:A,iconLeft:W,placeholder:y,onSearch:k,error:N,onBlur:M,onFocus:T,disable:E,searchValue:$,variant:K="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:D,optional:dn,description:S,helperText:L,errorText:f})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!f,[w,j]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[u,nn]=s.useState(-1),G=s.useId(),ln=u>=0?`${G}-opt-${u}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:h,ref:en,setIsComponentVisible:B}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||j(r),d(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(i){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(Ln=>Ln.value!==r);z||j(x),d(x)}else{const x=[...w,{label:e,value:r}];z||j(x),d(x)}l&&U("")}else{const b=[{label:e,value:r}];z||j(b),d(b),l&&U(H?"":e),B(!1)}};s.useEffect(()=>{z&&j(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,j(R.current||[]))},[t]);const Bn=()=>w.length?i?w==null?void 0:w.map((e,r)=>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(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:y}),F=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),x=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,x>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[h]),s.useEffect(()=>{if(!h||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||nn(-1)},[h]);const wn=e=>{if(I){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,u,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,u,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),u>=0&&o[u]&&!o[u].disable&&J(o[u].label,o[u].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Dn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Sn=l?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>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(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":h,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!h&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{i||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||i?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:h,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",h?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:h,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:T,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[W?s.cloneElement(W,{width:P,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Sn:Bn()}),Dn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:h?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:h,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:u,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} 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:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&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:[on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:V,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},an=(o,d,t)=>{const p=o.length;let c=d+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let i=0;i<p;i++)if(!o[i].disable)return i}else for(let i=p-1;i>=0;i--)if(!o[i].disable)return i;return-1},mn=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"})]}),sn=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"})}),yn=({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"})}),kn=({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"})});g.Dropdown=gn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|