@starasia/dropdown 6.0.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,11 @@
1
1
  import { jsxs as l, jsx as n, Fragment as tn } from "react/jsx-runtime";
2
- import dn, { useState as A, useRef as K, useEffect as g, forwardRef as En } from "react";
3
- const zn = `* {
2
+ import sn, { useState as A, useRef as K, useEffect as g, forwardRef as En } from "react";
3
+ const zn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
4
+ starasia, components, utilities). CSS app/Tailwind utility selalu bisa
5
+ menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
6
+ @layer starasia.components {
7
+
8
+ * {
4
9
  margin: 0;
5
10
  padding: 0;
6
11
  font-family: var(--sa-font-family, "Inter", sans-serif);
@@ -199,7 +204,7 @@ const zn = `* {
199
204
  border: 1px solid var(--sa-dropdown-border-subtle);
200
205
  padding-inline: 8px;
201
206
  padding-block: 2px;
202
- border-radius: 4px;
207
+ border-radius: var(--sa-radii-xs, 4px);
203
208
  background-color: var(--sa-dropdown-bg-chip);
204
209
  color: var(--sa-dropdown-brand);
205
210
  height: max-content;
@@ -517,7 +522,7 @@ const zn = `* {
517
522
  align-items: center;
518
523
  padding: 0 8px;
519
524
  border: 1px solid var(--sa-dropdown-border-subtle);
520
- border-radius: 4px;
525
+ border-radius: var(--sa-radii-xs, 4px);
521
526
  background: var(--sa-dropdown-bg-neutral);
522
527
  font-size: 10px;
523
528
  font-weight: 500;
@@ -577,14 +582,15 @@ const zn = `* {
577
582
  display: none;
578
583
  }
579
584
 
585
+ } /* @layer starasia.components */
580
586
  `;
581
587
  function Rn(o) {
582
- const [t, i] = A(o), p = K(null), c = (d) => {
583
- p.current && !p.current.contains(d.target) && i(!1);
588
+ const [i, t] = A(o), p = K(null), c = (s) => {
589
+ p.current && !p.current.contains(s.target) && t(!1);
584
590
  };
585
591
  return g(() => (document.addEventListener("click", c, !0), () => {
586
592
  document.removeEventListener("click", c, !0);
587
- }), []), { ref: p, isComponentVisible: t, setIsComponentVisible: i };
593
+ }), []), { ref: p, isComponentVisible: i, setIsComponentVisible: t };
588
594
  }
589
595
  const Bn = ({ ...o }) => /* @__PURE__ */ l(
590
596
  "svg",
@@ -640,26 +646,26 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
640
646
  ), Ln = En(
641
647
  ({
642
648
  positionDropdown: o,
643
- dropdownLists: t,
644
- isComponentVisible: i,
649
+ dropdownLists: i,
650
+ isComponentVisible: t,
645
651
  searchAble: p,
646
652
  hideSearch: c,
647
- onSearch: d,
648
- value: M,
653
+ onSearch: s,
654
+ value: S,
649
655
  handleChangeValue: F,
650
656
  multiSelect: y,
651
657
  searchValue: k,
652
658
  highlightedIndex: N,
653
- listboxId: O,
654
- footer: $,
659
+ listboxId: M,
660
+ footer: T,
655
661
  groupLabel: C,
656
- onSelectAll: T,
662
+ onSelectAll: $,
657
663
  emptyState: X
658
664
  }, Y) => {
659
- const S = K([]), q = k !== void 0, [Z, Q] = A(""), s = q ? k : Z, H = !t || t.length === 0;
665
+ const O = K([]), q = k !== void 0, [Z, Q] = A(""), d = q ? k : Z, H = !i || i.length === 0;
660
666
  g(() => {
661
667
  var a;
662
- N >= 0 && S.current[N] && ((a = S.current[N]) == null || a.scrollIntoView({ block: "nearest" }));
668
+ N >= 0 && O.current[N] && ((a = O.current[N]) == null || a.scrollIntoView({ block: "nearest" }));
663
669
  }, [N]);
664
670
  const _ = p && !c ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
665
671
  /* @__PURE__ */ n(Bn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
@@ -667,15 +673,15 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
667
673
  "input",
668
674
  {
669
675
  onChange: (a) => {
670
- q || Q(a.target.value), d && d(a.target.value);
676
+ q || Q(a.target.value), s && s(a.target.value);
671
677
  },
672
- value: s,
678
+ value: d,
673
679
  autoFocus: !0,
674
680
  placeholder: "Search..."
675
681
  }
676
682
  )
677
683
  ] }) : null;
678
- return /* @__PURE__ */ n(tn, { children: i ? /* @__PURE__ */ l(
684
+ return /* @__PURE__ */ n(tn, { children: t ? /* @__PURE__ */ l(
679
685
  "div",
680
686
  {
681
687
  className: [
@@ -696,33 +702,33 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
696
702
  {
697
703
  className: `sa-input-dropdown-item-container ${y ? "multi" : ""}`,
698
704
  role: "listbox",
699
- id: O,
705
+ id: M,
700
706
  "aria-multiselectable": y || void 0,
701
707
  children: [
702
- H && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: X ?? (s ? /* @__PURE__ */ l(tn, { children: [
708
+ H && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: X ?? (d ? /* @__PURE__ */ l(tn, { children: [
703
709
  "No results for",
704
710
  " ",
705
711
  /* @__PURE__ */ l("span", { className: "sa-input-dropdown-empty-query", children: [
706
712
  "“",
707
- s,
713
+ d,
708
714
  "”"
709
715
  ] })
710
716
  ] }) : "No data available") }),
711
717
  C && !H && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
712
718
  /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: C }),
713
- y && T && /* @__PURE__ */ n(
719
+ y && $ && /* @__PURE__ */ n(
714
720
  "button",
715
721
  {
716
722
  className: "sa-input-dropdown-section-select-all",
717
723
  onClick: (a) => {
718
- a.stopPropagation(), T();
724
+ a.stopPropagation(), $();
719
725
  },
720
726
  children: "Select all"
721
727
  }
722
728
  )
723
729
  ] }),
724
- t == null ? void 0 : t.map((a, m) => {
725
- const E = !!(M != null && M.find((B) => B.value === a.value)), V = !!a.description;
730
+ i == null ? void 0 : i.map((a, m) => {
731
+ const E = !!(S != null && S.find((B) => B.value === a.value)), V = !!a.description;
726
732
  return /* @__PURE__ */ l(
727
733
  "div",
728
734
  {
@@ -733,17 +739,17 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
733
739
  m === N ? "highlight" : "",
734
740
  a.disable ? "sa-input-dropdown-item-disable" : ""
735
741
  ].filter(Boolean).join(" "),
736
- id: O ? `${O}-opt-${m}` : void 0,
742
+ id: M ? `${M}-opt-${m}` : void 0,
737
743
  role: "option",
738
744
  "aria-selected": E,
739
745
  "aria-disabled": a.disable || void 0,
740
746
  ref: (B) => {
741
- S.current[m] = B;
747
+ O.current[m] = B;
742
748
  },
743
749
  onClick: () => F(a.label, a.value),
744
750
  children: [
745
751
  y && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: E && /* @__PURE__ */ n(Dn, { width: 16 }) }),
746
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: dn.cloneElement(a.icon, { width: 16 }) }),
752
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: sn.cloneElement(a.icon, { width: 16 }) }),
747
753
  /* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
748
754
  /* @__PURE__ */ n(
749
755
  "p",
@@ -774,50 +780,50 @@ const Bn = ({ ...o }) => /* @__PURE__ */ l(
774
780
  ]
775
781
  }
776
782
  ),
777
- $ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: $ })
783
+ T && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: T })
778
784
  ]
779
785
  }
780
786
  ) : null });
781
787
  }
782
788
  ), jn = ({
783
789
  children: o,
784
- handleChangePosition: t,
785
- enabled: i = !0
790
+ handleChangePosition: i,
791
+ enabled: t = !0
786
792
  }) => (g(() => {
787
- if (i)
788
- return window.addEventListener("scroll", t, !0), () => {
789
- window.removeEventListener("scroll", t, !0);
793
+ if (t)
794
+ return window.addEventListener("scroll", i, !0), () => {
795
+ window.removeEventListener("scroll", i, !0);
790
796
  };
791
- }, [i, t]), /* @__PURE__ */ n("div", { children: o })), hn = "sa-input-dropdown-styles", An = (o) => {
797
+ }, [t, i]), /* @__PURE__ */ n("div", { children: o })), hn = "sa-input-dropdown-styles", An = (o) => {
792
798
  if (!(typeof document > "u") && !document.getElementById(hn)) {
793
- const t = document.createElement("style");
794
- t.id = hn, t.textContent = o, document.head.appendChild(t);
799
+ const i = document.createElement("style");
800
+ i.id = hn, i.textContent = o, document.head.appendChild(i);
795
801
  }
796
802
  };
797
803
  An(zn);
798
804
  const Pn = ({
799
805
  dropdownLists: o,
800
- onChange: t,
801
- defaultValue: i,
806
+ onChange: i,
807
+ defaultValue: t,
802
808
  value: p,
803
809
  size: c = "sm",
804
- multiSelect: d,
805
- searchAble: M,
810
+ multiSelect: s,
811
+ searchAble: S,
806
812
  iconLeft: F,
807
813
  placeholder: y,
808
814
  onSearch: k,
809
815
  error: N,
810
- onBlur: O,
811
- onFocus: $,
816
+ onBlur: M,
817
+ onFocus: T,
812
818
  disable: C,
813
- searchValue: T,
819
+ searchValue: $,
814
820
  variant: X = "outline",
815
821
  footer: Y,
816
- groupLabel: S,
822
+ groupLabel: O,
817
823
  onSelectAll: q,
818
824
  emptyState: Z,
819
825
  fullWidth: Q = !0,
820
- triggerInput: s = !1,
826
+ triggerInput: d = !1,
821
827
  clearOnSelect: H = !1,
822
828
  hideChevronIcon: _ = !1,
823
829
  clearable: a = !1,
@@ -826,7 +832,7 @@ const Pn = ({
826
832
  label: E,
827
833
  labelPosition: V = "outside-top",
828
834
  required: B,
829
- optional: sn,
835
+ optional: dn,
830
836
  description: D,
831
837
  helperText: L,
832
838
  errorText: h
@@ -836,39 +842,39 @@ const Pn = ({
836
842
  `sa-select-field-size-${c}`,
837
843
  Q ? "sa-select-field-fullwidth" : ""
838
844
  ].filter(Boolean).join(" "), z = p !== void 0, en = K(), vn = N || !!h, [u, j] = A(
839
- z ? p || [] : i || []
840
- ), [xn, ln] = A(""), [f, on] = A(-1), G = dn.useId(), pn = f >= 0 ? `${G}-opt-${f}` : void 0, [cn, U] = A(
845
+ z ? p || [] : t || []
846
+ ), [xn, ln] = A(""), [f, on] = A(-1), G = sn.useId(), pn = f >= 0 ? `${G}-opt-${f}` : void 0, [cn, U] = A(
841
847
  () => {
842
848
  var e, r;
843
- return !d && (p != null && p.length || i != null && i.length) ? ((e = p == null ? void 0 : p[0]) == null ? void 0 : e.label) ?? ((r = i == null ? void 0 : i[0]) == null ? void 0 : r.label) ?? "" : "";
849
+ return !s && (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) ?? "" : "";
844
850
  }
845
851
  ), v = K(null), { isComponentVisible: w, ref: rn, setIsComponentVisible: R } = Rn(!1), I = o !== void 0, un = u.length > 0, gn = (e) => {
846
852
  e.stopPropagation();
847
853
  const r = [];
848
- z || j(r), t(r), s && U(""), m == null || m();
854
+ z || j(r), i(r), d && U(""), m == null || m();
849
855
  }, mn = () => {
850
856
  I && R((e) => !e);
851
857
  }, J = (e, r) => {
852
- if (d) {
858
+ if (s) {
853
859
  if (u == null ? void 0 : u.find((x) => x.value === r)) {
854
860
  const x = u.filter((Cn) => Cn.value !== r);
855
- z || j(x), t(x);
861
+ z || j(x), i(x);
856
862
  } else {
857
863
  const x = [...u, { label: e, value: r }];
858
- z || j(x), t(x);
864
+ z || j(x), i(x);
859
865
  }
860
- s && U("");
866
+ d && U("");
861
867
  } else {
862
868
  const b = [{ label: e, value: r }];
863
- z || j(b), t(b), s && U(H ? "" : e), R(!1);
869
+ z || j(b), i(b), d && U(H ? "" : e), R(!1);
864
870
  }
865
871
  };
866
872
  g(() => {
867
873
  z && j(p || []);
868
874
  }, [p]), g(() => {
869
- z || JSON.stringify(en.current) === JSON.stringify(i) || (en.current = i, j(en.current || []));
870
- }, [i]);
871
- const yn = () => u.length ? d ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
875
+ z || JSON.stringify(en.current) === JSON.stringify(t) || (en.current = t, j(en.current || []));
876
+ }, [t]);
877
+ const yn = () => u.length ? s ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
872
878
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
873
879
  /* @__PURE__ */ n(
874
880
  bn,
@@ -939,10 +945,10 @@ const Pn = ({
939
945
  tabIndex: -1,
940
946
  onClick: gn,
941
947
  onMouseDown: (e) => e.preventDefault(),
942
- children: /* @__PURE__ */ n(Mn, { width: P, height: P })
948
+ children: /* @__PURE__ */ n(Sn, { width: P, height: P })
943
949
  }
944
- ) : null, Nn = s ? /* @__PURE__ */ l(tn, { children: [
945
- d && u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
950
+ ) : null, Nn = d ? /* @__PURE__ */ l(tn, { children: [
951
+ s && u.map((e, r) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
946
952
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
947
953
  /* @__PURE__ */ n(
948
954
  bn,
@@ -972,10 +978,10 @@ const Pn = ({
972
978
  !C && I && R(!0);
973
979
  },
974
980
  onBlur: () => {
975
- d || setTimeout(() => R(!1), 150);
981
+ s || setTimeout(() => R(!1), 150);
976
982
  },
977
983
  onKeyDown: wn,
978
- placeholder: u.length === 0 || d ? y : void 0,
984
+ placeholder: u.length === 0 || s ? y : void 0,
979
985
  disabled: C
980
986
  }
981
987
  )
@@ -991,31 +997,31 @@ const Pn = ({
991
997
  "sa-input-dropdown-container",
992
998
  X,
993
999
  `sa-input-dropdown-size-${c}`,
994
- s ? "trigger-input" : "",
1000
+ d ? "trigger-input" : "",
995
1001
  w ? "active" : "",
996
1002
  vn ? "error" : "",
997
1003
  C ? "disable" : ""
998
1004
  ].filter(Boolean).join(" "),
999
1005
  ref: rn,
1000
- role: s ? void 0 : "combobox",
1001
- "aria-haspopup": s ? void 0 : "listbox",
1002
- "aria-expanded": s ? void 0 : w,
1003
- "aria-controls": s ? void 0 : G,
1004
- "aria-activedescendant": s ? void 0 : pn,
1005
- onClick: s ? void 0 : mn,
1006
- onKeyDown: s ? void 0 : wn,
1007
- tabIndex: s ? void 0 : 0,
1008
- onBlur: s ? void 0 : O,
1009
- onFocus: s ? void 0 : $,
1006
+ role: d ? void 0 : "combobox",
1007
+ "aria-haspopup": d ? void 0 : "listbox",
1008
+ "aria-expanded": d ? void 0 : w,
1009
+ "aria-controls": d ? void 0 : G,
1010
+ "aria-activedescendant": d ? void 0 : pn,
1011
+ onClick: d ? void 0 : mn,
1012
+ onKeyDown: d ? void 0 : wn,
1013
+ tabIndex: d ? void 0 : 0,
1014
+ onBlur: d ? void 0 : M,
1015
+ onFocus: d ? void 0 : T,
1010
1016
  children: [
1011
1017
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
1012
- F ? dn.cloneElement(F, {
1018
+ F ? sn.cloneElement(F, {
1013
1019
  width: P,
1014
1020
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
1015
1021
  }) : null,
1016
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: s ? Nn : yn() }),
1022
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: d ? Nn : yn() }),
1017
1023
  kn,
1018
- !_ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(Sn, { width: P }) : /* @__PURE__ */ n(On, { width: P }) })
1024
+ !_ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(On, { width: P }) : /* @__PURE__ */ n(Mn, { width: P }) })
1019
1025
  ] }),
1020
1026
  I && /* @__PURE__ */ n(
1021
1027
  Ln,
@@ -1025,16 +1031,16 @@ const Pn = ({
1025
1031
  isComponentVisible: w,
1026
1032
  listboxId: G,
1027
1033
  positionDropdown: xn,
1028
- searchAble: !!M,
1029
- hideSearch: s,
1034
+ searchAble: !!S,
1035
+ hideSearch: d,
1030
1036
  value: u,
1031
1037
  onSearch: k,
1032
1038
  ref: v,
1033
- multiSelect: d,
1034
- searchValue: s ? cn : T,
1039
+ multiSelect: s,
1040
+ searchValue: d ? cn : $,
1035
1041
  highlightedIndex: f,
1036
1042
  footer: Y,
1037
- groupLabel: S,
1043
+ groupLabel: O,
1038
1044
  onSelectAll: q,
1039
1045
  emptyState: Z
1040
1046
  }
@@ -1048,7 +1054,7 @@ const Pn = ({
1048
1054
  /* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
1049
1055
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
1050
1056
  /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: E }),
1051
- sn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1057
+ dn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1052
1058
  B && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1053
1059
  ] }),
1054
1060
  D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D })
@@ -1061,7 +1067,7 @@ const Pn = ({
1061
1067
  ] }) : /* @__PURE__ */ l("div", { className: nn, children: [
1062
1068
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
1063
1069
  /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: E }),
1064
- sn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1070
+ dn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1065
1071
  B && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1066
1072
  ] }),
1067
1073
  D && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: D }),
@@ -1074,24 +1080,24 @@ const Pn = ({
1074
1080
  L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1075
1081
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1076
1082
  ] });
1077
- }, fn = (o, t, i) => {
1083
+ }, fn = (o, i, t) => {
1078
1084
  const p = o.length;
1079
- let c = t + i;
1085
+ let c = i + t;
1080
1086
  for (; c >= 0 && c < p; ) {
1081
1087
  if (!o[c].disable)
1082
1088
  return c;
1083
- c += i;
1089
+ c += t;
1084
1090
  }
1085
- if (i === 1) {
1086
- for (let d = 0; d < p; d++)
1087
- if (!o[d].disable)
1088
- return d;
1091
+ if (t === 1) {
1092
+ for (let s = 0; s < p; s++)
1093
+ if (!o[s].disable)
1094
+ return s;
1089
1095
  } else
1090
- for (let d = p - 1; d >= 0; d--)
1091
- if (!o[d].disable)
1092
- return d;
1096
+ for (let s = p - 1; s >= 0; s--)
1097
+ if (!o[s].disable)
1098
+ return s;
1093
1099
  return -1;
1094
- }, Mn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1100
+ }, Sn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1095
1101
  /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1096
1102
  /* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
1097
1103
  ] }), bn = (o) => /* @__PURE__ */ n(
@@ -1115,7 +1121,7 @@ const Pn = ({
1115
1121
  }
1116
1122
  )
1117
1123
  }
1118
- ), On = ({ width: o = 16 }) => /* @__PURE__ */ n(
1124
+ ), Mn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1119
1125
  "svg",
1120
1126
  {
1121
1127
  xmlns: "http://www.w3.org/2000/svg",
@@ -1135,7 +1141,7 @@ const Pn = ({
1135
1141
  }
1136
1142
  )
1137
1143
  }
1138
- ), Sn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1144
+ ), On = ({ width: o = 16 }) => /* @__PURE__ */ n(
1139
1145
  "svg",
1140
1146
  {
1141
1147
  xmlns: "http://www.w3.org/2000/svg",
@@ -1,4 +1,9 @@
1
- (function(g,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const hn=`* {
1
+ (function(g,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,s){"use strict";const hn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
2
+ starasia, components, utilities). CSS app/Tailwind utility selalu bisa
3
+ menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
4
+ @layer starasia.components {
5
+
6
+ * {
2
7
  margin: 0;
3
8
  padding: 0;
4
9
  font-family: var(--sa-font-family, "Inter", sans-serif);
@@ -197,7 +202,7 @@
197
202
  border: 1px solid var(--sa-dropdown-border-subtle);
198
203
  padding-inline: 8px;
199
204
  padding-block: 2px;
200
- border-radius: 4px;
205
+ border-radius: var(--sa-radii-xs, 4px);
201
206
  background-color: var(--sa-dropdown-bg-chip);
202
207
  color: var(--sa-dropdown-brand);
203
208
  height: max-content;
@@ -515,7 +520,7 @@
515
520
  align-items: center;
516
521
  padding: 0 8px;
517
522
  border: 1px solid var(--sa-dropdown-border-subtle);
518
- border-radius: 4px;
523
+ border-radius: var(--sa-radii-xs, 4px);
519
524
  background: var(--sa-dropdown-bg-neutral);
520
525
  font-size: 10px;
521
526
  font-weight: 500;
@@ -575,4 +580,5 @@
575
580
  display: none;
576
581
  }
577
582
 
578
- `;function fn(o){const[d,t]=s.useState(o),p=s.useRef(null),c=i=>{p.current&&!p.current.contains(i.target)&&t(!1)};return s.useEffect(()=>(document.addEventListener("click",c,!0),()=>{document.removeEventListener("click",c,!0)}),[]),{ref:p,isComponentVisible:d,setIsComponentVisible:t}}const un=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),vn=s.forwardRef(({positionDropdown:o,dropdownLists:d,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:i,value:A,handleChangeValue:W,multiSelect:y,searchValue:k,highlightedIndex:N,listboxId:M,footer:T,groupLabel:E,onSelectAll:$,emptyState:K},X)=>{const O=s.useRef([]),q=k!==void 0,[Y,Z]=s.useState(""),l=q?k:Y,H=!d||d.length===0;s.useEffect(()=>{var a;N>=0&&O.current[N]&&((a=O.current[N])==null||a.scrollIntoView({block:"nearest"}))},[N]);const Q=p&&!c?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(un,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{q||Z(a.target.value),i&&i(a.target.value)},value:l,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:X,children:[Q,n.jsxs("div",{className:`sa-input-dropdown-item-container ${y?"multi":""}`,role:"listbox",id:M,"aria-multiselectable":y||void 0,children:[H&&n.jsx("div",{className:"sa-input-dropdown-empty",children:K??(l?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",l,"”"]})]}):"No data available")}),E&&!H&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:E}),y&&$&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),$()},children:"Select all"})]}),d==null?void 0:d.map((a,m)=>{const C=!!(A!=null&&A.find(D=>D.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:D=>{O.current[m]=D},onClick:()=>W(a.label,a.value),children:[y&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:C&&n.jsx(bn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},m)})]}),T&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:T})]}):null})}),xn=({children:o,handleChangePosition:d,enabled:t=!0})=>(s.useEffect(()=>{if(t)return window.addEventListener("scroll",d,!0),()=>{window.removeEventListener("scroll",d,!0)}},[t,d]),n.jsx("div",{children:o})),rn="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(rn)){const d=document.createElement("style");d.id=rn,d.textContent=o,document.head.appendChild(d)}})(hn);const gn=({dropdownLists:o,onChange:d,defaultValue:t,value:p,size:c="sm",multiSelect:i,searchAble:A,iconLeft:W,placeholder:y,onSearch:k,error:N,onBlur:M,onFocus:T,disable:E,searchValue:$,variant:K="outline",footer:X,groupLabel:O,onSelectAll:q,emptyState:Y,fullWidth:Z=!0,triggerInput:l=!1,clearOnSelect:H=!1,hideChevronIcon:Q=!1,clearable:a=!1,onClear:m,label:C,labelPosition:_="outside-top",required:D,optional:dn,description:S,helperText:L,errorText:f})=>{const V=["sa-select-field",`sa-select-field-size-${c}`,Z?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),z=p!==void 0,R=s.useRef(),Nn=N||!!f,[w,j]=s.useState(z?p||[]:t||[]),[En,tn]=s.useState(""),[u,nn]=s.useState(-1),G=s.useId(),ln=u>=0?`${G}-opt-${u}`:void 0,[pn,U]=s.useState(()=>{var e,r;return!i&&(p!=null&&p.length||t!=null&&t.length)?((e=p==null?void 0:p[0])==null?void 0:e.label)??((r=t==null?void 0:t[0])==null?void 0:r.label)??"":""}),v=s.useRef(null),{isComponentVisible:h,ref:en,setIsComponentVisible:B}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||j(r),d(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(i){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(Ln=>Ln.value!==r);z||j(x),d(x)}else{const x=[...w,{label:e,value:r}];z||j(x),d(x)}l&&U("")}else{const b=[{label:e,value:r}];z||j(b),d(b),l&&U(H?"":e),B(!1)}};s.useEffect(()=>{z&&j(p||[])},[p]),s.useEffect(()=>{z||JSON.stringify(R.current)===JSON.stringify(t)||(R.current=t,j(R.current||[]))},[t]);const Bn=()=>w.length?i?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:y}),F=()=>{if(en.current&&v.current){const e=window.innerHeight,r=en.current.getBoundingClientRect(),b=v.current.getBoundingClientRect(),x=r.bottom+b.height;v.current.style.left=`${r.left}px`,v.current.style.width=`${r.width}px`,x>=e-10?(v.current.style.top=`${r.top-b.height-5}px`,tn("top")):(v.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[h]),s.useEffect(()=>{if(!h||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||nn(-1)},[h]);const wn=e=>{if(I){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,u,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,u,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),u>=0&&o[u]&&!o[u].disable&&J(o[u].label,o[u].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Dn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Sn=l?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(sn,{onClick:b=>{b.stopPropagation(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":h,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!h&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{i||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||i?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:h,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",h?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:h,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0:T,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[W?s.cloneElement(W,{width:P,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:l?Sn:Bn()}),Dn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:h?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:h,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:i,searchValue:l?pn:$,highlightedIndex:u,footer:X,groupLabel:O,onSelectAll:q,emptyState:Y})]})});return C?_==="outside-left"?n.jsxs("div",{className:`${V} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:V,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:C}),dn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:V,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),on,L&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:L}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},an=(o,d,t)=>{const p=o.length;let c=d+t;for(;c>=0&&c<p;){if(!o[c].disable)return c;c+=t}if(t===1){for(let i=0;i<p;i++)if(!o[i].disable)return i}else for(let i=p-1;i>=0;i--)if(!o[i].disable)return i;return-1},mn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),sn=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),yn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),kn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});g.Dropdown=gn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
583
+ } /* @layer starasia.components */
584
+ `;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 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:i,isComponentVisible:t,searchAble:p,hideSearch:c,onSearch:d,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=!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(un,{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 ${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"})]}),i==null?void 0:i.map((a,m)=>{const C=!!(A!=null&&A.find(D=>D.value===a.value)),_=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",_?"has-description":"",C?"active":"",m===N?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),id:M?`${M}-opt-${m}`:void 0,role:"option","aria-selected":C,"aria-disabled":a.disable||void 0,ref:D=>{O.current[m]=D},onClick:()=>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: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)}})(hn);const gn=({dropdownLists:o,onChange:i,defaultValue:t,value:p,size:c="sm",multiSelect:d,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:D,optional:tn,description:S,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,dn]=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!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:h,ref:en,setIsComponentVisible:B}=fn(!1),I=o!==void 0,cn=w.length>0,Cn=e=>{e.stopPropagation();const r=[];z||L(r),i(r),l&&U(""),m==null||m()},zn=()=>{I&&B(e=>!e)},J=(e,r)=>{if(d){if(w==null?void 0:w.find(x=>x.value===r)){const x=w.filter(jn=>jn.value!==r);z||L(x),i(x)}else{const x=[...w,{label:e,value:r}];z||L(x),i(x)}l&&U("")}else{const b=[{label:e,value:r}];z||L(b),i(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?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(),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`,dn("top")):(v.current.style.top=`${r.top+r.height+4}px`,dn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[h]),s.useEffect(()=>{if(!h||!v.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(v.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||nn(-1)},[h]);const wn=e=>{if(I){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),B(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=an(o,u,1);r!==-1&&nn(r);break}case"ArrowUp":{e.preventDefault();const r=an(o,u,-1);r!==-1&&nn(r);break}case"Enter":{e.preventDefault(),u>=0&&o[u]&&!o[u].disable&&J(o[u].label,o[u].value);break}case"Escape":B(!1);break}}},P=c==="lg"||c==="xl"?20:c==="xs"?14:16,Dn=a&&!E?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${cn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!cn,tabIndex:-1,onClick:Cn,onMouseDown:e=>e.preventDefault(),children:n.jsx(mn,{width:P,height:P})}):null,Sn=l?n.jsxs(n.Fragment,{children:[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(),J(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",role:"combobox","aria-expanded":h,"aria-haspopup":"listbox","aria-controls":G,"aria-activedescendant":ln,"aria-autocomplete":"list",value:pn,onChange:e=>{const r=e.target.value;U(r),k==null||k(r),!h&&I&&B(!0)},onFocus:()=>{!E&&I&&B(!0)},onBlur:()=>{d||setTimeout(()=>B(!1),150)},onKeyDown:wn,placeholder:w.length===0||d?y:void 0,disabled:E})]}):null,on=n.jsx(xn,{handleChangePosition:F,enabled:h,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${c}`,l?"trigger-input":"",h?"active":"",Nn?"error":"",E?"disable":""].filter(Boolean).join(" "),ref:en,role:l?void 0:"combobox","aria-haspopup":l?void 0:"listbox","aria-expanded":l?void 0:h,"aria-controls":l?void 0:G,"aria-activedescendant":l?void 0:ln,onClick:l?void 0:zn,onKeyDown:l?void 0:wn,tabIndex:l?void 0:0,onBlur:l?void 0:M,onFocus:l?void 0: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?Sn:Bn()}),Dn,!Q&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:h?n.jsx(kn,{width:P}):n.jsx(yn,{width:P})})]}),I&&n.jsx(vn,{dropdownLists:o,handleChangeValue:J,isComponentVisible:h,listboxId:G,positionDropdown:En,searchAble:!!A,hideSearch:l,value:w,onSearch:k,ref:v,multiSelect:d,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}),tn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[on,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}),tn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),D&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),on,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:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),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"})}),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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",