@starasia/dropdown 6.1.2 → 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.
@@ -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 S, useRef as K, useEffect as g, forwardRef as En } from "react";
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). */
@@ -105,20 +105,20 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
105
105
  }
106
106
 
107
107
  /* --- Standard variant (default) --- */
108
- .sa-input-dropdown-container.standard {
108
+ .sa-input-dropdown-container.sa-input-dropdown-standard {
109
109
  background-color: var(--sa-dropdown-bg-neutral);
110
110
  border: 1px solid transparent;
111
111
  border-radius: var(--borderRadius);
112
112
  }
113
- .sa-input-dropdown-container.standard.active {
113
+ .sa-input-dropdown-container.sa-input-dropdown-standard.active {
114
114
  border: 1px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
115
115
  box-shadow: var(--sa-dropdown-ring-active);
116
116
  }
117
- .sa-input-dropdown-container.standard.error {
117
+ .sa-input-dropdown-container.sa-input-dropdown-standard.error {
118
118
  background-color: var(--sa-dropdown-bg-error);
119
119
  border-color: var(--sa-dropdown-border-error-subtle);
120
120
  }
121
- .sa-input-dropdown-container.standard.disable {
121
+ .sa-input-dropdown-container.sa-input-dropdown-standard.disable {
122
122
  background-color: var(--sa-dropdown-bg-disabled);
123
123
  border-color: transparent;
124
124
  cursor: not-allowed;
@@ -127,21 +127,21 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
127
127
  }
128
128
 
129
129
  /* --- Outline variant --- */
130
- .sa-input-dropdown-container.outline {
130
+ .sa-input-dropdown-container.sa-input-dropdown-outline {
131
131
  background-color: transparent;
132
132
  border: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
133
133
  border-radius: var(--borderRadius);
134
134
  outline: none;
135
135
  }
136
- .sa-input-dropdown-container.outline.active {
136
+ .sa-input-dropdown-container.sa-input-dropdown-outline.active {
137
137
  border: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
138
138
  box-shadow: none;
139
139
  }
140
- .sa-input-dropdown-container.outline.error {
140
+ .sa-input-dropdown-container.sa-input-dropdown-outline.error {
141
141
  background-color: transparent;
142
142
  border: 1px solid var(--sa-dropdown-border-error-subtle);
143
143
  }
144
- .sa-input-dropdown-container.outline.disable {
144
+ .sa-input-dropdown-container.sa-input-dropdown-outline.disable {
145
145
  background-color: var(--sa-dropdown-bg-disabled);
146
146
  border-color: var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
147
147
  cursor: not-allowed;
@@ -150,20 +150,20 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
150
150
  }
151
151
 
152
152
  /* --- Flushed variant --- */
153
- .sa-input-dropdown-container.flushed {
153
+ .sa-input-dropdown-container.sa-input-dropdown-flushed {
154
154
  background-color: transparent;
155
155
  border: none;
156
156
  border-bottom: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
157
157
  border-radius: 0;
158
158
  }
159
- .sa-input-dropdown-container.flushed.active {
159
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.active {
160
160
  border-bottom: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
161
161
  box-shadow: none;
162
162
  }
163
- .sa-input-dropdown-container.flushed.error {
163
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.error {
164
164
  border-bottom: 1px solid var(--sa-dropdown-border-error-subtle);
165
165
  }
166
- .sa-input-dropdown-container.flushed.disable {
166
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.disable {
167
167
  cursor: not-allowed;
168
168
  pointer-events: none;
169
169
  opacity: 0.6;
@@ -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
- align-items: flex-start;
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 — top-aligned with margin so they appear visually
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: flex-start;
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;
@@ -223,8 +236,8 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
223
236
  color: var(--sa-dropdown-placeholder);
224
237
  font-weight: 400;
225
238
  }
226
- .sa-input-dropdown-container.outline .sa-input-dropdown-placeholder,
227
- .sa-input-dropdown-container.flushed .sa-input-dropdown-placeholder {
239
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-placeholder,
240
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-placeholder {
228
241
  color: var(--sa-dropdown-placeholder-subtle);
229
242
  }
230
243
 
@@ -252,8 +265,8 @@ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
252
265
  .sa-input-dropdown-trigger-input::placeholder {
253
266
  color: var(--sa-dropdown-placeholder);
254
267
  }
255
- .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
256
- .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
268
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-trigger-input::placeholder,
269
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-trigger-input::placeholder {
257
270
  color: var(--sa-dropdown-placeholder-subtle);
258
271
  }
259
272
  .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
@@ -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, i] = S(o), p = K(null), c = (s) => {
592
- p.current && !p.current.contains(s.target) && i(!1);
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 g(() => (document.addEventListener("click", c, !0), () => {
607
+ return x(() => (document.addEventListener("click", c, !0), () => {
595
608
  document.removeEventListener("click", c, !0);
596
- }), []), { ref: p, isComponentVisible: t, setIsComponentVisible: i };
609
+ }), []), { ref: p, isComponentVisible: t, setIsComponentVisible: s };
597
610
  }
598
611
  const Bn = ({ ...o }) => /* @__PURE__ */ l(
599
612
  "svg",
@@ -646,14 +659,14 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
646
659
  }
647
660
  )
648
661
  }
649
- ), Ln = En(
662
+ ), jn = En(
650
663
  ({
651
664
  positionDropdown: o,
652
665
  dropdownLists: t,
653
- isComponentVisible: i,
666
+ isComponentVisible: s,
654
667
  searchAble: p,
655
668
  hideSearch: c,
656
- onSearch: s,
669
+ onSearch: i,
657
670
  value: A,
658
671
  handleChangeValue: F,
659
672
  multiSelect: k,
@@ -665,8 +678,8 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
665
678
  onSelectAll: $,
666
679
  emptyState: X
667
680
  }, Y) => {
668
- const O = K([]), q = y !== void 0, [Z, Q] = S(""), d = q ? y : Z, H = !t || t.length === 0;
669
- g(() => {
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), s && s(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: i ? /* @__PURE__ */ l(
700
+ return /* @__PURE__ */ n(tn, { children: s ? /* @__PURE__ */ l(
688
701
  "div",
689
702
  {
690
703
  className: [
@@ -788,29 +801,29 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
788
801
  }
789
802
  ) : null });
790
803
  }
791
- ), jn = ({
804
+ ), Sn = ({
792
805
  children: o,
793
806
  handleChangePosition: t,
794
- enabled: i = !0
795
- }) => (g(() => {
796
- if (i)
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
- }, [i, t]), /* @__PURE__ */ n("div", { children: o })), hn = "sa-input-dropdown-styles", Sn = (o) => {
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
- Sn(zn);
819
+ Ln(zn);
807
820
  const Pn = ({
808
821
  dropdownLists: o,
809
822
  onChange: t,
810
- defaultValue: i,
823
+ defaultValue: s,
811
824
  value: p,
812
825
  size: c = "sm",
813
- multiSelect: s,
826
+ multiSelect: i,
814
827
  searchAble: A,
815
828
  iconLeft: F,
816
829
  placeholder: k,
@@ -837,74 +850,74 @@ const Pn = ({
837
850
  required: B,
838
851
  optional: dn,
839
852
  description: D,
840
- helperText: L,
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 = K(), vn = N || !!h, [u, j] = S(
848
- z ? p || [] : i || []
849
- ), [xn, ln] = S(""), [f, on] = S(-1), G = sn.useId(), pn = f >= 0 ? `${G}-opt-${f}` : void 0, [cn, U] = S(
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 !s && (p != null && p.length || i != null && i.length) ? ((e = p == null ? void 0 : p[0]) == null ? void 0 : e.label) ?? ((r = i == null ? void 0 : i[0]) == null ? void 0 : r.label) ?? "" : "";
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 = K(null), { isComponentVisible: w, ref: rn, setIsComponentVisible: R } = Rn(!1), I = o !== void 0, un = u.length > 0, gn = (e) => {
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 || j(r), t(r), d && U(""), m == null || m();
870
+ z || S(r), t(r), d && K(""), m == null || m();
858
871
  }, mn = () => {
859
872
  I && R((e) => !e);
860
- }, J = (e, r) => {
861
- if (s) {
862
- if (u == null ? void 0 : u.find((x) => x.value === r)) {
863
- const x = u.filter((Cn) => Cn.value !== r);
864
- z || j(x), t(x);
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 x = [...u, { label: e, value: r }];
867
- z || j(x), t(x);
879
+ const g = [...u, { label: e, value: r }];
880
+ z || S(g), t(g);
868
881
  }
869
- d && U("");
882
+ d && K("");
870
883
  } else {
871
- const b = [{ label: e, value: r }];
872
- z || j(b), t(b), d && U(H ? "" : e), R(!1);
884
+ const f = [{ label: e, value: r }];
885
+ z || S(f), t(f), d && K(H ? "" : e), R(!1);
873
886
  }
874
887
  };
875
- g(() => {
876
- z && j(p || []);
877
- }, [p]), g(() => {
878
- z || JSON.stringify(en.current) === JSON.stringify(i) || (en.current = i, j(en.current || []));
879
- }, [i]);
880
- const kn = () => u.length ? s ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
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
- bn,
896
+ fn,
884
897
  {
885
- onClick: (b) => {
886
- b.stopPropagation(), J(e.label, e.value);
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(), b = v.current.getBoundingClientRect(), x = r.bottom + b.height;
893
- v.current.style.left = `${r.left}px`, v.current.style.width = `${r.width}px`, x >= e - 10 ? (v.current.style.top = `${r.top - b.height - 5}px`, ln("top")) : (v.current.style.top = `${r.top + r.height + 4}px`, ln("bottom"));
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
- g(() => (window.addEventListener("resize", W), () => {
909
+ x(() => (window.addEventListener("resize", W), () => {
897
910
  window.removeEventListener("resize", W);
898
- }), []), g(() => {
911
+ }), []), x(() => {
899
912
  W();
900
- }, [w]), g(() => {
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]), g(() => {
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 = fn(o, f, 1);
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 = fn(o, f, -1);
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(), f >= 0 && o[f] && !o[f].disable && J(
931
- o[f].label,
932
- o[f].value
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: gn,
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
- s && u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
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
- bn,
970
+ fn,
958
971
  {
959
- onClick: (b) => {
960
- b.stopPropagation(), J(e.label, e.value);
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
- U(r), y == null || y(r), !w && I && R(!0);
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
- s || setTimeout(() => R(!1), 150);
997
+ i || setTimeout(() => R(!1), 150);
985
998
  },
986
999
  onKeyDown: wn,
987
- placeholder: u.length === 0 || s ? k : void 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
- jn,
1005
+ Sn,
993
1006
  {
994
1007
  handleChangePosition: W,
995
1008
  enabled: w,
@@ -998,9 +1011,14 @@ const Pn = ({
998
1011
  {
999
1012
  className: [
1000
1013
  "sa-input-dropdown-container",
1001
- X,
1014
+ // namespaced: kelas variant polos ("outline"/"standard"/"flushed")
1015
+ // bentrok dgn utility Tailwind/shadcn (mis. `.outline`) → outline gelap.
1016
+ `sa-input-dropdown-${X}`,
1002
1017
  `sa-input-dropdown-size-${c}`,
1003
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" : "",
1004
1022
  w ? "active" : "",
1005
1023
  vn ? "error" : "",
1006
1024
  C ? "disable" : ""
@@ -1027,21 +1045,21 @@ const Pn = ({
1027
1045
  !_ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(On, { width: P }) : /* @__PURE__ */ n(Mn, { width: P }) })
1028
1046
  ] }),
1029
1047
  I && /* @__PURE__ */ n(
1030
- Ln,
1048
+ jn,
1031
1049
  {
1032
1050
  dropdownLists: o,
1033
- handleChangeValue: J,
1051
+ handleChangeValue: U,
1034
1052
  isComponentVisible: w,
1035
1053
  listboxId: G,
1036
- positionDropdown: xn,
1054
+ positionDropdown: gn,
1037
1055
  searchAble: !!A,
1038
1056
  hideSearch: d,
1039
1057
  value: u,
1040
1058
  onSearch: y,
1041
1059
  ref: v,
1042
- multiSelect: s,
1060
+ multiSelect: i,
1043
1061
  searchValue: d ? cn : $,
1044
- highlightedIndex: f,
1062
+ highlightedIndex: b,
1045
1063
  footer: Y,
1046
1064
  groupLabel: O,
1047
1065
  onSelectAll: q,
@@ -1064,7 +1082,7 @@ const Pn = ({
1064
1082
  ] }),
1065
1083
  /* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
1066
1084
  an,
1067
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1085
+ j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
1068
1086
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1069
1087
  ] })
1070
1088
  ] }) : /* @__PURE__ */ l("div", { className: nn, children: [
@@ -1075,35 +1093,35 @@ const Pn = ({
1075
1093
  ] }),
1076
1094
  D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
1077
1095
  an,
1078
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1096
+ j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
1079
1097
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1080
1098
  ] }) : /* @__PURE__ */ l("div", { className: nn, children: [
1081
1099
  D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
1082
1100
  an,
1083
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1101
+ j && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: j }),
1084
1102
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1085
1103
  ] });
1086
- }, fn = (o, t, i) => {
1104
+ }, bn = (o, t, s) => {
1087
1105
  const p = o.length;
1088
- let c = t + i;
1106
+ let c = t + s;
1089
1107
  for (; c >= 0 && c < p; ) {
1090
1108
  if (!o[c].disable)
1091
1109
  return c;
1092
- c += i;
1110
+ c += s;
1093
1111
  }
1094
- if (i === 1) {
1095
- for (let s = 0; s < p; s++)
1096
- if (!o[s].disable)
1097
- return s;
1112
+ if (s === 1) {
1113
+ for (let i = 0; i < p; i++)
1114
+ if (!o[i].disable)
1115
+ return i;
1098
1116
  } else
1099
- for (let s = p - 1; s >= 0; s--)
1100
- if (!o[s].disable)
1101
- return s;
1117
+ for (let i = p - 1; i >= 0; i--)
1118
+ if (!o[i].disable)
1119
+ return i;
1102
1120
  return -1;
1103
1121
  }, An = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1104
1122
  /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1105
1123
  /* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
1106
- ] }), bn = (o) => /* @__PURE__ */ n(
1124
+ ] }), fn = (o) => /* @__PURE__ */ n(
1107
1125
  "svg",
1108
1126
  {
1109
1127
  xmlns: "http://www.w3.org/2000/svg",
@@ -1,4 +1,4 @@
1
- (function(g,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const fn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
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 {
@@ -103,20 +103,20 @@
103
103
  }
104
104
 
105
105
  /* --- Standard variant (default) --- */
106
- .sa-input-dropdown-container.standard {
106
+ .sa-input-dropdown-container.sa-input-dropdown-standard {
107
107
  background-color: var(--sa-dropdown-bg-neutral);
108
108
  border: 1px solid transparent;
109
109
  border-radius: var(--borderRadius);
110
110
  }
111
- .sa-input-dropdown-container.standard.active {
111
+ .sa-input-dropdown-container.sa-input-dropdown-standard.active {
112
112
  border: 1px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
113
113
  box-shadow: var(--sa-dropdown-ring-active);
114
114
  }
115
- .sa-input-dropdown-container.standard.error {
115
+ .sa-input-dropdown-container.sa-input-dropdown-standard.error {
116
116
  background-color: var(--sa-dropdown-bg-error);
117
117
  border-color: var(--sa-dropdown-border-error-subtle);
118
118
  }
119
- .sa-input-dropdown-container.standard.disable {
119
+ .sa-input-dropdown-container.sa-input-dropdown-standard.disable {
120
120
  background-color: var(--sa-dropdown-bg-disabled);
121
121
  border-color: transparent;
122
122
  cursor: not-allowed;
@@ -125,21 +125,21 @@
125
125
  }
126
126
 
127
127
  /* --- Outline variant --- */
128
- .sa-input-dropdown-container.outline {
128
+ .sa-input-dropdown-container.sa-input-dropdown-outline {
129
129
  background-color: transparent;
130
130
  border: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
131
131
  border-radius: var(--borderRadius);
132
132
  outline: none;
133
133
  }
134
- .sa-input-dropdown-container.outline.active {
134
+ .sa-input-dropdown-container.sa-input-dropdown-outline.active {
135
135
  border: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
136
136
  box-shadow: none;
137
137
  }
138
- .sa-input-dropdown-container.outline.error {
138
+ .sa-input-dropdown-container.sa-input-dropdown-outline.error {
139
139
  background-color: transparent;
140
140
  border: 1px solid var(--sa-dropdown-border-error-subtle);
141
141
  }
142
- .sa-input-dropdown-container.outline.disable {
142
+ .sa-input-dropdown-container.sa-input-dropdown-outline.disable {
143
143
  background-color: var(--sa-dropdown-bg-disabled);
144
144
  border-color: var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
145
145
  cursor: not-allowed;
@@ -148,20 +148,20 @@
148
148
  }
149
149
 
150
150
  /* --- Flushed variant --- */
151
- .sa-input-dropdown-container.flushed {
151
+ .sa-input-dropdown-container.sa-input-dropdown-flushed {
152
152
  background-color: transparent;
153
153
  border: none;
154
154
  border-bottom: 1px solid var(--sa-dropdown-border-subtle, var(--sa-border-subtle, rgba(5, 21, 36, 0.1)));
155
155
  border-radius: 0;
156
156
  }
157
- .sa-input-dropdown-container.flushed.active {
157
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.active {
158
158
  border-bottom: 1.2px solid var(--sa-dropdown-border-active, var(--sa-border-focused, #1a4fa0));
159
159
  box-shadow: none;
160
160
  }
161
- .sa-input-dropdown-container.flushed.error {
161
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.error {
162
162
  border-bottom: 1px solid var(--sa-dropdown-border-error-subtle);
163
163
  }
164
- .sa-input-dropdown-container.flushed.disable {
164
+ .sa-input-dropdown-container.sa-input-dropdown-flushed.disable {
165
165
  cursor: not-allowed;
166
166
  pointer-events: none;
167
167
  opacity: 0.6;
@@ -172,18 +172,19 @@
172
172
  display: flex;
173
173
  flex-direction: row;
174
174
  gap: 8px;
175
- align-items: flex-start;
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 — top-aligned with margin so they appear visually
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: flex-start;
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;
@@ -221,8 +234,8 @@
221
234
  color: var(--sa-dropdown-placeholder);
222
235
  font-weight: 400;
223
236
  }
224
- .sa-input-dropdown-container.outline .sa-input-dropdown-placeholder,
225
- .sa-input-dropdown-container.flushed .sa-input-dropdown-placeholder {
237
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-placeholder,
238
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-placeholder {
226
239
  color: var(--sa-dropdown-placeholder-subtle);
227
240
  }
228
241
 
@@ -250,8 +263,8 @@
250
263
  .sa-input-dropdown-trigger-input::placeholder {
251
264
  color: var(--sa-dropdown-placeholder);
252
265
  }
253
- .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
254
- .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
266
+ .sa-input-dropdown-container.sa-input-dropdown-outline .sa-input-dropdown-trigger-input::placeholder,
267
+ .sa-input-dropdown-container.sa-input-dropdown-flushed .sa-input-dropdown-trigger-input::placeholder {
255
268
  color: var(--sa-dropdown-placeholder-subtle);
256
269
  }
257
270
  .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
@@ -584,4 +597,4 @@
584
597
  }
585
598
 
586
599
  } /* @layer starasia.components */
587
- `;function hn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const un=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue: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(un,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(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)}})(fn);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:h})=>{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||!!h,[w,L]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[u,nn]=s.useState(-1),G=s.useId(),ln=u>=0?`${G}-opt-${u}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:f,ref:en,setIsComponentVisible:B}=hn(!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()},[f]),s.useEffect(()=>{if(!f||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[f]),s.useEffect(()=>{f||nn(-1)},[f]);const wn=e=>{if(I){if(!f){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,u,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,u,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),u>=0&&o[u]&&!o[u].disable&&J(o[u].label,o[u].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,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":f,"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),!f&&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:f,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",f?"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:f,"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:f?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:f,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:u,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),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&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):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&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:V,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),on,j&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:j}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "6.1.2",
3
+ "version": "6.1.4",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",