@starasia/dropdown 5.5.4 → 5.5.6

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