@starasia/dropdown 5.5.6 → 5.6.0
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 +245 -217
- package/dist/dropdown.umd.js +20 -2
- package/dist/interface.d.ts +12 -0
- package/package.json +1 -1
package/dist/DropdownList.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface IProps {
|
|
|
18
18
|
footer?: React.ReactNode;
|
|
19
19
|
groupLabel?: string;
|
|
20
20
|
onSelectAll?: () => void;
|
|
21
|
+
emptyState?: React.ReactNode;
|
|
21
22
|
}
|
|
22
23
|
declare const DropdownList: React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLDivElement>>;
|
|
23
24
|
export default DropdownList;
|
package/dist/dropdown.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsxs as d, jsx as n, Fragment as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsxs as d, jsx as n, Fragment as rn } from "react/jsx-runtime";
|
|
2
|
+
import hn, { useState as L, useRef as J, useEffect as x, forwardRef as Nn } from "react";
|
|
3
|
+
const Cn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
|
|
4
4
|
* {
|
|
5
5
|
margin: 0;
|
|
6
6
|
padding: 0;
|
|
@@ -323,6 +323,24 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
323
323
|
gap: 4px;
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
/* === EMPTY STATE ===
|
|
327
|
+
Rendered inside the list container, so an empty panel is just the search bar
|
|
328
|
+
plus this message — no leftover padding strip, no footer border to collide
|
|
329
|
+
with. */
|
|
330
|
+
.sa-input-dropdown-empty {
|
|
331
|
+
padding: 20px 12px;
|
|
332
|
+
text-align: center;
|
|
333
|
+
font-size: 12px;
|
|
334
|
+
font-weight: 400;
|
|
335
|
+
line-height: 1.5;
|
|
336
|
+
color: var(--sa-dropdown-placeholder-subtle);
|
|
337
|
+
overflow-wrap: anywhere;
|
|
338
|
+
}
|
|
339
|
+
.sa-input-dropdown-empty-query {
|
|
340
|
+
color: var(--sa-dropdown-text-primary);
|
|
341
|
+
font-weight: 500;
|
|
342
|
+
}
|
|
343
|
+
|
|
326
344
|
/* === SECTION HEADER === */
|
|
327
345
|
.sa-input-dropdown-section-header {
|
|
328
346
|
display: flex;
|
|
@@ -561,15 +579,15 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
|
|
|
561
579
|
}
|
|
562
580
|
|
|
563
581
|
`;
|
|
564
|
-
function
|
|
565
|
-
const [
|
|
566
|
-
|
|
582
|
+
function En(o) {
|
|
583
|
+
const [t, i] = L(o), l = J(null), p = (s) => {
|
|
584
|
+
l.current && !l.current.contains(s.target) && i(!1);
|
|
567
585
|
};
|
|
568
|
-
return
|
|
586
|
+
return x(() => (document.addEventListener("click", p, !0), () => {
|
|
569
587
|
document.removeEventListener("click", p, !0);
|
|
570
|
-
}), []), { ref:
|
|
588
|
+
}), []), { ref: l, isComponentVisible: t, setIsComponentVisible: i };
|
|
571
589
|
}
|
|
572
|
-
const
|
|
590
|
+
const zn = ({ ...o }) => /* @__PURE__ */ d(
|
|
573
591
|
"svg",
|
|
574
592
|
{
|
|
575
593
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -601,7 +619,7 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
601
619
|
)
|
|
602
620
|
]
|
|
603
621
|
}
|
|
604
|
-
),
|
|
622
|
+
), Rn = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
605
623
|
"svg",
|
|
606
624
|
{
|
|
607
625
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -620,45 +638,44 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
620
638
|
}
|
|
621
639
|
)
|
|
622
640
|
}
|
|
623
|
-
),
|
|
641
|
+
), Bn = Nn(
|
|
624
642
|
({
|
|
625
643
|
positionDropdown: o,
|
|
626
|
-
dropdownLists:
|
|
627
|
-
isComponentVisible:
|
|
628
|
-
searchAble:
|
|
644
|
+
dropdownLists: t,
|
|
645
|
+
isComponentVisible: i,
|
|
646
|
+
searchAble: l,
|
|
629
647
|
hideSearch: p,
|
|
630
|
-
onSearch:
|
|
631
|
-
value:
|
|
632
|
-
handleChangeValue:
|
|
633
|
-
multiSelect:
|
|
648
|
+
onSearch: s,
|
|
649
|
+
value: j,
|
|
650
|
+
handleChangeValue: T,
|
|
651
|
+
multiSelect: E,
|
|
634
652
|
searchValue: m,
|
|
635
653
|
highlightedIndex: k,
|
|
636
|
-
footer:
|
|
637
|
-
groupLabel:
|
|
638
|
-
onSelectAll: y
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
654
|
+
footer: $,
|
|
655
|
+
groupLabel: q,
|
|
656
|
+
onSelectAll: y,
|
|
657
|
+
emptyState: K
|
|
658
|
+
}, X) => {
|
|
659
|
+
const A = J([]), H = m !== void 0, [Y, Z] = L(""), M = H ? m : Y, c = !t || t.length === 0;
|
|
660
|
+
x(() => {
|
|
642
661
|
var a;
|
|
643
|
-
k >= 0 &&
|
|
644
|
-
}, [k])
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const w = s && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
648
|
-
/* @__PURE__ */ n(En, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
662
|
+
k >= 0 && A.current[k] && ((a = A.current[k]) == null || a.scrollIntoView({ block: "nearest" }));
|
|
663
|
+
}, [k]);
|
|
664
|
+
const Q = l && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
|
|
665
|
+
/* @__PURE__ */ n(zn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
|
|
649
666
|
/* @__PURE__ */ n(
|
|
650
667
|
"input",
|
|
651
668
|
{
|
|
652
669
|
onChange: (a) => {
|
|
653
|
-
|
|
670
|
+
H || Z(a.target.value), s && s(a.target.value);
|
|
654
671
|
},
|
|
655
|
-
value:
|
|
672
|
+
value: M,
|
|
656
673
|
autoFocus: !0,
|
|
657
674
|
placeholder: "Search..."
|
|
658
675
|
}
|
|
659
676
|
)
|
|
660
677
|
] }) : null;
|
|
661
|
-
return /* @__PURE__ */ n(
|
|
678
|
+
return /* @__PURE__ */ n(rn, { children: i ? /* @__PURE__ */ d(
|
|
662
679
|
"div",
|
|
663
680
|
{
|
|
664
681
|
className: [
|
|
@@ -671,17 +688,26 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
671
688
|
o === "top" ? "search-bottom" : ""
|
|
672
689
|
].filter(Boolean).join(" "),
|
|
673
690
|
onClick: (a) => a.stopPropagation(),
|
|
674
|
-
ref:
|
|
691
|
+
ref: X,
|
|
675
692
|
children: [
|
|
676
|
-
|
|
693
|
+
Q,
|
|
677
694
|
/* @__PURE__ */ d(
|
|
678
695
|
"div",
|
|
679
696
|
{
|
|
680
|
-
className: `sa-input-dropdown-item-container ${
|
|
697
|
+
className: `sa-input-dropdown-item-container ${E ? "multi" : ""}`,
|
|
681
698
|
children: [
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
699
|
+
c && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: K ?? (M ? /* @__PURE__ */ d(rn, { children: [
|
|
700
|
+
"No results for",
|
|
701
|
+
" ",
|
|
702
|
+
/* @__PURE__ */ d("span", { className: "sa-input-dropdown-empty-query", children: [
|
|
703
|
+
"“",
|
|
704
|
+
M,
|
|
705
|
+
"”"
|
|
706
|
+
] })
|
|
707
|
+
] }) : "No data available") }),
|
|
708
|
+
q && !c && /* @__PURE__ */ d("div", { className: "sa-input-dropdown-section-header", children: [
|
|
709
|
+
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: q }),
|
|
710
|
+
E && y && /* @__PURE__ */ n(
|
|
685
711
|
"button",
|
|
686
712
|
{
|
|
687
713
|
className: "sa-input-dropdown-section-select-all",
|
|
@@ -692,25 +718,25 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
692
718
|
}
|
|
693
719
|
)
|
|
694
720
|
] }),
|
|
695
|
-
|
|
696
|
-
const
|
|
721
|
+
t == null ? void 0 : t.map((a, O) => {
|
|
722
|
+
const z = !!(j != null && j.find((S) => S.value === a.value)), P = !!a.description;
|
|
697
723
|
return /* @__PURE__ */ d(
|
|
698
724
|
"div",
|
|
699
725
|
{
|
|
700
726
|
className: [
|
|
701
727
|
"sa-input-dropdown-item",
|
|
702
|
-
|
|
703
|
-
|
|
728
|
+
P ? "has-description" : "",
|
|
729
|
+
z ? "active" : "",
|
|
704
730
|
O === k ? "highlight" : "",
|
|
705
731
|
a.disable ? "sa-input-dropdown-item-disable" : ""
|
|
706
732
|
].filter(Boolean).join(" "),
|
|
707
|
-
ref: (
|
|
708
|
-
|
|
733
|
+
ref: (S) => {
|
|
734
|
+
A.current[O] = S;
|
|
709
735
|
},
|
|
710
|
-
onClick: () =>
|
|
736
|
+
onClick: () => T(a.label, a.value),
|
|
711
737
|
children: [
|
|
712
|
-
|
|
713
|
-
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children:
|
|
738
|
+
E && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: z && /* @__PURE__ */ n(Rn, { width: 16 }) }),
|
|
739
|
+
a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: hn.cloneElement(a.icon, { width: 16 }) }),
|
|
714
740
|
/* @__PURE__ */ d("div", { style: { minWidth: 0, flex: 1 }, children: [
|
|
715
741
|
/* @__PURE__ */ n(
|
|
716
742
|
"p",
|
|
@@ -741,146 +767,147 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
|
|
|
741
767
|
]
|
|
742
768
|
}
|
|
743
769
|
),
|
|
744
|
-
|
|
770
|
+
$ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: $ })
|
|
745
771
|
]
|
|
746
772
|
}
|
|
747
773
|
) : null });
|
|
748
774
|
}
|
|
749
|
-
),
|
|
775
|
+
), Dn = ({
|
|
750
776
|
children: o,
|
|
751
|
-
handleChangePosition:
|
|
752
|
-
enabled:
|
|
753
|
-
}) => (
|
|
754
|
-
if (
|
|
755
|
-
return window.addEventListener("scroll",
|
|
756
|
-
window.removeEventListener("scroll",
|
|
777
|
+
handleChangePosition: t,
|
|
778
|
+
enabled: i = !0
|
|
779
|
+
}) => (x(() => {
|
|
780
|
+
if (i)
|
|
781
|
+
return window.addEventListener("scroll", t, !0), () => {
|
|
782
|
+
window.removeEventListener("scroll", t, !0);
|
|
757
783
|
};
|
|
758
|
-
}, [
|
|
759
|
-
if (!(typeof document > "u") && !document.getElementById(
|
|
760
|
-
const
|
|
761
|
-
|
|
784
|
+
}, [i, t]), /* @__PURE__ */ n("div", { children: o })), cn = "sa-input-dropdown-styles", Ln = (o) => {
|
|
785
|
+
if (!(typeof document > "u") && !document.getElementById(cn)) {
|
|
786
|
+
const t = document.createElement("style");
|
|
787
|
+
t.id = cn, t.textContent = o, document.head.appendChild(t);
|
|
762
788
|
}
|
|
763
789
|
};
|
|
764
|
-
Ln(
|
|
765
|
-
const
|
|
790
|
+
Ln(Cn);
|
|
791
|
+
const Sn = ({
|
|
766
792
|
dropdownLists: o,
|
|
767
|
-
onChange:
|
|
768
|
-
defaultValue:
|
|
769
|
-
value:
|
|
793
|
+
onChange: t,
|
|
794
|
+
defaultValue: i,
|
|
795
|
+
value: l,
|
|
770
796
|
size: p = "sm",
|
|
771
|
-
multiSelect:
|
|
772
|
-
searchAble:
|
|
773
|
-
iconLeft:
|
|
774
|
-
placeholder:
|
|
797
|
+
multiSelect: s,
|
|
798
|
+
searchAble: j,
|
|
799
|
+
iconLeft: T,
|
|
800
|
+
placeholder: E,
|
|
775
801
|
onSearch: m,
|
|
776
802
|
error: k,
|
|
777
|
-
onBlur:
|
|
778
|
-
onFocus:
|
|
803
|
+
onBlur: $,
|
|
804
|
+
onFocus: q,
|
|
779
805
|
disable: y,
|
|
780
806
|
searchValue: K,
|
|
781
|
-
variant:
|
|
782
|
-
footer:
|
|
783
|
-
groupLabel:
|
|
784
|
-
onSelectAll:
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
807
|
+
variant: X = "outline",
|
|
808
|
+
footer: A,
|
|
809
|
+
groupLabel: H,
|
|
810
|
+
onSelectAll: Y,
|
|
811
|
+
emptyState: Z,
|
|
812
|
+
fullWidth: M = !0,
|
|
813
|
+
triggerInput: c = !1,
|
|
814
|
+
clearOnSelect: Q = !1,
|
|
815
|
+
hideChevronIcon: a = !1,
|
|
816
|
+
clearable: O = !1,
|
|
817
|
+
onClear: z,
|
|
791
818
|
/* field wrapper */
|
|
792
|
-
label:
|
|
793
|
-
labelPosition:
|
|
794
|
-
required:
|
|
795
|
-
optional:
|
|
796
|
-
description:
|
|
797
|
-
helperText:
|
|
819
|
+
label: P,
|
|
820
|
+
labelPosition: S = "outside-top",
|
|
821
|
+
required: an,
|
|
822
|
+
optional: tn,
|
|
823
|
+
description: R,
|
|
824
|
+
helperText: B,
|
|
798
825
|
errorText: h
|
|
799
826
|
}) => {
|
|
800
|
-
const
|
|
827
|
+
const _ = [
|
|
801
828
|
"sa-select-field",
|
|
802
829
|
`sa-select-field-size-${p}`,
|
|
803
|
-
|
|
804
|
-
].filter(Boolean).join(" "),
|
|
805
|
-
|
|
806
|
-
), [
|
|
830
|
+
M ? "sa-select-field-fullwidth" : ""
|
|
831
|
+
].filter(Boolean).join(" "), N = l !== void 0, V = J(), fn = k || !!h, [u, D] = L(
|
|
832
|
+
N ? l || [] : i || []
|
|
833
|
+
), [bn, sn] = L(""), [v, nn] = L(-1), [dn, G] = L(
|
|
807
834
|
() => {
|
|
808
835
|
var e, r;
|
|
809
|
-
return !
|
|
836
|
+
return !s && (l != null && l.length || i != null && i.length) ? ((e = l == null ? void 0 : l[0]) == null ? void 0 : e.label) ?? ((r = i == null ? void 0 : i[0]) == null ? void 0 : r.label) ?? "" : "";
|
|
810
837
|
}
|
|
811
|
-
),
|
|
838
|
+
), b = J(null), { isComponentVisible: w, ref: en, setIsComponentVisible: C } = En(!1), I = o !== void 0, ln = u.length > 0, gn = (e) => {
|
|
812
839
|
e.stopPropagation();
|
|
813
840
|
const r = [];
|
|
814
|
-
|
|
815
|
-
},
|
|
816
|
-
|
|
841
|
+
N || D(r), t(r), c && G(""), z == null || z();
|
|
842
|
+
}, xn = () => {
|
|
843
|
+
I && C((e) => !e);
|
|
817
844
|
}, U = (e, r) => {
|
|
818
|
-
if (
|
|
819
|
-
if (
|
|
820
|
-
const
|
|
821
|
-
|
|
845
|
+
if (s) {
|
|
846
|
+
if (u == null ? void 0 : u.find((g) => g.value === r)) {
|
|
847
|
+
const g = u.filter((yn) => yn.value !== r);
|
|
848
|
+
N || D(g), t(g);
|
|
822
849
|
} else {
|
|
823
|
-
const
|
|
824
|
-
|
|
850
|
+
const g = [...u, { label: e, value: r }];
|
|
851
|
+
N || D(g), t(g);
|
|
825
852
|
}
|
|
826
|
-
|
|
853
|
+
c && G("");
|
|
827
854
|
} else {
|
|
828
855
|
const f = [{ label: e, value: r }];
|
|
829
|
-
|
|
856
|
+
N || D(f), t(f), c && G(Q ? "" : e), C(!1);
|
|
830
857
|
}
|
|
831
858
|
};
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}, [
|
|
835
|
-
|
|
836
|
-
}, [
|
|
837
|
-
const
|
|
859
|
+
x(() => {
|
|
860
|
+
N && D(l || []);
|
|
861
|
+
}, [l]), x(() => {
|
|
862
|
+
N || JSON.stringify(V.current) === JSON.stringify(i) || (V.current = i, D(V.current || []));
|
|
863
|
+
}, [i]);
|
|
864
|
+
const vn = () => u.length ? s ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
838
865
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
839
866
|
/* @__PURE__ */ n(
|
|
840
|
-
|
|
867
|
+
wn,
|
|
841
868
|
{
|
|
842
869
|
onClick: (f) => {
|
|
843
870
|
f.stopPropagation(), U(e.label, e.value);
|
|
844
871
|
}
|
|
845
872
|
}
|
|
846
873
|
)
|
|
847
|
-
] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children:
|
|
848
|
-
if (
|
|
849
|
-
const e = window.innerHeight, r =
|
|
850
|
-
|
|
874
|
+
] }, 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: E }), W = () => {
|
|
875
|
+
if (en.current && b.current) {
|
|
876
|
+
const e = window.innerHeight, r = en.current.getBoundingClientRect(), f = b.current.getBoundingClientRect(), g = r.bottom + f.height;
|
|
877
|
+
b.current.style.left = `${r.left}px`, b.current.style.width = `${r.width}px`, g >= e - 10 ? (b.current.style.top = `${r.top - f.height - 5}px`, sn("top")) : (b.current.style.top = `${r.top + r.height + 4}px`, sn("bottom"));
|
|
851
878
|
}
|
|
852
879
|
};
|
|
853
|
-
|
|
854
|
-
window.removeEventListener("resize",
|
|
855
|
-
}), []),
|
|
856
|
-
|
|
857
|
-
}, [
|
|
858
|
-
if (!
|
|
880
|
+
x(() => (window.addEventListener("resize", W), () => {
|
|
881
|
+
window.removeEventListener("resize", W);
|
|
882
|
+
}), []), x(() => {
|
|
883
|
+
W();
|
|
884
|
+
}, [w]), x(() => {
|
|
885
|
+
if (!w || !b.current)
|
|
859
886
|
return;
|
|
860
887
|
const e = new ResizeObserver(() => {
|
|
861
|
-
|
|
888
|
+
W();
|
|
862
889
|
});
|
|
863
|
-
return e.observe(
|
|
864
|
-
}, [
|
|
865
|
-
|
|
866
|
-
}, [
|
|
867
|
-
const
|
|
868
|
-
if (
|
|
869
|
-
if (!
|
|
870
|
-
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(),
|
|
890
|
+
return e.observe(b.current), () => e.disconnect();
|
|
891
|
+
}, [w]), x(() => {
|
|
892
|
+
w || nn(-1);
|
|
893
|
+
}, [w]);
|
|
894
|
+
const pn = (e) => {
|
|
895
|
+
if (I) {
|
|
896
|
+
if (!w) {
|
|
897
|
+
(e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
|
|
871
898
|
return;
|
|
872
899
|
}
|
|
873
900
|
switch (e.key) {
|
|
874
901
|
case "ArrowDown": {
|
|
875
902
|
e.preventDefault();
|
|
876
|
-
const r =
|
|
877
|
-
r !== -1 &&
|
|
903
|
+
const r = un(o, v, 1);
|
|
904
|
+
r !== -1 && nn(r);
|
|
878
905
|
break;
|
|
879
906
|
}
|
|
880
907
|
case "ArrowUp": {
|
|
881
908
|
e.preventDefault();
|
|
882
|
-
const r =
|
|
883
|
-
r !== -1 &&
|
|
909
|
+
const r = un(o, v, -1);
|
|
910
|
+
r !== -1 && nn(r);
|
|
884
911
|
break;
|
|
885
912
|
}
|
|
886
913
|
case "Enter": {
|
|
@@ -891,27 +918,27 @@ const Mn = ({
|
|
|
891
918
|
break;
|
|
892
919
|
}
|
|
893
920
|
case "Escape":
|
|
894
|
-
|
|
921
|
+
C(!1);
|
|
895
922
|
break;
|
|
896
923
|
}
|
|
897
924
|
}
|
|
898
|
-
},
|
|
925
|
+
}, F = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, mn = O && !y ? /* @__PURE__ */ n(
|
|
899
926
|
"button",
|
|
900
927
|
{
|
|
901
928
|
type: "button",
|
|
902
|
-
className: `sa-input-dropdown-clear${
|
|
929
|
+
className: `sa-input-dropdown-clear${ln ? "" : " sa-input-dropdown-clear-hidden"}`,
|
|
903
930
|
"aria-label": "Clear selection",
|
|
904
|
-
"aria-hidden": !
|
|
931
|
+
"aria-hidden": !ln,
|
|
905
932
|
tabIndex: -1,
|
|
906
|
-
onClick:
|
|
933
|
+
onClick: gn,
|
|
907
934
|
onMouseDown: (e) => e.preventDefault(),
|
|
908
|
-
children: /* @__PURE__ */ n(
|
|
935
|
+
children: /* @__PURE__ */ n(jn, { width: F, height: F })
|
|
909
936
|
}
|
|
910
|
-
) : null,
|
|
911
|
-
|
|
937
|
+
) : null, kn = c ? /* @__PURE__ */ d(rn, { children: [
|
|
938
|
+
s && u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
912
939
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
913
940
|
/* @__PURE__ */ n(
|
|
914
|
-
|
|
941
|
+
wn,
|
|
915
942
|
{
|
|
916
943
|
onClick: (f) => {
|
|
917
944
|
f.stopPropagation(), U(e.label, e.value);
|
|
@@ -923,73 +950,74 @@ const Mn = ({
|
|
|
923
950
|
"input",
|
|
924
951
|
{
|
|
925
952
|
className: "sa-input-dropdown-trigger-input",
|
|
926
|
-
value:
|
|
953
|
+
value: dn,
|
|
927
954
|
onChange: (e) => {
|
|
928
955
|
const r = e.target.value;
|
|
929
|
-
G(r), m == null || m(r), !
|
|
956
|
+
G(r), m == null || m(r), !w && I && C(!0);
|
|
930
957
|
},
|
|
931
958
|
onFocus: () => {
|
|
932
|
-
!y &&
|
|
959
|
+
!y && I && C(!0);
|
|
933
960
|
},
|
|
934
961
|
onBlur: () => {
|
|
935
|
-
|
|
962
|
+
s || setTimeout(() => C(!1), 150);
|
|
936
963
|
},
|
|
937
|
-
onKeyDown:
|
|
938
|
-
placeholder:
|
|
964
|
+
onKeyDown: pn,
|
|
965
|
+
placeholder: u.length === 0 || s ? E : void 0,
|
|
939
966
|
disabled: y
|
|
940
967
|
}
|
|
941
968
|
)
|
|
942
|
-
] }) : null,
|
|
943
|
-
|
|
969
|
+
] }) : null, on = /* @__PURE__ */ n(
|
|
970
|
+
Dn,
|
|
944
971
|
{
|
|
945
|
-
handleChangePosition:
|
|
946
|
-
enabled:
|
|
972
|
+
handleChangePosition: W,
|
|
973
|
+
enabled: w,
|
|
947
974
|
children: /* @__PURE__ */ d(
|
|
948
975
|
"div",
|
|
949
976
|
{
|
|
950
977
|
className: [
|
|
951
978
|
"sa-input-dropdown-container",
|
|
952
|
-
|
|
979
|
+
X,
|
|
953
980
|
`sa-input-dropdown-size-${p}`,
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
981
|
+
c ? "trigger-input" : "",
|
|
982
|
+
w ? "active" : "",
|
|
983
|
+
fn ? "error" : "",
|
|
957
984
|
y ? "disable" : ""
|
|
958
985
|
].filter(Boolean).join(" "),
|
|
959
|
-
ref:
|
|
960
|
-
onClick:
|
|
961
|
-
onKeyDown:
|
|
962
|
-
tabIndex:
|
|
963
|
-
onBlur:
|
|
964
|
-
onFocus:
|
|
986
|
+
ref: en,
|
|
987
|
+
onClick: c ? void 0 : xn,
|
|
988
|
+
onKeyDown: c ? void 0 : pn,
|
|
989
|
+
tabIndex: c ? void 0 : 0,
|
|
990
|
+
onBlur: c ? void 0 : $,
|
|
991
|
+
onFocus: c ? void 0 : q,
|
|
965
992
|
children: [
|
|
966
993
|
/* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
967
|
-
|
|
968
|
-
width:
|
|
994
|
+
T ? hn.cloneElement(T, {
|
|
995
|
+
width: F,
|
|
969
996
|
style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
|
|
970
997
|
}) : null,
|
|
971
|
-
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children:
|
|
972
|
-
|
|
973
|
-
!
|
|
998
|
+
/* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: c ? kn : vn() }),
|
|
999
|
+
mn,
|
|
1000
|
+
!a && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(Mn, { width: F }) : /* @__PURE__ */ n(An, { width: F }) })
|
|
974
1001
|
] }),
|
|
975
|
-
|
|
976
|
-
|
|
1002
|
+
I && /* @__PURE__ */ n(
|
|
1003
|
+
Bn,
|
|
977
1004
|
{
|
|
978
1005
|
dropdownLists: o,
|
|
979
1006
|
handleChangeValue: U,
|
|
980
|
-
isComponentVisible:
|
|
981
|
-
positionDropdown:
|
|
982
|
-
searchAble: !!
|
|
983
|
-
hideSearch:
|
|
984
|
-
value:
|
|
1007
|
+
isComponentVisible: w,
|
|
1008
|
+
positionDropdown: bn,
|
|
1009
|
+
searchAble: !!j,
|
|
1010
|
+
hideSearch: c,
|
|
1011
|
+
value: u,
|
|
985
1012
|
onSearch: m,
|
|
986
|
-
ref:
|
|
987
|
-
multiSelect:
|
|
988
|
-
searchValue: K,
|
|
1013
|
+
ref: b,
|
|
1014
|
+
multiSelect: s,
|
|
1015
|
+
searchValue: c ? dn : K,
|
|
989
1016
|
highlightedIndex: v,
|
|
990
|
-
footer:
|
|
991
|
-
groupLabel:
|
|
992
|
-
onSelectAll:
|
|
1017
|
+
footer: A,
|
|
1018
|
+
groupLabel: H,
|
|
1019
|
+
onSelectAll: Y,
|
|
1020
|
+
emptyState: Z
|
|
993
1021
|
}
|
|
994
1022
|
)
|
|
995
1023
|
]
|
|
@@ -997,57 +1025,57 @@ const Mn = ({
|
|
|
997
1025
|
)
|
|
998
1026
|
}
|
|
999
1027
|
);
|
|
1000
|
-
return
|
|
1028
|
+
return P ? S === "outside-left" ? /* @__PURE__ */ d("div", { className: `${_} sa-select-field-left`, children: [
|
|
1001
1029
|
/* @__PURE__ */ d("div", { className: "sa-select-field-left-label", children: [
|
|
1002
1030
|
/* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
|
|
1003
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
1004
|
-
|
|
1005
|
-
|
|
1031
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: P }),
|
|
1032
|
+
tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1033
|
+
an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
1006
1034
|
] }),
|
|
1007
|
-
|
|
1035
|
+
R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R })
|
|
1008
1036
|
] }),
|
|
1009
1037
|
/* @__PURE__ */ d("div", { className: "sa-select-field-input-wrap", children: [
|
|
1010
|
-
|
|
1011
|
-
|
|
1038
|
+
on,
|
|
1039
|
+
B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
|
|
1012
1040
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1013
1041
|
] })
|
|
1014
|
-
] }) : /* @__PURE__ */ d("div", { className:
|
|
1042
|
+
] }) : /* @__PURE__ */ d("div", { className: _, children: [
|
|
1015
1043
|
/* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
|
|
1016
|
-
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children:
|
|
1017
|
-
|
|
1018
|
-
|
|
1044
|
+
/* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: P }),
|
|
1045
|
+
tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
|
|
1046
|
+
an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
|
|
1019
1047
|
] }),
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1048
|
+
R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
|
|
1049
|
+
on,
|
|
1050
|
+
B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
|
|
1023
1051
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1024
|
-
] }) : /* @__PURE__ */ d("div", { className:
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1052
|
+
] }) : /* @__PURE__ */ d("div", { className: _, children: [
|
|
1053
|
+
R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
|
|
1054
|
+
on,
|
|
1055
|
+
B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
|
|
1028
1056
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1029
1057
|
] });
|
|
1030
|
-
},
|
|
1031
|
-
const
|
|
1032
|
-
let p =
|
|
1033
|
-
for (; p >= 0 && p <
|
|
1058
|
+
}, un = (o, t, i) => {
|
|
1059
|
+
const l = o.length;
|
|
1060
|
+
let p = t + i;
|
|
1061
|
+
for (; p >= 0 && p < l; ) {
|
|
1034
1062
|
if (!o[p].disable)
|
|
1035
1063
|
return p;
|
|
1036
|
-
p +=
|
|
1064
|
+
p += i;
|
|
1037
1065
|
}
|
|
1038
|
-
if (
|
|
1039
|
-
for (let
|
|
1040
|
-
if (!o[
|
|
1041
|
-
return
|
|
1066
|
+
if (i === 1) {
|
|
1067
|
+
for (let s = 0; s < l; s++)
|
|
1068
|
+
if (!o[s].disable)
|
|
1069
|
+
return s;
|
|
1042
1070
|
} else
|
|
1043
|
-
for (let
|
|
1044
|
-
if (!o[
|
|
1045
|
-
return
|
|
1071
|
+
for (let s = l - 1; s >= 0; s--)
|
|
1072
|
+
if (!o[s].disable)
|
|
1073
|
+
return s;
|
|
1046
1074
|
return -1;
|
|
1047
|
-
},
|
|
1075
|
+
}, jn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
|
|
1048
1076
|
/* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
1049
1077
|
/* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1050
|
-
] }),
|
|
1078
|
+
] }), wn = (o) => /* @__PURE__ */ n(
|
|
1051
1079
|
"svg",
|
|
1052
1080
|
{
|
|
1053
1081
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1068,7 +1096,7 @@ const Mn = ({
|
|
|
1068
1096
|
}
|
|
1069
1097
|
)
|
|
1070
1098
|
}
|
|
1071
|
-
),
|
|
1099
|
+
), An = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
1072
1100
|
"svg",
|
|
1073
1101
|
{
|
|
1074
1102
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1088,7 +1116,7 @@ const Mn = ({
|
|
|
1088
1116
|
}
|
|
1089
1117
|
)
|
|
1090
1118
|
}
|
|
1091
|
-
),
|
|
1119
|
+
), Mn = ({ width: o = 16 }) => /* @__PURE__ */ n(
|
|
1092
1120
|
"svg",
|
|
1093
1121
|
{
|
|
1094
1122
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -1110,5 +1138,5 @@ const Mn = ({
|
|
|
1110
1138
|
}
|
|
1111
1139
|
);
|
|
1112
1140
|
export {
|
|
1113
|
-
|
|
1141
|
+
Sn as Dropdown
|
|
1114
1142
|
};
|
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,s){"use strict";const cn=`@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;
|
|
@@ -321,6 +321,24 @@
|
|
|
321
321
|
gap: 4px;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
/* === EMPTY STATE ===
|
|
325
|
+
Rendered inside the list container, so an empty panel is just the search bar
|
|
326
|
+
plus this message — no leftover padding strip, no footer border to collide
|
|
327
|
+
with. */
|
|
328
|
+
.sa-input-dropdown-empty {
|
|
329
|
+
padding: 20px 12px;
|
|
330
|
+
text-align: center;
|
|
331
|
+
font-size: 12px;
|
|
332
|
+
font-weight: 400;
|
|
333
|
+
line-height: 1.5;
|
|
334
|
+
color: var(--sa-dropdown-placeholder-subtle);
|
|
335
|
+
overflow-wrap: anywhere;
|
|
336
|
+
}
|
|
337
|
+
.sa-input-dropdown-empty-query {
|
|
338
|
+
color: var(--sa-dropdown-text-primary);
|
|
339
|
+
font-weight: 500;
|
|
340
|
+
}
|
|
341
|
+
|
|
324
342
|
/* === SECTION HEADER === */
|
|
325
343
|
.sa-input-dropdown-section-header {
|
|
326
344
|
display: flex;
|
|
@@ -558,4 +576,4 @@
|
|
|
558
576
|
display: none;
|
|
559
577
|
}
|
|
560
578
|
|
|
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"})});
|
|
579
|
+
`;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(""),A=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:A,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??(A?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",A,"”"]})]}):"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,M)=>{const z=!!(L!=null&&L.find(P=>P.value===a.value)),O=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",O?"has-description":"",z?"active":"",M===y?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:P=>{j.current[M]=P},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})]})]},M)})]}),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:A=!0,triggerInput:c=!1,clearOnSelect:Z=!1,hideChevronIcon:a=!1,clearable:M=!1,onClear:z,label:O,labelPosition:P="outside-top",required:an,optional:sn,description:B,helperText:D,errorText:f})=>{const Q=["sa-select-field",`sa-select-field-size-${p}`,A?"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(""),[v,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),I=o!==void 0,ln=w.length>0,Nn=e=>{e.stopPropagation();const r=[];N||S(r),t(r),c&&G(""),z==null||z()},En=()=>{I&&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}),F=()=>{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",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[h]),s.useEffect(()=>{if(!h||!b.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(b.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||V(-1)},[h]);const pn=e=>{if(I){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=on(o,v,1);r!==-1&&V(r);break}case"ArrowUp":{e.preventDefault();const r=on(o,v,-1);r!==-1&&V(r);break}case"Enter":{e.preventDefault(),v>=0&&o[v]&&!o[v].disable&&U(o[v].label,o[v].value);break}case"Escape":E(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,zn=M&&!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(xn,{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&&I&&E(!0)},onFocus:()=>{!k&&I&&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:F,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(vn,{width:W})})]}),I&&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:v,footer:j,groupLabel:H,onSelectAll:X,emptyState:Y})]})});return O?P==="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:O}),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:O}),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},xn=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"})}),vn=({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"})});x.Dropdown=gn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
package/dist/interface.d.ts
CHANGED
|
@@ -45,6 +45,18 @@ export interface IDropdown {
|
|
|
45
45
|
footer?: React.ReactNode;
|
|
46
46
|
groupLabel?: string;
|
|
47
47
|
onSelectAll?: () => void;
|
|
48
|
+
/**
|
|
49
|
+
* Rendered inside the panel when `dropdownLists` is empty. Any node — text,
|
|
50
|
+
* an illustration, a "create new" button.
|
|
51
|
+
*
|
|
52
|
+
* The built-in default only covers the two cases the component can actually
|
|
53
|
+
* tell apart: a search that matched nothing, and a genuinely empty list.
|
|
54
|
+
* It cannot see whether a request is still in flight, whether one failed, or
|
|
55
|
+
* whether a lazy dropdown has not fetched yet — those all look identical
|
|
56
|
+
* from in here. Pass this prop to speak for the states only you know about;
|
|
57
|
+
* leave it `undefined` for the rest and the default takes over.
|
|
58
|
+
*/
|
|
59
|
+
emptyState?: React.ReactNode;
|
|
48
60
|
fullWidth?: boolean;
|
|
49
61
|
triggerInput?: boolean;
|
|
50
62
|
clearOnSelect?: boolean;
|