@starasia/dropdown 5.5.5 → 5.5.6
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 +227 -203
- package/dist/dropdown.umd.js +17 -2
- package/package.json +1 -1
package/dist/dropdown.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as d, jsx as n, Fragment as
|
|
2
|
-
import
|
|
1
|
+
import { jsxs as d, jsx as n, Fragment as pn } from "react/jsx-runtime";
|
|
2
|
+
import cn, { useState as j, useRef as J, useEffect as b, 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;
|
|
@@ -297,6 +297,21 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
/* Panel opened upward: search bar moves below the list. Done with \`order\` so
|
|
301
|
+
the input keeps its DOM node — re-parenting it in JSX would remount it and
|
|
302
|
+
wipe the text the user is typing. */
|
|
303
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-item-container {
|
|
304
|
+
order: 1;
|
|
305
|
+
}
|
|
306
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-container-dropdown-search {
|
|
307
|
+
order: 2;
|
|
308
|
+
border-bottom: none;
|
|
309
|
+
border-top: 1px solid var(--sa-dropdown-border-subtle);
|
|
310
|
+
}
|
|
311
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-footer {
|
|
312
|
+
order: 3;
|
|
313
|
+
}
|
|
314
|
+
|
|
300
315
|
/* === LIST SCROLL AREA === */
|
|
301
316
|
.sa-input-dropdown-item-container {
|
|
302
317
|
flex: 1 1 auto;
|
|
@@ -547,12 +562,12 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
547
562
|
|
|
548
563
|
`;
|
|
549
564
|
function Cn(o) {
|
|
550
|
-
const [l,
|
|
551
|
-
s.current && !s.current.contains(
|
|
565
|
+
const [l, t] = j(o), s = J(null), p = (i) => {
|
|
566
|
+
s.current && !s.current.contains(i.target) && t(!1);
|
|
552
567
|
};
|
|
553
|
-
return
|
|
568
|
+
return b(() => (document.addEventListener("click", p, !0), () => {
|
|
554
569
|
document.removeEventListener("click", p, !0);
|
|
555
|
-
}), []), { ref: s, isComponentVisible: l, setIsComponentVisible:
|
|
570
|
+
}), []), { ref: s, isComponentVisible: l, setIsComponentVisible: t };
|
|
556
571
|
}
|
|
557
572
|
const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
558
573
|
"svg",
|
|
@@ -609,83 +624,93 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
609
624
|
({
|
|
610
625
|
positionDropdown: o,
|
|
611
626
|
dropdownLists: l,
|
|
612
|
-
isComponentVisible:
|
|
627
|
+
isComponentVisible: t,
|
|
613
628
|
searchAble: s,
|
|
614
629
|
hideSearch: p,
|
|
615
|
-
onSearch:
|
|
616
|
-
value:
|
|
617
|
-
handleChangeValue:
|
|
618
|
-
multiSelect:
|
|
619
|
-
searchValue:
|
|
620
|
-
highlightedIndex:
|
|
621
|
-
footer:
|
|
622
|
-
groupLabel:
|
|
623
|
-
onSelectAll:
|
|
624
|
-
},
|
|
625
|
-
const
|
|
626
|
-
|
|
630
|
+
onSearch: i,
|
|
631
|
+
value: A,
|
|
632
|
+
handleChangeValue: F,
|
|
633
|
+
multiSelect: z,
|
|
634
|
+
searchValue: m,
|
|
635
|
+
highlightedIndex: k,
|
|
636
|
+
footer: T,
|
|
637
|
+
groupLabel: $,
|
|
638
|
+
onSelectAll: y
|
|
639
|
+
}, K) => {
|
|
640
|
+
const I = J([]), R = m !== void 0, [X, q] = j(""), Z = R ? m : X;
|
|
641
|
+
b(() => {
|
|
627
642
|
var a;
|
|
628
|
-
|
|
629
|
-
}, [
|
|
630
|
-
|
|
643
|
+
k >= 0 && I.current[k] && ((a = I.current[k]) == null || a.scrollIntoView({ block: "nearest" }));
|
|
644
|
+
}, [k]), b(() => {
|
|
645
|
+
!t && !R && q("");
|
|
646
|
+
}, [t, R]);
|
|
647
|
+
const w = s && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
631
648
|
/* @__PURE__ */ n(En, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
632
649
|
/* @__PURE__ */ n(
|
|
633
650
|
"input",
|
|
634
651
|
{
|
|
635
652
|
onChange: (a) => {
|
|
636
|
-
|
|
653
|
+
R || q(a.target.value), i && i(a.target.value);
|
|
637
654
|
},
|
|
638
|
-
value:
|
|
655
|
+
value: Z,
|
|
639
656
|
autoFocus: !0,
|
|
640
657
|
placeholder: "Search..."
|
|
641
658
|
}
|
|
642
659
|
)
|
|
643
660
|
] }) : null;
|
|
644
|
-
return /* @__PURE__ */ n(
|
|
661
|
+
return /* @__PURE__ */ n(pn, { children: t ? /* @__PURE__ */ d(
|
|
645
662
|
"div",
|
|
646
663
|
{
|
|
647
|
-
className:
|
|
664
|
+
className: [
|
|
665
|
+
"sa-input-dropdown-lists-container",
|
|
666
|
+
/* When the panel opens upward the search bar sits below the
|
|
667
|
+
list. That is a CSS `order` swap, never a second JSX slot —
|
|
668
|
+
moving the node between slots would remount the input and
|
|
669
|
+
drop both the typed text and the caret every time the panel
|
|
670
|
+
flips (which it does whenever filtering resizes the panel). */
|
|
671
|
+
o === "top" ? "search-bottom" : ""
|
|
672
|
+
].filter(Boolean).join(" "),
|
|
648
673
|
onClick: (a) => a.stopPropagation(),
|
|
649
|
-
ref:
|
|
674
|
+
ref: K,
|
|
650
675
|
children: [
|
|
651
|
-
|
|
676
|
+
w,
|
|
652
677
|
/* @__PURE__ */ d(
|
|
653
678
|
"div",
|
|
654
679
|
{
|
|
655
|
-
className: `sa-input-dropdown-item-container ${
|
|
680
|
+
className: `sa-input-dropdown-item-container ${z ? "multi" : ""}`,
|
|
656
681
|
children: [
|
|
657
|
-
|
|
658
|
-
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children:
|
|
659
|
-
|
|
682
|
+
$ && /* @__PURE__ */ d("div", { className: "sa-input-dropdown-section-header", children: [
|
|
683
|
+
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: $ }),
|
|
684
|
+
z && y && /* @__PURE__ */ n(
|
|
660
685
|
"button",
|
|
661
686
|
{
|
|
662
687
|
className: "sa-input-dropdown-section-select-all",
|
|
663
688
|
onClick: (a) => {
|
|
664
|
-
a.stopPropagation(),
|
|
689
|
+
a.stopPropagation(), y();
|
|
665
690
|
},
|
|
666
691
|
children: "Select all"
|
|
667
692
|
}
|
|
668
693
|
)
|
|
669
694
|
] }),
|
|
670
|
-
l.map((a,
|
|
671
|
-
const
|
|
695
|
+
l.map((a, O) => {
|
|
696
|
+
const H = !!(A != null && A.find((N) => N.value === a.value)), M = !!a.description;
|
|
672
697
|
return /* @__PURE__ */ d(
|
|
673
698
|
"div",
|
|
674
699
|
{
|
|
675
700
|
className: [
|
|
676
701
|
"sa-input-dropdown-item",
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
702
|
+
M ? "has-description" : "",
|
|
703
|
+
H ? "active" : "",
|
|
704
|
+
O === k ? "highlight" : "",
|
|
680
705
|
a.disable ? "sa-input-dropdown-item-disable" : ""
|
|
681
706
|
].filter(Boolean).join(" "),
|
|
682
|
-
ref: (
|
|
683
|
-
|
|
707
|
+
ref: (N) => {
|
|
708
|
+
I.current[O] = N;
|
|
684
709
|
},
|
|
685
|
-
onClick: () =>
|
|
710
|
+
onClick: () => F(a.label, a.value),
|
|
686
711
|
children: [
|
|
687
|
-
|
|
688
|
-
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children:
|
|
712
|
+
z && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: H && /* @__PURE__ */ n(zn, { width: 16 }) }),
|
|
713
|
+
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: cn.cloneElement(a.icon, { width: 16 }) }),
|
|
689
714
|
/* @__PURE__ */ d("div", { style: { minWidth: 0, flex: 1 }, children: [
|
|
690
715
|
/* @__PURE__ */ n(
|
|
691
716
|
"p",
|
|
@@ -710,14 +735,13 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
710
735
|
] })
|
|
711
736
|
]
|
|
712
737
|
},
|
|
713
|
-
|
|
738
|
+
O
|
|
714
739
|
);
|
|
715
740
|
})
|
|
716
741
|
]
|
|
717
742
|
}
|
|
718
743
|
),
|
|
719
|
-
|
|
720
|
-
F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: F })
|
|
744
|
+
T && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: T })
|
|
721
745
|
]
|
|
722
746
|
}
|
|
723
747
|
) : null });
|
|
@@ -725,172 +749,172 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
725
749
|
), Bn = ({
|
|
726
750
|
children: o,
|
|
727
751
|
handleChangePosition: l,
|
|
728
|
-
enabled:
|
|
729
|
-
}) => (
|
|
730
|
-
if (
|
|
752
|
+
enabled: t = !0
|
|
753
|
+
}) => (b(() => {
|
|
754
|
+
if (t)
|
|
731
755
|
return window.addEventListener("scroll", l, !0), () => {
|
|
732
756
|
window.removeEventListener("scroll", l, !0);
|
|
733
757
|
};
|
|
734
|
-
}, [
|
|
735
|
-
if (!(typeof document > "u") && !document.getElementById(
|
|
758
|
+
}, [t, l]), /* @__PURE__ */ n("div", { children: o })), sn = "sa-input-dropdown-styles", Ln = (o) => {
|
|
759
|
+
if (!(typeof document > "u") && !document.getElementById(sn)) {
|
|
736
760
|
const l = document.createElement("style");
|
|
737
|
-
l.id =
|
|
761
|
+
l.id = sn, l.textContent = o, document.head.appendChild(l);
|
|
738
762
|
}
|
|
739
763
|
};
|
|
740
764
|
Ln(Nn);
|
|
741
765
|
const Mn = ({
|
|
742
766
|
dropdownLists: o,
|
|
743
767
|
onChange: l,
|
|
744
|
-
defaultValue:
|
|
768
|
+
defaultValue: t,
|
|
745
769
|
value: s,
|
|
746
770
|
size: p = "sm",
|
|
747
|
-
multiSelect:
|
|
748
|
-
searchAble:
|
|
749
|
-
iconLeft:
|
|
750
|
-
placeholder:
|
|
751
|
-
onSearch:
|
|
752
|
-
error:
|
|
753
|
-
onBlur:
|
|
754
|
-
onFocus:
|
|
755
|
-
disable:
|
|
756
|
-
searchValue:
|
|
757
|
-
variant:
|
|
758
|
-
footer:
|
|
759
|
-
groupLabel:
|
|
760
|
-
onSelectAll:
|
|
761
|
-
fullWidth:
|
|
762
|
-
triggerInput:
|
|
763
|
-
clearOnSelect:
|
|
764
|
-
hideChevronIcon:
|
|
765
|
-
clearable:
|
|
766
|
-
onClear:
|
|
771
|
+
multiSelect: i,
|
|
772
|
+
searchAble: A,
|
|
773
|
+
iconLeft: F,
|
|
774
|
+
placeholder: z,
|
|
775
|
+
onSearch: m,
|
|
776
|
+
error: k,
|
|
777
|
+
onBlur: T,
|
|
778
|
+
onFocus: $,
|
|
779
|
+
disable: y,
|
|
780
|
+
searchValue: K,
|
|
781
|
+
variant: I = "outline",
|
|
782
|
+
footer: R,
|
|
783
|
+
groupLabel: X,
|
|
784
|
+
onSelectAll: q,
|
|
785
|
+
fullWidth: Z = !0,
|
|
786
|
+
triggerInput: w = !1,
|
|
787
|
+
clearOnSelect: a = !1,
|
|
788
|
+
hideChevronIcon: O = !1,
|
|
789
|
+
clearable: H = !1,
|
|
790
|
+
onClear: M,
|
|
767
791
|
/* field wrapper */
|
|
768
|
-
label:
|
|
769
|
-
labelPosition:
|
|
770
|
-
required:
|
|
771
|
-
optional:
|
|
772
|
-
description:
|
|
773
|
-
helperText:
|
|
792
|
+
label: N,
|
|
793
|
+
labelPosition: wn = "outside-top",
|
|
794
|
+
required: en,
|
|
795
|
+
optional: on,
|
|
796
|
+
description: B,
|
|
797
|
+
helperText: L,
|
|
774
798
|
errorText: h
|
|
775
799
|
}) => {
|
|
776
|
-
const
|
|
800
|
+
const Q = [
|
|
777
801
|
"sa-select-field",
|
|
778
802
|
`sa-select-field-size-${p}`,
|
|
779
|
-
|
|
780
|
-
].filter(Boolean).join(" "),
|
|
781
|
-
|
|
782
|
-
), [hn,
|
|
803
|
+
Z ? "sa-select-field-fullwidth" : ""
|
|
804
|
+
].filter(Boolean).join(" "), C = s !== void 0, Y = J(), un = k || !!h, [c, D] = j(
|
|
805
|
+
C ? s || [] : t || []
|
|
806
|
+
), [hn, rn] = j(""), [v, _] = j(-1), [fn, G] = j(
|
|
783
807
|
() => {
|
|
784
808
|
var e, r;
|
|
785
|
-
return !
|
|
809
|
+
return !i && (s != null && s.length || t != null && t.length) ? ((e = s == null ? void 0 : s[0]) == null ? void 0 : e.label) ?? ((r = t == null ? void 0 : t[0]) == null ? void 0 : r.label) ?? "" : "";
|
|
786
810
|
}
|
|
787
|
-
),
|
|
811
|
+
), g = J(null), { isComponentVisible: u, ref: V, setIsComponentVisible: E } = Cn(!1), P = o !== void 0, an = c.length > 0, bn = (e) => {
|
|
788
812
|
e.stopPropagation();
|
|
789
813
|
const r = [];
|
|
790
|
-
|
|
814
|
+
C || D(r), l(r), w && G(""), M == null || M();
|
|
791
815
|
}, gn = () => {
|
|
792
|
-
|
|
793
|
-
},
|
|
794
|
-
if (
|
|
795
|
-
if (c == null ? void 0 : c.find((
|
|
796
|
-
const
|
|
797
|
-
|
|
816
|
+
P && E((e) => !e);
|
|
817
|
+
}, U = (e, r) => {
|
|
818
|
+
if (i) {
|
|
819
|
+
if (c == null ? void 0 : c.find((x) => x.value === r)) {
|
|
820
|
+
const x = c.filter((kn) => kn.value !== r);
|
|
821
|
+
C || D(x), l(x);
|
|
798
822
|
} else {
|
|
799
|
-
const
|
|
800
|
-
|
|
823
|
+
const x = [...c, { label: e, value: r }];
|
|
824
|
+
C || D(x), l(x);
|
|
801
825
|
}
|
|
802
|
-
|
|
826
|
+
w && G("");
|
|
803
827
|
} else {
|
|
804
828
|
const f = [{ label: e, value: r }];
|
|
805
|
-
|
|
829
|
+
C || D(f), l(f), w && G(a ? "" : e), E(!1);
|
|
806
830
|
}
|
|
807
831
|
};
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}, [s]),
|
|
811
|
-
|
|
812
|
-
}, [
|
|
813
|
-
const xn = () => c.length ?
|
|
832
|
+
b(() => {
|
|
833
|
+
C && D(s || []);
|
|
834
|
+
}, [s]), b(() => {
|
|
835
|
+
C || JSON.stringify(Y.current) === JSON.stringify(t) || (Y.current = t, D(Y.current || []));
|
|
836
|
+
}, [t]);
|
|
837
|
+
const xn = () => c.length ? i ? c == null ? void 0 : c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
814
838
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
815
839
|
/* @__PURE__ */ n(
|
|
816
|
-
|
|
840
|
+
ln,
|
|
817
841
|
{
|
|
818
842
|
onClick: (f) => {
|
|
819
|
-
f.stopPropagation(),
|
|
843
|
+
f.stopPropagation(), U(e.label, e.value);
|
|
820
844
|
}
|
|
821
845
|
}
|
|
822
846
|
)
|
|
823
|
-
] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children:
|
|
824
|
-
if (
|
|
825
|
-
const e = window.innerHeight, r =
|
|
826
|
-
|
|
847
|
+
] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: z }), S = () => {
|
|
848
|
+
if (V.current && g.current) {
|
|
849
|
+
const e = window.innerHeight, r = V.current.getBoundingClientRect(), f = g.current.getBoundingClientRect(), x = r.bottom + f.height;
|
|
850
|
+
g.current.style.left = `${r.left}px`, g.current.style.width = `${r.width}px`, x >= e - 10 ? (g.current.style.top = `${r.top - f.height - 5}px`, rn("top")) : (g.current.style.top = `${r.top + r.height + 4}px`, rn("bottom"));
|
|
827
851
|
}
|
|
828
852
|
};
|
|
829
|
-
|
|
830
|
-
window.removeEventListener("resize",
|
|
831
|
-
}), []),
|
|
832
|
-
|
|
833
|
-
}, [
|
|
834
|
-
if (!
|
|
853
|
+
b(() => (window.addEventListener("resize", S), () => {
|
|
854
|
+
window.removeEventListener("resize", S);
|
|
855
|
+
}), []), b(() => {
|
|
856
|
+
S();
|
|
857
|
+
}, [u]), b(() => {
|
|
858
|
+
if (!u || !g.current)
|
|
835
859
|
return;
|
|
836
860
|
const e = new ResizeObserver(() => {
|
|
837
|
-
|
|
861
|
+
S();
|
|
838
862
|
});
|
|
839
|
-
return e.observe(
|
|
840
|
-
}, [
|
|
841
|
-
|
|
842
|
-
}, [
|
|
843
|
-
const
|
|
844
|
-
if (
|
|
845
|
-
if (!
|
|
846
|
-
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(),
|
|
863
|
+
return e.observe(g.current), () => e.disconnect();
|
|
864
|
+
}, [u]), b(() => {
|
|
865
|
+
u || _(-1);
|
|
866
|
+
}, [u]);
|
|
867
|
+
const tn = (e) => {
|
|
868
|
+
if (P) {
|
|
869
|
+
if (!u) {
|
|
870
|
+
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), E(!0));
|
|
847
871
|
return;
|
|
848
872
|
}
|
|
849
873
|
switch (e.key) {
|
|
850
874
|
case "ArrowDown": {
|
|
851
875
|
e.preventDefault();
|
|
852
|
-
const r =
|
|
853
|
-
r !== -1 &&
|
|
876
|
+
const r = dn(o, v, 1);
|
|
877
|
+
r !== -1 && _(r);
|
|
854
878
|
break;
|
|
855
879
|
}
|
|
856
880
|
case "ArrowUp": {
|
|
857
881
|
e.preventDefault();
|
|
858
|
-
const r =
|
|
859
|
-
r !== -1 &&
|
|
882
|
+
const r = dn(o, v, -1);
|
|
883
|
+
r !== -1 && _(r);
|
|
860
884
|
break;
|
|
861
885
|
}
|
|
862
886
|
case "Enter": {
|
|
863
|
-
e.preventDefault(), v >= 0 && o[v] && !o[v].disable &&
|
|
887
|
+
e.preventDefault(), v >= 0 && o[v] && !o[v].disable && U(
|
|
864
888
|
o[v].label,
|
|
865
889
|
o[v].value
|
|
866
890
|
);
|
|
867
891
|
break;
|
|
868
892
|
}
|
|
869
893
|
case "Escape":
|
|
870
|
-
|
|
894
|
+
E(!1);
|
|
871
895
|
break;
|
|
872
896
|
}
|
|
873
897
|
}
|
|
874
|
-
},
|
|
898
|
+
}, W = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, vn = H && !y ? /* @__PURE__ */ n(
|
|
875
899
|
"button",
|
|
876
900
|
{
|
|
877
901
|
type: "button",
|
|
878
|
-
className: `sa-input-dropdown-clear${
|
|
902
|
+
className: `sa-input-dropdown-clear${an ? "" : " sa-input-dropdown-clear-hidden"}`,
|
|
879
903
|
"aria-label": "Clear selection",
|
|
880
|
-
"aria-hidden": !
|
|
904
|
+
"aria-hidden": !an,
|
|
881
905
|
tabIndex: -1,
|
|
882
906
|
onClick: bn,
|
|
883
907
|
onMouseDown: (e) => e.preventDefault(),
|
|
884
|
-
children: /* @__PURE__ */ n(Dn, { width:
|
|
908
|
+
children: /* @__PURE__ */ n(Dn, { width: W, height: W })
|
|
885
909
|
}
|
|
886
|
-
) : null, mn =
|
|
887
|
-
|
|
910
|
+
) : null, mn = w ? /* @__PURE__ */ d(pn, { children: [
|
|
911
|
+
i && c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
888
912
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
889
913
|
/* @__PURE__ */ n(
|
|
890
|
-
|
|
914
|
+
ln,
|
|
891
915
|
{
|
|
892
916
|
onClick: (f) => {
|
|
893
|
-
f.stopPropagation(),
|
|
917
|
+
f.stopPropagation(), U(e.label, e.value);
|
|
894
918
|
}
|
|
895
919
|
}
|
|
896
920
|
)
|
|
@@ -902,70 +926,70 @@ const Mn = ({
|
|
|
902
926
|
value: fn,
|
|
903
927
|
onChange: (e) => {
|
|
904
928
|
const r = e.target.value;
|
|
905
|
-
|
|
929
|
+
G(r), m == null || m(r), !u && P && E(!0);
|
|
906
930
|
},
|
|
907
931
|
onFocus: () => {
|
|
908
|
-
!
|
|
932
|
+
!y && P && E(!0);
|
|
909
933
|
},
|
|
910
934
|
onBlur: () => {
|
|
911
|
-
|
|
935
|
+
i || setTimeout(() => E(!1), 150);
|
|
912
936
|
},
|
|
913
|
-
onKeyDown:
|
|
914
|
-
placeholder: c.length === 0 ||
|
|
915
|
-
disabled:
|
|
937
|
+
onKeyDown: tn,
|
|
938
|
+
placeholder: c.length === 0 || i ? z : void 0,
|
|
939
|
+
disabled: y
|
|
916
940
|
}
|
|
917
941
|
)
|
|
918
|
-
] }) : null,
|
|
942
|
+
] }) : null, nn = /* @__PURE__ */ n(
|
|
919
943
|
Bn,
|
|
920
944
|
{
|
|
921
|
-
handleChangePosition:
|
|
922
|
-
enabled:
|
|
945
|
+
handleChangePosition: S,
|
|
946
|
+
enabled: u,
|
|
923
947
|
children: /* @__PURE__ */ d(
|
|
924
948
|
"div",
|
|
925
949
|
{
|
|
926
950
|
className: [
|
|
927
951
|
"sa-input-dropdown-container",
|
|
928
|
-
|
|
952
|
+
I,
|
|
929
953
|
`sa-input-dropdown-size-${p}`,
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
954
|
+
w ? "trigger-input" : "",
|
|
955
|
+
u ? "active" : "",
|
|
956
|
+
un ? "error" : "",
|
|
957
|
+
y ? "disable" : ""
|
|
934
958
|
].filter(Boolean).join(" "),
|
|
935
|
-
ref:
|
|
936
|
-
onClick:
|
|
937
|
-
onKeyDown:
|
|
938
|
-
tabIndex:
|
|
939
|
-
onBlur:
|
|
940
|
-
onFocus:
|
|
959
|
+
ref: V,
|
|
960
|
+
onClick: w ? void 0 : gn,
|
|
961
|
+
onKeyDown: w ? void 0 : tn,
|
|
962
|
+
tabIndex: w ? void 0 : 0,
|
|
963
|
+
onBlur: w ? void 0 : T,
|
|
964
|
+
onFocus: w ? void 0 : $,
|
|
941
965
|
children: [
|
|
942
966
|
/* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
943
|
-
|
|
944
|
-
width:
|
|
967
|
+
F ? cn.cloneElement(F, {
|
|
968
|
+
width: W,
|
|
945
969
|
style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
|
|
946
970
|
}) : null,
|
|
947
|
-
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children:
|
|
971
|
+
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : xn() }),
|
|
948
972
|
vn,
|
|
949
|
-
!
|
|
973
|
+
!O && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: u ? /* @__PURE__ */ n(An, { width: W }) : /* @__PURE__ */ n(jn, { width: W }) })
|
|
950
974
|
] }),
|
|
951
|
-
|
|
975
|
+
P && /* @__PURE__ */ n(
|
|
952
976
|
Rn,
|
|
953
977
|
{
|
|
954
978
|
dropdownLists: o,
|
|
955
|
-
handleChangeValue:
|
|
956
|
-
isComponentVisible:
|
|
979
|
+
handleChangeValue: U,
|
|
980
|
+
isComponentVisible: u,
|
|
957
981
|
positionDropdown: hn,
|
|
958
|
-
searchAble: !!
|
|
959
|
-
hideSearch:
|
|
982
|
+
searchAble: !!A,
|
|
983
|
+
hideSearch: w,
|
|
960
984
|
value: c,
|
|
961
|
-
onSearch:
|
|
962
|
-
ref:
|
|
963
|
-
multiSelect:
|
|
964
|
-
searchValue:
|
|
985
|
+
onSearch: m,
|
|
986
|
+
ref: g,
|
|
987
|
+
multiSelect: i,
|
|
988
|
+
searchValue: K,
|
|
965
989
|
highlightedIndex: v,
|
|
966
|
-
footer:
|
|
967
|
-
groupLabel:
|
|
968
|
-
onSelectAll:
|
|
990
|
+
footer: R,
|
|
991
|
+
groupLabel: X,
|
|
992
|
+
onSelectAll: q
|
|
969
993
|
}
|
|
970
994
|
)
|
|
971
995
|
]
|
|
@@ -973,57 +997,57 @@ const Mn = ({
|
|
|
973
997
|
)
|
|
974
998
|
}
|
|
975
999
|
);
|
|
976
|
-
return
|
|
1000
|
+
return N ? wn === "outside-left" ? /* @__PURE__ */ d("div", { className: `${Q} sa-select-field-left`, children: [
|
|
977
1001
|
/* @__PURE__ */ d("div", { className: "sa-select-field-left-label", children: [
|
|
978
1002
|
/* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
|
|
979
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
980
|
-
|
|
981
|
-
|
|
1003
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: N }),
|
|
1004
|
+
on && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1005
|
+
en && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
982
1006
|
] }),
|
|
983
|
-
|
|
1007
|
+
B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B })
|
|
984
1008
|
] }),
|
|
985
1009
|
/* @__PURE__ */ d("div", { className: "sa-select-field-input-wrap", children: [
|
|
986
|
-
|
|
987
|
-
|
|
1010
|
+
nn,
|
|
1011
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
988
1012
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
989
1013
|
] })
|
|
990
|
-
] }) : /* @__PURE__ */ d("div", { className:
|
|
1014
|
+
] }) : /* @__PURE__ */ d("div", { className: Q, children: [
|
|
991
1015
|
/* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
|
|
992
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
993
|
-
|
|
994
|
-
|
|
1016
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: N }),
|
|
1017
|
+
on && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1018
|
+
en && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
995
1019
|
] }),
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1020
|
+
B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
|
|
1021
|
+
nn,
|
|
1022
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
999
1023
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1000
|
-
] }) : /* @__PURE__ */ d("div", { className:
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1024
|
+
] }) : /* @__PURE__ */ d("div", { className: Q, children: [
|
|
1025
|
+
B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
|
|
1026
|
+
nn,
|
|
1027
|
+
L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
|
|
1004
1028
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1005
1029
|
] });
|
|
1006
|
-
},
|
|
1030
|
+
}, dn = (o, l, t) => {
|
|
1007
1031
|
const s = o.length;
|
|
1008
|
-
let p = l +
|
|
1032
|
+
let p = l + t;
|
|
1009
1033
|
for (; p >= 0 && p < s; ) {
|
|
1010
1034
|
if (!o[p].disable)
|
|
1011
1035
|
return p;
|
|
1012
|
-
p +=
|
|
1036
|
+
p += t;
|
|
1013
1037
|
}
|
|
1014
|
-
if (
|
|
1015
|
-
for (let
|
|
1016
|
-
if (!o[
|
|
1017
|
-
return
|
|
1038
|
+
if (t === 1) {
|
|
1039
|
+
for (let i = 0; i < s; i++)
|
|
1040
|
+
if (!o[i].disable)
|
|
1041
|
+
return i;
|
|
1018
1042
|
} else
|
|
1019
|
-
for (let
|
|
1020
|
-
if (!o[
|
|
1021
|
-
return
|
|
1043
|
+
for (let i = s - 1; i >= 0; i--)
|
|
1044
|
+
if (!o[i].disable)
|
|
1045
|
+
return i;
|
|
1022
1046
|
return -1;
|
|
1023
1047
|
}, Dn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
|
|
1024
1048
|
/* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
1025
1049
|
/* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1026
|
-
] }),
|
|
1050
|
+
] }), ln = (o) => /* @__PURE__ */ n(
|
|
1027
1051
|
"svg",
|
|
1028
1052
|
{
|
|
1029
1053
|
xmlns: "http://www.w3.org/2000/svg",
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Dropdown={},x.jsxRuntime,x.React))})(this,function(x,n,
|
|
1
|
+
(function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Dropdown={},x.jsxRuntime,x.React))})(this,function(x,n,d){"use strict";const tn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
2
2
|
* {
|
|
3
3
|
margin: 0;
|
|
4
4
|
padding: 0;
|
|
@@ -295,6 +295,21 @@
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
/* Panel opened upward: search bar moves below the list. Done with \`order\` so
|
|
299
|
+
the input keeps its DOM node — re-parenting it in JSX would remount it and
|
|
300
|
+
wipe the text the user is typing. */
|
|
301
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-item-container {
|
|
302
|
+
order: 1;
|
|
303
|
+
}
|
|
304
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-container-dropdown-search {
|
|
305
|
+
order: 2;
|
|
306
|
+
border-bottom: none;
|
|
307
|
+
border-top: 1px solid var(--sa-dropdown-border-subtle);
|
|
308
|
+
}
|
|
309
|
+
.sa-input-dropdown-lists-container.search-bottom > .sa-input-dropdown-footer {
|
|
310
|
+
order: 3;
|
|
311
|
+
}
|
|
312
|
+
|
|
298
313
|
/* === LIST SCROLL AREA === */
|
|
299
314
|
.sa-input-dropdown-item-container {
|
|
300
315
|
flex: 1 1 auto;
|
|
@@ -543,4 +558,4 @@
|
|
|
543
558
|
display: none;
|
|
544
559
|
}
|
|
545
560
|
|
|
546
|
-
`;function dn(o){const[l,s]=i.useState(o),t=i.useRef(null),p=d=>{t.current&&!t.current.contains(d.target)&&s(!1)};return i.useEffect(()=>(document.addEventListener("click",p,!0),()=>{document.removeEventListener("click",p,!0)}),[]),{ref:t,isComponentVisible:l,setIsComponentVisible:s}}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=i.forwardRef(({positionDropdown:o,dropdownLists:l,isComponentVisible:s,searchAble:t,hideSearch:p,onSearch:d,value:D,handleChangeValue:P,multiSelect:E,searchValue:C,highlightedIndex:k,footer:W,groupLabel:F,onSelectAll:m},G)=>{const j=i.useRef([]);i.useEffect(()=>{var a;k>=0&&j.current[k]&&((a=j.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]);const T=t&&!p?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:a=>{d&&d(a.target.value)},value:C,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:G,children:[o!=="top"&&T,n.jsxs("div",{className:`sa-input-dropdown-item-container ${E?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),E&&m&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),m()},children:"Select all"})]}),l.map((a,S)=>{const $=!!(D!=null&&D.find(A=>A.value===a.value)),w=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",$?"active":"",S===k?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:A=>{j.current[S]=A},onClick:()=>P(a.label,a.value),children:[E&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:$&&n.jsx(ln,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:i.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})]})]},S)})]}),o==="top"&&T,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:W})]}):null})}),cn=({children:o,handleChangePosition:l,enabled:s=!0})=>(i.useEffect(()=>{if(s)return window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("scroll",l,!0)}},[s,l]),n.jsx("div",{children:o})),_="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(_)){const l=document.createElement("style");l.id=_,l.textContent=o,document.head.appendChild(l)}})(sn);const wn=({dropdownLists:o,onChange:l,defaultValue:s,value:t,size:p="sm",multiSelect:d,searchAble:D,iconLeft:P,placeholder:E,onSearch:C,error:k,onBlur:W,onFocus:F,disable:m,searchValue:G,variant:j="outline",footer:T,groupLabel:a,onSelectAll:S,fullWidth:$=!0,triggerInput:w=!1,clearOnSelect:A=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:z,helperText:B,errorText:h})=>{const J=["sa-select-field",`sa-select-field-size-${p}`,$?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),y=t!==void 0,Z=i.useRef(),vn=k||!!h,[c,L]=i.useState(y?t||[]:s||[]),[kn,on]=i.useState(""),[v,Q]=i.useState(-1),[mn,q]=i.useState(()=>{var e,r;return!d&&(t!=null&&t.length||s!=null&&s.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((r=s==null?void 0:s[0])==null?void 0:r.label)??"":""}),b=i.useRef(null),{isComponentVisible:f,ref:X,setIsComponentVisible:N}=dn(!1),O=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const r=[];y||L(r),l(r),w&&q(""),U==null||U()},Nn=()=>{O&&N(e=>!e)},H=(e,r)=>{if(d){if(c==null?void 0:c.find(g=>g.value===r)){const g=c.filter(Bn=>Bn.value!==r);y||L(g),l(g)}else{const g=[...c,{label:e,value:r}];y||L(g),l(g)}w&&q("")}else{const u=[{label:e,value:r}];y||L(u),l(u),w&&q(A?"":e),N(!1)}};i.useEffect(()=>{y&&L(t||[])},[t]),i.useEffect(()=>{y||JSON.stringify(Z.current)===JSON.stringify(s)||(Z.current=s,L(Z.current||[]))},[s]);const En=()=>c.length?d?c==null?void 0:c.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(R,{onClick:u=>{u.stopPropagation(),H(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:E}),I=()=>{if(X.current&&b.current){const e=window.innerHeight,r=X.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`,on("top")):(b.current.style.top=`${r.top+r.height+4}px`,on("bottom"))}};i.useEffect(()=>(window.addEventListener("resize",I),()=>{window.removeEventListener("resize",I)}),[]),i.useEffect(()=>{I()},[f]),i.useEffect(()=>{if(!f||!b.current)return;const e=new ResizeObserver(()=>{I()});return e.observe(b.current),()=>e.disconnect()},[f]),i.useEffect(()=>{f||Q(-1)},[f]);const an=e=>{if(O){if(!f){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),N(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=V(o,v,1);r!==-1&&Q(r);break}case"ArrowUp":{e.preventDefault();const r=V(o,v,-1);r!==-1&&Q(r);break}case"Enter":{e.preventDefault(),v>=0&&o[v]&&!o[v].disable&&H(o[v].label,o[v].value);break}case"Escape":N(!1);break}}},M=p==="lg"||p==="xl"?20:p==="xs"?14:16,Cn=gn&&!m?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:[d&&c.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(R,{onClick:u=>{u.stopPropagation(),H(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const r=e.target.value;q(r),C==null||C(r),!f&&O&&N(!0)},onFocus:()=>{!m&&O&&N(!0)},onBlur:()=>{d||setTimeout(()=>N(!1),150)},onKeyDown:an,placeholder:c.length===0||d?E:void 0,disabled:m})]}):null,Y=n.jsx(cn,{handleChangePosition:I,enabled:f,children:n.jsxs("div",{className:["sa-input-dropdown-container",j,`sa-input-dropdown-size-${p}`,w?"trigger-input":"",f?"active":"",vn?"error":"",m?"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:[P?i.cloneElement(P,{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:f?n.jsx(un,{width:M}):n.jsx(hn,{width:M})})]}),O&&n.jsx(pn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:f,positionDropdown:kn,searchAble:!!D,hideSearch:w,value:c,onSearch:C,ref:b,multiSelect:d,searchValue:G,highlightedIndex:v,footer:T,groupLabel:a,onSelectAll:S})]})});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:"*"})]}),z&&n.jsx("p",{className:"sa-select-field-helper-top",children:z})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),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:"*"})]}),z&&n.jsx("p",{className:"sa-select-field-helper-top",children:z}),Y,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:J,children:[z&&n.jsx("p",{className:"sa-select-field-helper-top",children:z}),Y,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},V=(o,l,s)=>{const t=o.length;let p=l+s;for(;p>=0&&p<t;){if(!o[p].disable)return p;p+=s}if(s===1){for(let d=0;d<t;d++)if(!o[d].disable)return d}else for(let d=t-1;d>=0;d--)if(!o[d].disable)return d;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"})});x.Dropdown=wn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
561
|
+
`;function ln(o){const[l,s]=d.useState(o),i=d.useRef(null),p=t=>{i.current&&!i.current.contains(t.target)&&s(!1)};return d.useEffect(()=>(document.addEventListener("click",p,!0),()=>{document.removeEventListener("click",p,!0)}),[]),{ref:i,isComponentVisible:l,setIsComponentVisible:s}}const pn=({...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"})]}),cn=({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"})}),wn=d.forwardRef(({positionDropdown:o,dropdownLists:l,isComponentVisible:s,searchAble:i,hideSearch:p,onSearch:t,value:j,handleChangeValue:F,multiSelect:z,searchValue:m,highlightedIndex:k,footer:T,groupLabel:$,onSelectAll:y},J)=>{const O=d.useRef([]),B=m!==void 0,[K,q]=d.useState(""),X=B?m:K;d.useEffect(()=>{var a;k>=0&&O.current[k]&&((a=O.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]),d.useEffect(()=>{!s&&!B&&q("")},[s,B]);const w=i&&!p?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(pn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{B||q(a.target.value),t&&t(a.target.value)},value:X,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:J,children:[w,n.jsxs("div",{className:`sa-input-dropdown-item-container ${z?"multi":""}`,children:[$&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:$}),z&&y&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),y()},children:"Select all"})]}),l.map((a,A)=>{const H=!!(j!=null&&j.find(N=>N.value===a.value)),I=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",I?"has-description":"",H?"active":"",A===k?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:N=>{O.current[A]=N},onClick:()=>F(a.label,a.value),children:[z&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:H&&n.jsx(cn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:d.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)})]}),T&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:T})]}):null})}),fn=({children:o,handleChangePosition:l,enabled:s=!0})=>(d.useEffect(()=>{if(s)return window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("scroll",l,!0)}},[s,l]),n.jsx("div",{children:o})),R="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(R)){const l=document.createElement("style");l.id=R,l.textContent=o,document.head.appendChild(l)}})(tn);const hn=({dropdownLists:o,onChange:l,defaultValue:s,value:i,size:p="sm",multiSelect:t,searchAble:j,iconLeft:F,placeholder:z,onSearch:m,error:k,onBlur:T,onFocus:$,disable:y,searchValue:J,variant:O="outline",footer:B,groupLabel:K,onSelectAll:q,fullWidth:X=!0,triggerInput:w=!1,clearOnSelect:a=!1,hideChevronIcon:A=!1,clearable:H=!1,onClear:I,label:N,labelPosition:xn="outside-top",required:on,optional:rn,description:L,helperText:D,errorText:h})=>{const Z=["sa-select-field",`sa-select-field-size-${p}`,X?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=i!==void 0,Q=d.useRef(),vn=k||!!h,[c,S]=d.useState(E?i||[]:s||[]),[mn,an]=d.useState(""),[v,Y]=d.useState(-1),[kn,G]=d.useState(()=>{var e,r;return!t&&(i!=null&&i.length||s!=null&&s.length)?((e=i==null?void 0:i[0])==null?void 0:e.label)??((r=s==null?void 0:s[0])==null?void 0:r.label)??"":""}),b=d.useRef(null),{isComponentVisible:f,ref:_,setIsComponentVisible:C}=ln(!1),M=o!==void 0,sn=c.length>0,yn=e=>{e.stopPropagation();const r=[];E||S(r),l(r),w&&G(""),I==null||I()},Nn=()=>{M&&C(e=>!e)},U=(e,r)=>{if(t){if(c==null?void 0:c.find(g=>g.value===r)){const g=c.filter(Bn=>Bn.value!==r);E||S(g),l(g)}else{const g=[...c,{label:e,value:r}];E||S(g),l(g)}w&&G("")}else{const u=[{label:e,value:r}];E||S(u),l(u),w&&G(a?"":e),C(!1)}};d.useEffect(()=>{E&&S(i||[])},[i]),d.useEffect(()=>{E||JSON.stringify(Q.current)===JSON.stringify(s)||(Q.current=s,S(Q.current||[]))},[s]);const En=()=>c.length?t?c==null?void 0:c.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(en,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:z}),P=()=>{if(_.current&&b.current){const e=window.innerHeight,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`,an("top")):(b.current.style.top=`${r.top+r.height+4}px`,an("bottom"))}};d.useEffect(()=>(window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P)}),[]),d.useEffect(()=>{P()},[f]),d.useEffect(()=>{if(!f||!b.current)return;const e=new ResizeObserver(()=>{P()});return e.observe(b.current),()=>e.disconnect()},[f]),d.useEffect(()=>{f||Y(-1)},[f]);const dn=e=>{if(M){if(!f){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=nn(o,v,1);r!==-1&&Y(r);break}case"ArrowUp":{e.preventDefault();const r=nn(o,v,-1);r!==-1&&Y(r);break}case"Enter":{e.preventDefault(),v>=0&&o[v]&&!o[v].disable&&U(o[v].label,o[v].value);break}case"Escape":C(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,Cn=H&&!y?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${sn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!sn,tabIndex:-1,onClick:yn,onMouseDown:e=>e.preventDefault(),children:n.jsx(un,{width:W,height:W})}):null,zn=w?n.jsxs(n.Fragment,{children:[t&&c.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(en,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:kn,onChange:e=>{const r=e.target.value;G(r),m==null||m(r),!f&&M&&C(!0)},onFocus:()=>{!y&&M&&C(!0)},onBlur:()=>{t||setTimeout(()=>C(!1),150)},onKeyDown:dn,placeholder:c.length===0||t?z:void 0,disabled:y})]}):null,V=n.jsx(fn,{handleChangePosition:P,enabled:f,children:n.jsxs("div",{className:["sa-input-dropdown-container",O,`sa-input-dropdown-size-${p}`,w?"trigger-input":"",f?"active":"",vn?"error":"",y?"disable":""].filter(Boolean).join(" "),ref:_,onClick:w?void 0:Nn,onKeyDown:w?void 0:dn,tabIndex:w?void 0:0,onBlur:w?void 0:T,onFocus:w?void 0:$,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[F?d.cloneElement(F,{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,!A&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:f?n.jsx(gn,{width:W}):n.jsx(bn,{width:W})})]}),M&&n.jsx(wn,{dropdownLists:o,handleChangeValue:U,isComponentVisible:f,positionDropdown:mn,searchAble:!!j,hideSearch:w,value:c,onSearch:m,ref:b,multiSelect:t,searchValue:J,highlightedIndex:v,footer:B,groupLabel:K,onSelectAll:q})]})});return N?xn==="outside-left"?n.jsxs("div",{className:`${Z} 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:N}),rn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),on&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[V,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:Z,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:N}),rn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),on&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L}),V,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:Z,children:[L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L}),V,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},nn=(o,l,s)=>{const i=o.length;let p=l+s;for(;p>=0&&p<i;){if(!o[p].disable)return p;p+=s}if(s===1){for(let t=0;t<i;t++)if(!o[t].disable)return t}else for(let t=i-1;t>=0;t--)if(!o[t].disable)return t;return-1},un=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"})]}),en=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"})}),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",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"})}),gn=({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"})});x.Dropdown=hn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|