@starasia/dropdown 6.1.3 → 6.1.4
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 +115 -99
- package/dist/dropdown.umd.js +20 -7
- package/package.json +1 -1
package/dist/dropdown.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as l, jsx as n, Fragment as tn } from "react/jsx-runtime";
|
|
2
|
-
import sn, { useState as
|
|
2
|
+
import sn, { useState as L, useRef as J, useEffect as x, forwardRef as En } from "react";
|
|
3
3
|
const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
4
4
|
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
5
5
|
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
@@ -174,18 +174,19 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
|
|
|
174
174
|
display: flex;
|
|
175
175
|
flex-direction: row;
|
|
176
176
|
gap: 8px;
|
|
177
|
-
|
|
177
|
+
/* Single-line (combobox input, placeholder, single value) → center supaya
|
|
178
|
+
teks & chevron sejajar persis di tengah field. Kasus multiSelect yang
|
|
179
|
+
chip-nya bisa membungkus di-override ke flex-start di bawah. */
|
|
180
|
+
align-items: center;
|
|
178
181
|
justify-content: space-between;
|
|
179
182
|
width: 100%;
|
|
180
183
|
min-width: 0;
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
/* Chevron + clear button —
|
|
184
|
-
centered when single-line, and snap to top-right when content wraps */
|
|
186
|
+
/* Chevron + clear button — center di single-line (sejajar teks input). */
|
|
185
187
|
.sa-input-dropdown-chevron,
|
|
186
188
|
.sa-input-dropdown-clear {
|
|
187
|
-
align-self:
|
|
188
|
-
margin-top: var(--iconMarginTop, 4px);
|
|
189
|
+
align-self: center;
|
|
189
190
|
}
|
|
190
191
|
.sa-input-dropdown-chevron {
|
|
191
192
|
display: inline-flex;
|
|
@@ -194,6 +195,18 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
|
|
|
194
195
|
flex-shrink: 0;
|
|
195
196
|
}
|
|
196
197
|
|
|
198
|
+
/* multiSelect: chip bisa membungkus ke beberapa baris → tempel area chip &
|
|
199
|
+
chevron/clear ke baris ATAS, bukan center di blok tinggi yang membungkus.
|
|
200
|
+
Single-line tetap center (aturan di atas). */
|
|
201
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-preview-container {
|
|
202
|
+
align-items: flex-start;
|
|
203
|
+
}
|
|
204
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-chevron,
|
|
205
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-clear {
|
|
206
|
+
align-self: flex-start;
|
|
207
|
+
margin-top: var(--iconMarginTop, 4px);
|
|
208
|
+
}
|
|
209
|
+
|
|
197
210
|
.sa-input-dropdown-container-preview-item {
|
|
198
211
|
flex: 1;
|
|
199
212
|
display: flex;
|
|
@@ -588,12 +601,12 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
|
|
|
588
601
|
} /* @layer starasia.components */
|
|
589
602
|
`;
|
|
590
603
|
function Rn(o) {
|
|
591
|
-
const [t,
|
|
592
|
-
p.current && !p.current.contains(
|
|
604
|
+
const [t, s] = L(o), p = J(null), c = (i) => {
|
|
605
|
+
p.current && !p.current.contains(i.target) && s(!1);
|
|
593
606
|
};
|
|
594
|
-
return
|
|
607
|
+
return x(() => (document.addEventListener("click", c, !0), () => {
|
|
595
608
|
document.removeEventListener("click", c, !0);
|
|
596
|
-
}), []), { ref: p, isComponentVisible: t, setIsComponentVisible:
|
|
609
|
+
}), []), { ref: p, isComponentVisible: t, setIsComponentVisible: s };
|
|
597
610
|
}
|
|
598
611
|
const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
599
612
|
"svg",
|
|
@@ -646,27 +659,27 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
646
659
|
}
|
|
647
660
|
)
|
|
648
661
|
}
|
|
649
|
-
),
|
|
662
|
+
), jn = En(
|
|
650
663
|
({
|
|
651
664
|
positionDropdown: o,
|
|
652
665
|
dropdownLists: t,
|
|
653
|
-
isComponentVisible:
|
|
666
|
+
isComponentVisible: s,
|
|
654
667
|
searchAble: p,
|
|
655
668
|
hideSearch: c,
|
|
656
|
-
onSearch:
|
|
669
|
+
onSearch: i,
|
|
657
670
|
value: A,
|
|
658
671
|
handleChangeValue: F,
|
|
659
672
|
multiSelect: k,
|
|
660
673
|
searchValue: y,
|
|
661
674
|
highlightedIndex: N,
|
|
662
675
|
listboxId: M,
|
|
663
|
-
footer:
|
|
676
|
+
footer: T,
|
|
664
677
|
groupLabel: C,
|
|
665
|
-
onSelectAll:
|
|
678
|
+
onSelectAll: $,
|
|
666
679
|
emptyState: X
|
|
667
680
|
}, Y) => {
|
|
668
|
-
const O =
|
|
669
|
-
|
|
681
|
+
const O = J([]), q = y !== void 0, [Z, Q] = L(""), d = q ? y : Z, H = !t || t.length === 0;
|
|
682
|
+
x(() => {
|
|
670
683
|
var a;
|
|
671
684
|
N >= 0 && O.current[N] && ((a = O.current[N]) == null || a.scrollIntoView({ block: "nearest" }));
|
|
672
685
|
}, [N]);
|
|
@@ -676,7 +689,7 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
676
689
|
"input",
|
|
677
690
|
{
|
|
678
691
|
onChange: (a) => {
|
|
679
|
-
q || Q(a.target.value),
|
|
692
|
+
q || Q(a.target.value), i && i(a.target.value);
|
|
680
693
|
},
|
|
681
694
|
value: d,
|
|
682
695
|
autoFocus: !0,
|
|
@@ -684,7 +697,7 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
684
697
|
}
|
|
685
698
|
)
|
|
686
699
|
] }) : null;
|
|
687
|
-
return /* @__PURE__ */ n(tn, { children:
|
|
700
|
+
return /* @__PURE__ */ n(tn, { children: s ? /* @__PURE__ */ l(
|
|
688
701
|
"div",
|
|
689
702
|
{
|
|
690
703
|
className: [
|
|
@@ -719,12 +732,12 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
719
732
|
] }) : "No data available") }),
|
|
720
733
|
C && !H && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
|
|
721
734
|
/* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: C }),
|
|
722
|
-
k &&
|
|
735
|
+
k && $ && /* @__PURE__ */ n(
|
|
723
736
|
"button",
|
|
724
737
|
{
|
|
725
738
|
className: "sa-input-dropdown-section-select-all",
|
|
726
739
|
onClick: (a) => {
|
|
727
|
-
a.stopPropagation(),
|
|
740
|
+
a.stopPropagation(), $();
|
|
728
741
|
},
|
|
729
742
|
children: "Select all"
|
|
730
743
|
}
|
|
@@ -783,43 +796,43 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
|
|
|
783
796
|
]
|
|
784
797
|
}
|
|
785
798
|
),
|
|
786
|
-
|
|
799
|
+
T && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: T })
|
|
787
800
|
]
|
|
788
801
|
}
|
|
789
802
|
) : null });
|
|
790
803
|
}
|
|
791
|
-
),
|
|
804
|
+
), Sn = ({
|
|
792
805
|
children: o,
|
|
793
806
|
handleChangePosition: t,
|
|
794
|
-
enabled:
|
|
795
|
-
}) => (
|
|
796
|
-
if (
|
|
807
|
+
enabled: s = !0
|
|
808
|
+
}) => (x(() => {
|
|
809
|
+
if (s)
|
|
797
810
|
return window.addEventListener("scroll", t, !0), () => {
|
|
798
811
|
window.removeEventListener("scroll", t, !0);
|
|
799
812
|
};
|
|
800
|
-
}, [
|
|
813
|
+
}, [s, t]), /* @__PURE__ */ n("div", { children: o })), hn = "sa-input-dropdown-styles", Ln = (o) => {
|
|
801
814
|
if (!(typeof document > "u") && !document.getElementById(hn)) {
|
|
802
815
|
const t = document.createElement("style");
|
|
803
816
|
t.id = hn, t.textContent = o, document.head.appendChild(t);
|
|
804
817
|
}
|
|
805
818
|
};
|
|
806
|
-
|
|
819
|
+
Ln(zn);
|
|
807
820
|
const Pn = ({
|
|
808
821
|
dropdownLists: o,
|
|
809
822
|
onChange: t,
|
|
810
|
-
defaultValue:
|
|
823
|
+
defaultValue: s,
|
|
811
824
|
value: p,
|
|
812
825
|
size: c = "sm",
|
|
813
|
-
multiSelect:
|
|
826
|
+
multiSelect: i,
|
|
814
827
|
searchAble: A,
|
|
815
828
|
iconLeft: F,
|
|
816
829
|
placeholder: k,
|
|
817
830
|
onSearch: y,
|
|
818
831
|
error: N,
|
|
819
832
|
onBlur: M,
|
|
820
|
-
onFocus:
|
|
833
|
+
onFocus: T,
|
|
821
834
|
disable: C,
|
|
822
|
-
searchValue:
|
|
835
|
+
searchValue: $,
|
|
823
836
|
variant: X = "outline",
|
|
824
837
|
footer: Y,
|
|
825
838
|
groupLabel: O,
|
|
@@ -837,74 +850,74 @@ const Pn = ({
|
|
|
837
850
|
required: B,
|
|
838
851
|
optional: dn,
|
|
839
852
|
description: D,
|
|
840
|
-
helperText:
|
|
853
|
+
helperText: j,
|
|
841
854
|
errorText: h
|
|
842
855
|
}) => {
|
|
843
856
|
const nn = [
|
|
844
857
|
"sa-select-field",
|
|
845
858
|
`sa-select-field-size-${c}`,
|
|
846
859
|
Q ? "sa-select-field-fullwidth" : ""
|
|
847
|
-
].filter(Boolean).join(" "), z = p !== void 0, en =
|
|
848
|
-
z ? p || [] :
|
|
849
|
-
), [
|
|
860
|
+
].filter(Boolean).join(" "), z = p !== void 0, en = J(), vn = N || !!h, [u, S] = L(
|
|
861
|
+
z ? p || [] : s || []
|
|
862
|
+
), [gn, ln] = L(""), [b, on] = L(-1), G = sn.useId(), pn = b >= 0 ? `${G}-opt-${b}` : void 0, [cn, K] = L(
|
|
850
863
|
() => {
|
|
851
864
|
var e, r;
|
|
852
|
-
return !
|
|
865
|
+
return !i && (p != null && p.length || s != null && s.length) ? ((e = p == null ? void 0 : p[0]) == null ? void 0 : e.label) ?? ((r = s == null ? void 0 : s[0]) == null ? void 0 : r.label) ?? "" : "";
|
|
853
866
|
}
|
|
854
|
-
), v =
|
|
867
|
+
), v = J(null), { isComponentVisible: w, ref: rn, setIsComponentVisible: R } = Rn(!1), I = o !== void 0, un = u.length > 0, xn = (e) => {
|
|
855
868
|
e.stopPropagation();
|
|
856
869
|
const r = [];
|
|
857
|
-
z ||
|
|
870
|
+
z || S(r), t(r), d && K(""), m == null || m();
|
|
858
871
|
}, mn = () => {
|
|
859
872
|
I && R((e) => !e);
|
|
860
|
-
},
|
|
861
|
-
if (
|
|
862
|
-
if (u == null ? void 0 : u.find((
|
|
863
|
-
const
|
|
864
|
-
z ||
|
|
873
|
+
}, U = (e, r) => {
|
|
874
|
+
if (i) {
|
|
875
|
+
if (u == null ? void 0 : u.find((g) => g.value === r)) {
|
|
876
|
+
const g = u.filter((Cn) => Cn.value !== r);
|
|
877
|
+
z || S(g), t(g);
|
|
865
878
|
} else {
|
|
866
|
-
const
|
|
867
|
-
z ||
|
|
879
|
+
const g = [...u, { label: e, value: r }];
|
|
880
|
+
z || S(g), t(g);
|
|
868
881
|
}
|
|
869
|
-
d &&
|
|
882
|
+
d && K("");
|
|
870
883
|
} else {
|
|
871
|
-
const
|
|
872
|
-
z ||
|
|
884
|
+
const f = [{ label: e, value: r }];
|
|
885
|
+
z || S(f), t(f), d && K(H ? "" : e), R(!1);
|
|
873
886
|
}
|
|
874
887
|
};
|
|
875
|
-
|
|
876
|
-
z &&
|
|
877
|
-
}, [p]),
|
|
878
|
-
z || JSON.stringify(en.current) === JSON.stringify(
|
|
879
|
-
}, [
|
|
880
|
-
const kn = () => u.length ?
|
|
888
|
+
x(() => {
|
|
889
|
+
z && S(p || []);
|
|
890
|
+
}, [p]), x(() => {
|
|
891
|
+
z || JSON.stringify(en.current) === JSON.stringify(s) || (en.current = s, S(en.current || []));
|
|
892
|
+
}, [s]);
|
|
893
|
+
const kn = () => u.length ? i ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
881
894
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
882
895
|
/* @__PURE__ */ n(
|
|
883
|
-
|
|
896
|
+
fn,
|
|
884
897
|
{
|
|
885
|
-
onClick: (
|
|
886
|
-
|
|
898
|
+
onClick: (f) => {
|
|
899
|
+
f.stopPropagation(), U(e.label, e.value);
|
|
887
900
|
}
|
|
888
901
|
}
|
|
889
902
|
)
|
|
890
903
|
] }, 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: k }), W = () => {
|
|
891
904
|
if (rn.current && v.current) {
|
|
892
|
-
const e = window.innerHeight, r = rn.current.getBoundingClientRect(),
|
|
893
|
-
v.current.style.left = `${r.left}px`, v.current.style.width = `${r.width}px`,
|
|
905
|
+
const e = window.innerHeight, r = rn.current.getBoundingClientRect(), f = v.current.getBoundingClientRect(), g = r.bottom + f.height;
|
|
906
|
+
v.current.style.left = `${r.left}px`, v.current.style.width = `${r.width}px`, g >= e - 10 ? (v.current.style.top = `${r.top - f.height - 5}px`, ln("top")) : (v.current.style.top = `${r.top + r.height + 4}px`, ln("bottom"));
|
|
894
907
|
}
|
|
895
908
|
};
|
|
896
|
-
|
|
909
|
+
x(() => (window.addEventListener("resize", W), () => {
|
|
897
910
|
window.removeEventListener("resize", W);
|
|
898
|
-
}), []),
|
|
911
|
+
}), []), x(() => {
|
|
899
912
|
W();
|
|
900
|
-
}, [w]),
|
|
913
|
+
}, [w]), x(() => {
|
|
901
914
|
if (!w || !v.current)
|
|
902
915
|
return;
|
|
903
916
|
const e = new ResizeObserver(() => {
|
|
904
917
|
W();
|
|
905
918
|
});
|
|
906
919
|
return e.observe(v.current), () => e.disconnect();
|
|
907
|
-
}, [w]),
|
|
920
|
+
}, [w]), x(() => {
|
|
908
921
|
w || on(-1);
|
|
909
922
|
}, [w]);
|
|
910
923
|
const wn = (e) => {
|
|
@@ -916,20 +929,20 @@ const Pn = ({
|
|
|
916
929
|
switch (e.key) {
|
|
917
930
|
case "ArrowDown": {
|
|
918
931
|
e.preventDefault();
|
|
919
|
-
const r =
|
|
932
|
+
const r = bn(o, b, 1);
|
|
920
933
|
r !== -1 && on(r);
|
|
921
934
|
break;
|
|
922
935
|
}
|
|
923
936
|
case "ArrowUp": {
|
|
924
937
|
e.preventDefault();
|
|
925
|
-
const r =
|
|
938
|
+
const r = bn(o, b, -1);
|
|
926
939
|
r !== -1 && on(r);
|
|
927
940
|
break;
|
|
928
941
|
}
|
|
929
942
|
case "Enter": {
|
|
930
|
-
e.preventDefault(),
|
|
931
|
-
o[
|
|
932
|
-
o[
|
|
943
|
+
e.preventDefault(), b >= 0 && o[b] && !o[b].disable && U(
|
|
944
|
+
o[b].label,
|
|
945
|
+
o[b].value
|
|
933
946
|
);
|
|
934
947
|
break;
|
|
935
948
|
}
|
|
@@ -946,18 +959,18 @@ const Pn = ({
|
|
|
946
959
|
"aria-label": "Clear selection",
|
|
947
960
|
"aria-hidden": !un,
|
|
948
961
|
tabIndex: -1,
|
|
949
|
-
onClick:
|
|
962
|
+
onClick: xn,
|
|
950
963
|
onMouseDown: (e) => e.preventDefault(),
|
|
951
964
|
children: /* @__PURE__ */ n(An, { width: P, height: P })
|
|
952
965
|
}
|
|
953
966
|
) : null, Nn = d ? /* @__PURE__ */ l(tn, { children: [
|
|
954
|
-
|
|
967
|
+
i && u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
|
|
955
968
|
/* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
|
|
956
969
|
/* @__PURE__ */ n(
|
|
957
|
-
|
|
970
|
+
fn,
|
|
958
971
|
{
|
|
959
|
-
onClick: (
|
|
960
|
-
|
|
972
|
+
onClick: (f) => {
|
|
973
|
+
f.stopPropagation(), U(e.label, e.value);
|
|
961
974
|
}
|
|
962
975
|
}
|
|
963
976
|
)
|
|
@@ -975,21 +988,21 @@ const Pn = ({
|
|
|
975
988
|
value: cn,
|
|
976
989
|
onChange: (e) => {
|
|
977
990
|
const r = e.target.value;
|
|
978
|
-
|
|
991
|
+
K(r), y == null || y(r), !w && I && R(!0);
|
|
979
992
|
},
|
|
980
993
|
onFocus: () => {
|
|
981
994
|
!C && I && R(!0);
|
|
982
995
|
},
|
|
983
996
|
onBlur: () => {
|
|
984
|
-
|
|
997
|
+
i || setTimeout(() => R(!1), 150);
|
|
985
998
|
},
|
|
986
999
|
onKeyDown: wn,
|
|
987
|
-
placeholder: u.length === 0 ||
|
|
1000
|
+
placeholder: u.length === 0 || i ? k : void 0,
|
|
988
1001
|
disabled: C
|
|
989
1002
|
}
|
|
990
1003
|
)
|
|
991
1004
|
] }) : null, an = /* @__PURE__ */ n(
|
|
992
|
-
|
|
1005
|
+
Sn,
|
|
993
1006
|
{
|
|
994
1007
|
handleChangePosition: W,
|
|
995
1008
|
enabled: w,
|
|
@@ -1003,6 +1016,9 @@ const Pn = ({
|
|
|
1003
1016
|
`sa-input-dropdown-${X}`,
|
|
1004
1017
|
`sa-input-dropdown-size-${c}`,
|
|
1005
1018
|
d ? "trigger-input" : "",
|
|
1019
|
+
// multiSelect = chip bisa membungkus → CSS tempel chevron/clear ke
|
|
1020
|
+
// baris atas; single-line tetap center (fix combobox kelihatan naik).
|
|
1021
|
+
i ? "multiselect" : "",
|
|
1006
1022
|
w ? "active" : "",
|
|
1007
1023
|
vn ? "error" : "",
|
|
1008
1024
|
C ? "disable" : ""
|
|
@@ -1017,7 +1033,7 @@ const Pn = ({
|
|
|
1017
1033
|
onKeyDown: d ? void 0 : wn,
|
|
1018
1034
|
tabIndex: d ? void 0 : 0,
|
|
1019
1035
|
onBlur: d ? void 0 : M,
|
|
1020
|
-
onFocus: d ? void 0 :
|
|
1036
|
+
onFocus: d ? void 0 : T,
|
|
1021
1037
|
children: [
|
|
1022
1038
|
/* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
|
|
1023
1039
|
F ? sn.cloneElement(F, {
|
|
@@ -1029,21 +1045,21 @@ const Pn = ({
|
|
|
1029
1045
|
!_ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(On, { width: P }) : /* @__PURE__ */ n(Mn, { width: P }) })
|
|
1030
1046
|
] }),
|
|
1031
1047
|
I && /* @__PURE__ */ n(
|
|
1032
|
-
|
|
1048
|
+
jn,
|
|
1033
1049
|
{
|
|
1034
1050
|
dropdownLists: o,
|
|
1035
|
-
handleChangeValue:
|
|
1051
|
+
handleChangeValue: U,
|
|
1036
1052
|
isComponentVisible: w,
|
|
1037
1053
|
listboxId: G,
|
|
1038
|
-
positionDropdown:
|
|
1054
|
+
positionDropdown: gn,
|
|
1039
1055
|
searchAble: !!A,
|
|
1040
1056
|
hideSearch: d,
|
|
1041
1057
|
value: u,
|
|
1042
1058
|
onSearch: y,
|
|
1043
1059
|
ref: v,
|
|
1044
|
-
multiSelect:
|
|
1045
|
-
searchValue: d ? cn :
|
|
1046
|
-
highlightedIndex:
|
|
1060
|
+
multiSelect: i,
|
|
1061
|
+
searchValue: d ? cn : $,
|
|
1062
|
+
highlightedIndex: b,
|
|
1047
1063
|
footer: Y,
|
|
1048
1064
|
groupLabel: O,
|
|
1049
1065
|
onSelectAll: q,
|
|
@@ -1066,7 +1082,7 @@ const Pn = ({
|
|
|
1066
1082
|
] }),
|
|
1067
1083
|
/* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
|
|
1068
1084
|
an,
|
|
1069
|
-
|
|
1085
|
+
j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
|
|
1070
1086
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1071
1087
|
] })
|
|
1072
1088
|
] }) : /* @__PURE__ */ l("div", { className: nn, children: [
|
|
@@ -1077,35 +1093,35 @@ const Pn = ({
|
|
|
1077
1093
|
] }),
|
|
1078
1094
|
D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
|
|
1079
1095
|
an,
|
|
1080
|
-
|
|
1096
|
+
j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
|
|
1081
1097
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1082
1098
|
] }) : /* @__PURE__ */ l("div", { className: nn, children: [
|
|
1083
1099
|
D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
|
|
1084
1100
|
an,
|
|
1085
|
-
|
|
1101
|
+
j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
|
|
1086
1102
|
h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
|
|
1087
1103
|
] });
|
|
1088
|
-
},
|
|
1104
|
+
}, bn = (o, t, s) => {
|
|
1089
1105
|
const p = o.length;
|
|
1090
|
-
let c = t +
|
|
1106
|
+
let c = t + s;
|
|
1091
1107
|
for (; c >= 0 && c < p; ) {
|
|
1092
1108
|
if (!o[c].disable)
|
|
1093
1109
|
return c;
|
|
1094
|
-
c +=
|
|
1110
|
+
c += s;
|
|
1095
1111
|
}
|
|
1096
|
-
if (
|
|
1097
|
-
for (let
|
|
1098
|
-
if (!o[
|
|
1099
|
-
return
|
|
1112
|
+
if (s === 1) {
|
|
1113
|
+
for (let i = 0; i < p; i++)
|
|
1114
|
+
if (!o[i].disable)
|
|
1115
|
+
return i;
|
|
1100
1116
|
} else
|
|
1101
|
-
for (let
|
|
1102
|
-
if (!o[
|
|
1103
|
-
return
|
|
1117
|
+
for (let i = p - 1; i >= 0; i--)
|
|
1118
|
+
if (!o[i].disable)
|
|
1119
|
+
return i;
|
|
1104
1120
|
return -1;
|
|
1105
1121
|
}, An = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
|
|
1106
1122
|
/* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
|
|
1107
1123
|
/* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
1108
|
-
] }),
|
|
1124
|
+
] }), fn = (o) => /* @__PURE__ */ n(
|
|
1109
1125
|
"svg",
|
|
1110
1126
|
{
|
|
1111
1127
|
xmlns: "http://www.w3.org/2000/svg",
|
package/dist/dropdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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 un=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
|
|
2
2
|
starasia, components, utilities). CSS app/Tailwind utility selalu bisa
|
|
3
3
|
menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
|
|
4
4
|
@layer starasia.components {
|
|
@@ -172,18 +172,19 @@
|
|
|
172
172
|
display: flex;
|
|
173
173
|
flex-direction: row;
|
|
174
174
|
gap: 8px;
|
|
175
|
-
|
|
175
|
+
/* Single-line (combobox input, placeholder, single value) → center supaya
|
|
176
|
+
teks & chevron sejajar persis di tengah field. Kasus multiSelect yang
|
|
177
|
+
chip-nya bisa membungkus di-override ke flex-start di bawah. */
|
|
178
|
+
align-items: center;
|
|
176
179
|
justify-content: space-between;
|
|
177
180
|
width: 100%;
|
|
178
181
|
min-width: 0;
|
|
179
182
|
}
|
|
180
183
|
|
|
181
|
-
/* Chevron + clear button —
|
|
182
|
-
centered when single-line, and snap to top-right when content wraps */
|
|
184
|
+
/* Chevron + clear button — center di single-line (sejajar teks input). */
|
|
183
185
|
.sa-input-dropdown-chevron,
|
|
184
186
|
.sa-input-dropdown-clear {
|
|
185
|
-
align-self:
|
|
186
|
-
margin-top: var(--iconMarginTop, 4px);
|
|
187
|
+
align-self: center;
|
|
187
188
|
}
|
|
188
189
|
.sa-input-dropdown-chevron {
|
|
189
190
|
display: inline-flex;
|
|
@@ -192,6 +193,18 @@
|
|
|
192
193
|
flex-shrink: 0;
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
/* multiSelect: chip bisa membungkus ke beberapa baris → tempel area chip &
|
|
197
|
+
chevron/clear ke baris ATAS, bukan center di blok tinggi yang membungkus.
|
|
198
|
+
Single-line tetap center (aturan di atas). */
|
|
199
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-preview-container {
|
|
200
|
+
align-items: flex-start;
|
|
201
|
+
}
|
|
202
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-chevron,
|
|
203
|
+
.sa-input-dropdown-container.multiselect .sa-input-dropdown-clear {
|
|
204
|
+
align-self: flex-start;
|
|
205
|
+
margin-top: var(--iconMarginTop, 4px);
|
|
206
|
+
}
|
|
207
|
+
|
|
195
208
|
.sa-input-dropdown-container-preview-item {
|
|
196
209
|
flex: 1;
|
|
197
210
|
display: flex;
|
|
@@ -584,4 +597,4 @@
|
|
|
584
597
|
}
|
|
585
598
|
|
|
586
599
|
} /* @layer starasia.components */
|
|
587
|
-
`;function fn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const 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"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue:T,multiSelect:y,searchValue:k,highlightedIndex:N,listboxId:M,footer:W,groupLabel:E,onSelectAll:$,emptyState:K},X)=>{const O=s.useRef([]),q=k!==void 0,[Y,Z]=s.useState(""),l=q?k:Y,H=!d||d.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(hn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(S=>S.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:S=>{O.current[m]=S},onClick:()=>T(a.label,a.value),children:[y&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:W})]}):null})}),xn=({children:o,handleChangePosition:d,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",d,!0),()=>{window.removeEventListener("scroll",d,!0)}},[t,d]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const d=document.createElement("style");d.id=rn,d.textContent=o,document.head.appendChild(d)}})(un);const gn=({dropdownLists:o,onChange:d,defaultValue:t,value:p,size:c="sm",multiSelect:i,searchAble:A,iconLeft:T,placeholder:y,onSearch:k,error:N,onBlur:M,onFocus:W,disable:E,searchValue:$,variant:K="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:S,optional:dn,description:D,helperText:j,errorText:f})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!f,[w,L]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[h,nn]=s.useState(-1),G=s.useId(),ln=h>=0?`${G}-opt-${h}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:u,ref:en,setIsComponentVisible:B}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||L(r),d(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(i){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(jn=>jn.value!==r);z||L(x),d(x)}else{const x=[...w,{label:e,value:r}];z||L(x),d(x)}l&&U("")}else{const b=[{label:e,value:r}];z||L(b),d(b),l&&U(H?"":e),B(!1)}};s.useEffect(()=>{z&&L(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,L(R.current||[]))},[t]);const Bn=()=>w.length?i?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:y}),F=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),x=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,x>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[u]),s.useEffect(()=>{if(!u||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[u]),s.useEffect(()=>{u||nn(-1)},[u]);const wn=e=>{if(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,h,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,h,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),h>=0&&o[h]&&!o[h].disable&&J(o[h].label,o[h].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Sn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Dn=l?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!u&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{i||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||i?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:u,children:n.jsxs("div",{className:["sa-input-dropdown-container",`sa-input-dropdown-${K}`,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",u?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:u,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:W,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[T?s.cloneElement(T,{width:P,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Dn:Bn()}),Sn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:u,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:h,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),S&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:V,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},an=(o,d,t)=>{const p=o.length;let c=d+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let i=0;i<p;i++)if(!o[i].disable)return i}else for(let i=p-1;i>=0;i--)if(!o[i].disable)return i;return-1},mn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),sn=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),yn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),kn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});g.Dropdown=gn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
600
|
+
`;function fn(o){const[i,t]=s.useState(o),p=s.useRef(null),c=d=>{p.current&&!p.current.contains(d.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:i,setIsComponentVisible:t}}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"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:i,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:d,value:A,handleChangeValue:P,multiSelect:k,searchValue:y,highlightedIndex:N,listboxId:M,footer:W,groupLabel:E,onSelectAll:$,emptyState:J},X)=>{const O=s.useRef([]),q=y!==void 0,[Y,Z]=s.useState(""),l=q?y:Y,H=!i||i.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(hn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),d&&d(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${k?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":k||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:J??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),k&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),i==null?void 0:i.map((a,m)=>{const C=!!(A!=null&&A.find(B=>B.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:B=>{O.current[m]=B},onClick:()=>P(a.label,a.value),children:[k&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:W})]}):null})}),gn=({children:o,handleChangePosition:i,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",i,!0),()=>{window.removeEventListener("scroll",i,!0)}},[t,i]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const i=document.createElement("style");i.id=rn,i.textContent=o,document.head.appendChild(i)}})(un);const xn=({dropdownLists:o,onChange:i,defaultValue:t,value:p,size:c="sm",multiSelect:d,searchAble:A,iconLeft:P,placeholder:k,onSearch:y,error:N,onBlur:M,onFocus:W,disable:E,searchValue:$,variant:J="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:B,optional:dn,description:D,helperText:j,errorText:f})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!f,[w,L]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[h,nn]=s.useState(-1),G=s.useId(),ln=h>=0?`${G}-opt-${h}`:void 0,[pn,K]=s.useState(()=>{var e,r;return!d&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:u,ref:en,setIsComponentVisible:S}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||L(r),i(r),l&&K(""),m==null||m()},zn=()=>{I&&S(e=>!e)},U=(e,r)=>{if(d){if(w==null?void 0:w.find(g=>g.value===r)){const g=w.filter(jn=>jn.value!==r);z||L(g),i(g)}else{const g=[...w,{label:e,value:r}];z||L(g),i(g)}l&&K("")}else{const b=[{label:e,value:r}];z||L(b),i(b),l&&K(H?"":e),S(!1)}};s.useEffect(()=>{z&&L(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,L(R.current||[]))},[t]);const Sn=()=>w.length?d?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),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:k}),T=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),g=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,g>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",T),()=>{window.removeEventListener("resize",T)}),[]),s.useEffect(()=>{T()},[u]),s.useEffect(()=>{if(!u||!v.current)return;const e=new ResizeObserver(()=>{T()});return e.observe(v.current),()=>e.disconnect()},[u]),s.useEffect(()=>{u||nn(-1)},[u]);const wn=e=>{if(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),S(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,h,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,h,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),h>=0&&o[h]&&!o[h].disable&&U(o[h].label,o[h].value);break}case"Escape":S(!1);break}}},F=c==="lg"||c==="xl"?20:c==="xs"?14:16,Bn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:F,height:F})}):null,Dn=l?n.jsxs(n.Fragment,{children:[d&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),U(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;K(r),y==null||y(r),!u&&I&&S(!0)},onFocus:()=>{!E&&I&&S(!0)},onBlur:()=>{d||setTimeout(()=>S(!1),150)},onKeyDown:wn,placeholder:w.length===0||d?k:void 0,disabled:E})]}):null,on=n.jsx(gn,{handleChangePosition:T,enabled:u,children:n.jsxs("div",{className:["sa-input-dropdown-container",`sa-input-dropdown-${J}`,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",d?"multiselect":"",u?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:u,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:W,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[P?s.cloneElement(P,{width:F,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Dn:Sn()}),Bn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(yn,{width:F}):n.jsx(kn,{width:F})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:U,isComponentVisible:u,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:y,ref:v,multiSelect:d,searchValue:l?pn:$,highlightedIndex:h,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),B&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),B&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:V,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:j}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},an=(o,i,t)=>{const p=o.length;let c=i+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let d=0;d<p;d++)if(!o[d].disable)return d}else for(let d=p-1;d>=0;d--)if(!o[d].disable)return d;return-1},mn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),sn=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),kn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),yn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});x.Dropdown=xn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|