@starasia/dropdown 5.5.3 → 5.5.5

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,26 @@
1
1
  import React, { ReactNode } from "react";
2
- declare const ScrollAwareWrapper: ({ children, handleChangePosition, }: {
2
+ /**
3
+ * Keeps a `position: fixed` popover glued to its trigger while ANY ancestor —
4
+ * the window or a nested scroll container — scrolls.
5
+ *
6
+ * Scroll events do not bubble, so listening on a single "scrollable parent"
7
+ * misses scrolls from other containers. The previous implementation also
8
+ * detected that parent with a heuristic (`scrollHeight > clientHeight ||
9
+ * scrollWidth > clientWidth`) that matched any ancestor whose content merely
10
+ * *overflowed* its box rather than one that actually scrolls — so it frequently
11
+ * latched onto a static element whose `scroll` event never fires, leaving the
12
+ * popover frozen while the real container scrolled. (This is why two dropdowns
13
+ * in the same toolbar could behave differently: whichever one happened to have
14
+ * an overflowing ancestor in its chain stopped tracking.)
15
+ *
16
+ * Listening on `window` in the capture phase sidesteps both problems: capture
17
+ * runs from the top of the propagation path, so the handler receives scroll
18
+ * events from every descendant scroll container regardless of overflow style.
19
+ * Gated by `enabled` so the listener is only active while the panel is open.
20
+ */
21
+ declare const ScrollAwareWrapper: ({ children, handleChangePosition, enabled, }: {
3
22
  children: ReactNode;
4
23
  handleChangePosition: () => void;
24
+ enabled?: boolean | undefined;
5
25
  }) => React.JSX.Element;
6
26
  export default ScrollAwareWrapper;
@@ -1,5 +1,5 @@
1
- import { jsxs as l, jsx as n, Fragment as dn } from "react/jsx-runtime";
2
- import ln, { useState as M, useRef as S, useEffect as v, forwardRef as yn } from "react";
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";
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;
@@ -546,15 +546,15 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
546
546
  }
547
547
 
548
548
  `;
549
- function En(o) {
550
- const [p, s] = M(o), d = S(null), i = (r) => {
551
- d.current && !d.current.contains(r.target) && s(!1);
549
+ function Cn(o) {
550
+ const [l, i] = P(o), s = G(null), p = (t) => {
551
+ s.current && !s.current.contains(t.target) && i(!1);
552
552
  };
553
- return v(() => (document.addEventListener("click", i, !0), () => {
554
- document.removeEventListener("click", i, !0);
555
- }), []), { ref: d, isComponentVisible: p, setIsComponentVisible: s };
553
+ return x(() => (document.addEventListener("click", p, !0), () => {
554
+ document.removeEventListener("click", p, !0);
555
+ }), []), { ref: s, isComponentVisible: l, setIsComponentVisible: i };
556
556
  }
557
- const Cn = ({ ...o }) => /* @__PURE__ */ l(
557
+ const En = ({ ...o }) => /* @__PURE__ */ d(
558
558
  "svg",
559
559
  {
560
560
  xmlns: "http://www.w3.org/2000/svg",
@@ -608,285 +608,270 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
608
608
  ), Rn = yn(
609
609
  ({
610
610
  positionDropdown: o,
611
- dropdownLists: p,
612
- isComponentVisible: s,
613
- searchAble: d,
614
- hideSearch: i,
615
- onSearch: r,
616
- value: m,
617
- handleChangeValue: u,
618
- multiSelect: R,
619
- searchValue: L,
620
- highlightedIndex: y,
611
+ dropdownLists: l,
612
+ isComponentVisible: i,
613
+ searchAble: s,
614
+ hideSearch: p,
615
+ onSearch: t,
616
+ value: L,
617
+ handleChangeValue: W,
618
+ multiSelect: C,
619
+ searchValue: E,
620
+ highlightedIndex: m,
621
621
  footer: F,
622
- groupLabel: T,
623
- onSelectAll: N
622
+ groupLabel: S,
623
+ onSelectAll: k
624
624
  }, U) => {
625
- const A = S([]);
626
- v(() => {
627
- var t;
628
- y >= 0 && A.current[y] && ((t = A.current[y]) == null || t.scrollIntoView({ block: "nearest" }));
629
- }, [y]);
630
- const $ = d && !i ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
631
- /* @__PURE__ */ n(Cn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
625
+ const D = G([]);
626
+ x(() => {
627
+ 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: [
631
+ /* @__PURE__ */ n(En, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
632
632
  /* @__PURE__ */ n(
633
633
  "input",
634
634
  {
635
- onChange: (t) => {
636
- r && r(t.target.value);
635
+ onChange: (a) => {
636
+ t && t(a.target.value);
637
637
  },
638
- value: L,
638
+ value: E,
639
639
  autoFocus: !0,
640
640
  placeholder: "Search..."
641
641
  }
642
642
  )
643
643
  ] }) : null;
644
- return /* @__PURE__ */ n(dn, { children: s ? /* @__PURE__ */ l(
644
+ return /* @__PURE__ */ n(dn, { children: i ? /* @__PURE__ */ d(
645
645
  "div",
646
646
  {
647
647
  className: "sa-input-dropdown-lists-container",
648
- onClick: (t) => t.stopPropagation(),
648
+ onClick: (a) => a.stopPropagation(),
649
649
  ref: U,
650
650
  children: [
651
- o !== "top" && $,
652
- /* @__PURE__ */ l(
651
+ o !== "top" && T,
652
+ /* @__PURE__ */ d(
653
653
  "div",
654
654
  {
655
- className: `sa-input-dropdown-item-container ${R ? "multi" : ""}`,
655
+ className: `sa-input-dropdown-item-container ${C ? "multi" : ""}`,
656
656
  children: [
657
- T && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
658
- /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: T }),
659
- R && N && /* @__PURE__ */ n(
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(
660
660
  "button",
661
661
  {
662
662
  className: "sa-input-dropdown-section-select-all",
663
- onClick: (t) => {
664
- t.stopPropagation(), N();
663
+ onClick: (a) => {
664
+ a.stopPropagation(), k();
665
665
  },
666
666
  children: "Select all"
667
667
  }
668
668
  )
669
669
  ] }),
670
- p.map((t, P) => {
671
- const H = !!(m != null && m.find((I) => I.value === t.value)), w = !!t.description;
672
- return /* @__PURE__ */ l(
670
+ l.map((a, j) => {
671
+ const $ = !!(L != null && L.find((A) => A.value === a.value)), u = !!a.description;
672
+ return /* @__PURE__ */ d(
673
673
  "div",
674
674
  {
675
675
  className: [
676
676
  "sa-input-dropdown-item",
677
- w ? "has-description" : "",
678
- H ? "active" : "",
679
- P === y ? "highlight" : "",
680
- t.disable ? "sa-input-dropdown-item-disable" : ""
677
+ u ? "has-description" : "",
678
+ $ ? "active" : "",
679
+ j === m ? "highlight" : "",
680
+ a.disable ? "sa-input-dropdown-item-disable" : ""
681
681
  ].filter(Boolean).join(" "),
682
- ref: (I) => {
683
- A.current[P] = I;
682
+ ref: (A) => {
683
+ D.current[j] = A;
684
684
  },
685
- onClick: () => u(t.label, t.value),
685
+ onClick: () => W(a.label, a.value),
686
686
  children: [
687
- R && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: H && /* @__PURE__ */ n(zn, { width: 16 }) }),
688
- t.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: ln.cloneElement(t.icon, { width: 16 }) }),
689
- /* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, 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 }) }),
689
+ /* @__PURE__ */ d("div", { style: { minWidth: 0, flex: 1 }, children: [
690
690
  /* @__PURE__ */ n(
691
691
  "p",
692
692
  {
693
693
  className: [
694
694
  "sa-input-dropdown-item-text",
695
- t.disable ? "sa-input-dropdown-item-disable" : ""
695
+ a.disable ? "sa-input-dropdown-item-disable" : ""
696
696
  ].filter(Boolean).join(" "),
697
- children: t.label
697
+ children: a.label
698
698
  }
699
699
  ),
700
- t.description && /* @__PURE__ */ n(
700
+ a.description && /* @__PURE__ */ n(
701
701
  "p",
702
702
  {
703
703
  className: [
704
704
  "sa-input-dropdown-item-text-description",
705
- t.disable ? "sa-input-dropdown-item-disable" : ""
705
+ a.disable ? "sa-input-dropdown-item-disable" : ""
706
706
  ].filter(Boolean).join(" "),
707
- children: t.description
707
+ children: a.description
708
708
  }
709
709
  )
710
710
  ] })
711
711
  ]
712
712
  },
713
- P
713
+ j
714
714
  );
715
715
  })
716
716
  ]
717
717
  }
718
718
  ),
719
- o === "top" && $,
720
- F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (t) => t.stopPropagation(), children: F })
719
+ o === "top" && T,
720
+ F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: F })
721
721
  ]
722
722
  }
723
723
  ) : null });
724
724
  }
725
- ), Ln = ({
725
+ ), Bn = ({
726
726
  children: o,
727
- handleChangePosition: p
728
- }) => {
729
- const s = S(null);
730
- v(() => {
731
- var m;
732
- const i = () => {
733
- if (s.current) {
734
- let u = s.current.parentElement;
735
- for (; u && !d(u); )
736
- u = u.parentElement;
737
- u && p();
738
- }
727
+ handleChangePosition: l,
728
+ enabled: i = !0
729
+ }) => (x(() => {
730
+ if (i)
731
+ return window.addEventListener("scroll", l, !0), () => {
732
+ window.removeEventListener("scroll", l, !0);
739
733
  };
740
- let r = (m = s.current) == null ? void 0 : m.parentElement;
741
- for (; r && !d(r); )
742
- r = r.parentElement;
743
- return r && r.addEventListener("scroll", i), i(), () => {
744
- r && r.removeEventListener("scroll", i);
745
- };
746
- }, []);
747
- const d = (i) => i && (i.scrollHeight > i.clientHeight || i.scrollWidth > i.clientWidth);
748
- return /* @__PURE__ */ n("div", { ref: s, children: o });
749
- }, an = "sa-input-dropdown-styles", Bn = (o) => {
734
+ }, [i, l]), /* @__PURE__ */ n("div", { children: o })), an = "sa-input-dropdown-styles", Ln = (o) => {
750
735
  if (!(typeof document > "u") && !document.getElementById(an)) {
751
- const p = document.createElement("style");
752
- p.id = an, p.textContent = o, document.head.appendChild(p);
736
+ const l = document.createElement("style");
737
+ l.id = an, l.textContent = o, document.head.appendChild(l);
753
738
  }
754
739
  };
755
- Bn(Nn);
756
- const On = ({
740
+ Ln(Nn);
741
+ const Mn = ({
757
742
  dropdownLists: o,
758
- onChange: p,
759
- defaultValue: s,
760
- value: d,
761
- size: i = "sm",
762
- multiSelect: r,
763
- searchAble: m,
764
- iconLeft: u,
765
- placeholder: R,
766
- onSearch: L,
767
- error: y,
743
+ onChange: l,
744
+ defaultValue: i,
745
+ value: s,
746
+ size: p = "sm",
747
+ multiSelect: t,
748
+ searchAble: L,
749
+ iconLeft: W,
750
+ placeholder: C,
751
+ onSearch: E,
752
+ error: m,
768
753
  onBlur: F,
769
- onFocus: T,
770
- disable: N,
754
+ onFocus: S,
755
+ disable: k,
771
756
  searchValue: U,
772
- variant: A = "outline",
773
- footer: $,
774
- groupLabel: t,
775
- onSelectAll: P,
776
- fullWidth: H = !0,
777
- triggerInput: w = !1,
778
- clearOnSelect: I = !1,
757
+ variant: D = "outline",
758
+ footer: T,
759
+ groupLabel: a,
760
+ onSelectAll: j,
761
+ fullWidth: $ = !0,
762
+ triggerInput: u = !1,
763
+ clearOnSelect: A = !1,
779
764
  hideChevronIcon: pn = !1,
780
765
  clearable: cn = !1,
781
766
  onClear: K,
782
767
  /* field wrapper */
783
768
  label: J,
784
- labelPosition: wn = "outside-top",
769
+ labelPosition: un = "outside-top",
785
770
  required: V,
786
771
  optional: nn,
787
- description: B,
788
- helperText: D,
772
+ description: z,
773
+ helperText: R,
789
774
  errorText: h
790
775
  }) => {
791
776
  const Z = [
792
777
  "sa-select-field",
793
- `sa-select-field-size-${i}`,
794
- H ? "sa-select-field-fullwidth" : ""
795
- ].filter(Boolean).join(" "), E = d !== void 0, Q = S(), un = y || !!h, [c, j] = M(
796
- E ? d || [] : s || []
797
- ), [hn, en] = M(""), [k, X] = M(-1), [fn, q] = M(
778
+ `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(
798
783
  () => {
799
- var e, a;
800
- return !r && (d != null && d.length || s != null && s.length) ? ((e = d == null ? void 0 : d[0]) == null ? void 0 : e.label) ?? ((a = s == null ? void 0 : s[0]) == null ? void 0 : a.label) ?? "" : "";
784
+ 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) ?? "" : "";
801
786
  }
802
- ), g = S(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), O = o !== void 0, on = c.length > 0, bn = (e) => {
787
+ ), b = G(null), { isComponentVisible: w, ref: Y, setIsComponentVisible: N } = Cn(!1), I = o !== void 0, on = c.length > 0, bn = (e) => {
803
788
  e.stopPropagation();
804
- const a = [];
805
- E || j(a), p(a), w && q(""), K == null || K();
789
+ const r = [];
790
+ y || B(r), l(r), u && q(""), K == null || K();
806
791
  }, gn = () => {
807
- O && C((e) => !e);
808
- }, G = (e, a) => {
809
- if (r) {
810
- if (c == null ? void 0 : c.find((x) => x.value === a)) {
811
- const x = c.filter((kn) => kn.value !== a);
812
- E || j(x), p(x);
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);
813
798
  } else {
814
- const x = [...c, { label: e, value: a }];
815
- E || j(x), p(x);
799
+ const g = [...c, { label: e, value: r }];
800
+ y || B(g), l(g);
816
801
  }
817
- w && q("");
802
+ u && q("");
818
803
  } else {
819
- const b = [{ label: e, value: a }];
820
- E || j(b), p(b), w && q(I ? "" : e), C(!1);
804
+ const f = [{ label: e, value: r }];
805
+ y || B(f), l(f), u && q(A ? "" : e), N(!1);
821
806
  }
822
807
  };
823
- v(() => {
824
- E && j(d || []);
825
- }, [d]), v(() => {
826
- E || JSON.stringify(Q.current) === JSON.stringify(s) || (Q.current = s, j(Q.current || []));
827
- }, [s]);
828
- const xn = () => c.length ? r ? c == null ? void 0 : c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
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: [
829
814
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
830
815
  /* @__PURE__ */ n(
831
816
  sn,
832
817
  {
833
- onClick: (b) => {
834
- b.stopPropagation(), G(e.label, e.value);
818
+ onClick: (f) => {
819
+ f.stopPropagation(), H(e.label, e.value);
835
820
  }
836
821
  }
837
822
  )
838
- ] }, a)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: R }), z = () => {
839
- if (Y.current && g.current) {
840
- const e = window.innerHeight, a = Y.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), x = a.bottom + b.height;
841
- g.current.style.left = `${a.left}px`, g.current.style.width = `${a.width}px`, x >= e - 10 ? (g.current.style.top = `${a.top - b.height - 5}px`, en("top")) : (g.current.style.top = `${a.top + a.height + 4}px`, en("bottom"));
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"));
842
827
  }
843
828
  };
844
- v(() => (window.addEventListener("scroll", z), window.addEventListener("resize", z), () => {
845
- window.removeEventListener("scroll", z), window.removeEventListener("resize", z);
846
- }), []), v(() => {
847
- z();
848
- }, [f]), v(() => {
849
- if (!f || !g.current)
829
+ x(() => (window.addEventListener("resize", O), () => {
830
+ window.removeEventListener("resize", O);
831
+ }), []), x(() => {
832
+ O();
833
+ }, [w]), x(() => {
834
+ if (!w || !b.current)
850
835
  return;
851
836
  const e = new ResizeObserver(() => {
852
- z();
837
+ O();
853
838
  });
854
- return e.observe(g.current), () => e.disconnect();
855
- }, [f]), v(() => {
856
- f || X(-1);
857
- }, [f]);
839
+ return e.observe(b.current), () => e.disconnect();
840
+ }, [w]), x(() => {
841
+ w || X(-1);
842
+ }, [w]);
858
843
  const rn = (e) => {
859
- if (O) {
860
- if (!f) {
861
- (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
844
+ if (I) {
845
+ if (!w) {
846
+ (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), N(!0));
862
847
  return;
863
848
  }
864
849
  switch (e.key) {
865
850
  case "ArrowDown": {
866
851
  e.preventDefault();
867
- const a = tn(o, k, 1);
868
- a !== -1 && X(a);
852
+ const r = tn(o, v, 1);
853
+ r !== -1 && X(r);
869
854
  break;
870
855
  }
871
856
  case "ArrowUp": {
872
857
  e.preventDefault();
873
- const a = tn(o, k, -1);
874
- a !== -1 && X(a);
858
+ const r = tn(o, v, -1);
859
+ r !== -1 && X(r);
875
860
  break;
876
861
  }
877
862
  case "Enter": {
878
- e.preventDefault(), k >= 0 && o[k] && !o[k].disable && G(
879
- o[k].label,
880
- o[k].value
863
+ e.preventDefault(), v >= 0 && o[v] && !o[v].disable && H(
864
+ o[v].label,
865
+ o[v].value
881
866
  );
882
867
  break;
883
868
  }
884
869
  case "Escape":
885
- C(!1);
870
+ N(!1);
886
871
  break;
887
872
  }
888
873
  }
889
- }, W = i === "lg" || i === "xl" ? 20 : i === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
874
+ }, M = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, vn = cn && !k ? /* @__PURE__ */ n(
890
875
  "button",
891
876
  {
892
877
  type: "button",
@@ -896,139 +881,146 @@ const On = ({
896
881
  tabIndex: -1,
897
882
  onClick: bn,
898
883
  onMouseDown: (e) => e.preventDefault(),
899
- children: /* @__PURE__ */ n(Dn, { width: W, height: W })
884
+ children: /* @__PURE__ */ n(Dn, { width: M, height: M })
900
885
  }
901
- ) : null, mn = w ? /* @__PURE__ */ l(dn, { children: [
902
- r && c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
886
+ ) : null, mn = u ? /* @__PURE__ */ d(dn, { children: [
887
+ t && c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
903
888
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
904
889
  /* @__PURE__ */ n(
905
890
  sn,
906
891
  {
907
- onClick: (b) => {
908
- b.stopPropagation(), G(e.label, e.value);
892
+ onClick: (f) => {
893
+ f.stopPropagation(), H(e.label, e.value);
909
894
  }
910
895
  }
911
896
  )
912
- ] }, a)),
897
+ ] }, r)),
913
898
  /* @__PURE__ */ n(
914
899
  "input",
915
900
  {
916
901
  className: "sa-input-dropdown-trigger-input",
917
902
  value: fn,
918
903
  onChange: (e) => {
919
- const a = e.target.value;
920
- q(a), L == null || L(a), !f && O && C(!0);
904
+ const r = e.target.value;
905
+ q(r), E == null || E(r), !w && I && N(!0);
921
906
  },
922
907
  onFocus: () => {
923
- !N && O && C(!0);
908
+ !k && I && N(!0);
924
909
  },
925
910
  onBlur: () => {
926
- r || setTimeout(() => C(!1), 150);
911
+ t || setTimeout(() => N(!1), 150);
927
912
  },
928
913
  onKeyDown: rn,
929
- placeholder: c.length === 0 || r ? R : void 0,
930
- disabled: N
914
+ placeholder: c.length === 0 || t ? C : void 0,
915
+ disabled: k
931
916
  }
932
917
  )
933
- ] }) : null, _ = /* @__PURE__ */ n(Ln, { handleChangePosition: z, children: /* @__PURE__ */ l(
934
- "div",
918
+ ] }) : null, _ = /* @__PURE__ */ n(
919
+ Bn,
935
920
  {
936
- className: [
937
- "sa-input-dropdown-container",
938
- A,
939
- `sa-input-dropdown-size-${i}`,
940
- w ? "trigger-input" : "",
941
- f ? "active" : "",
942
- un ? "error" : "",
943
- N ? "disable" : ""
944
- ].filter(Boolean).join(" "),
945
- ref: Y,
946
- onClick: w ? void 0 : gn,
947
- onKeyDown: w ? void 0 : rn,
948
- tabIndex: w ? void 0 : 0,
949
- onBlur: w ? void 0 : F,
950
- onFocus: w ? void 0 : T,
951
- children: [
952
- /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
953
- u ? ln.cloneElement(u, {
954
- width: W,
955
- style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
956
- }) : null,
957
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : xn() }),
958
- vn,
959
- !pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(An, { width: W }) : /* @__PURE__ */ n(jn, { width: W }) })
960
- ] }),
961
- O && /* @__PURE__ */ n(
962
- Rn,
963
- {
964
- dropdownLists: o,
965
- handleChangeValue: G,
966
- isComponentVisible: f,
967
- positionDropdown: hn,
968
- searchAble: !!m,
969
- hideSearch: w,
970
- value: c,
971
- onSearch: L,
972
- ref: g,
973
- multiSelect: r,
974
- searchValue: U,
975
- highlightedIndex: k,
976
- footer: $,
977
- groupLabel: t,
978
- onSelectAll: P
979
- }
980
- )
981
- ]
921
+ handleChangePosition: O,
922
+ enabled: w,
923
+ children: /* @__PURE__ */ d(
924
+ "div",
925
+ {
926
+ className: [
927
+ "sa-input-dropdown-container",
928
+ D,
929
+ `sa-input-dropdown-size-${p}`,
930
+ u ? "trigger-input" : "",
931
+ w ? "active" : "",
932
+ wn ? "error" : "",
933
+ k ? "disable" : ""
934
+ ].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,
941
+ children: [
942
+ /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-container", children: [
943
+ W ? ln.cloneElement(W, {
944
+ width: M,
945
+ style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
946
+ }) : null,
947
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: u ? mn : xn() }),
948
+ vn,
949
+ !pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(An, { width: M }) : /* @__PURE__ */ n(jn, { width: M }) })
950
+ ] }),
951
+ I && /* @__PURE__ */ n(
952
+ Rn,
953
+ {
954
+ dropdownLists: o,
955
+ handleChangeValue: H,
956
+ isComponentVisible: w,
957
+ positionDropdown: hn,
958
+ searchAble: !!L,
959
+ hideSearch: u,
960
+ value: c,
961
+ onSearch: E,
962
+ ref: b,
963
+ multiSelect: t,
964
+ searchValue: U,
965
+ highlightedIndex: v,
966
+ footer: T,
967
+ groupLabel: a,
968
+ onSelectAll: j
969
+ }
970
+ )
971
+ ]
972
+ }
973
+ )
982
974
  }
983
- ) });
984
- return J ? wn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${Z} sa-select-field-left`, children: [
985
- /* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
986
- /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
975
+ );
976
+ return J ? un === "outside-left" ? /* @__PURE__ */ d("div", { className: `${Z} sa-select-field-left`, children: [
977
+ /* @__PURE__ */ d("div", { className: "sa-select-field-left-label", children: [
978
+ /* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
987
979
  /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: J }),
988
980
  nn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
989
981
  V && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
990
982
  ] }),
991
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B })
983
+ z && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: z })
992
984
  ] }),
993
- /* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
985
+ /* @__PURE__ */ d("div", { className: "sa-select-field-input-wrap", children: [
994
986
  _,
995
- D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
987
+ R && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: R }),
996
988
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
997
989
  ] })
998
- ] }) : /* @__PURE__ */ l("div", { className: Z, children: [
999
- /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
990
+ ] }) : /* @__PURE__ */ d("div", { className: Z, children: [
991
+ /* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
1000
992
  /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: J }),
1001
993
  nn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1002
994
  V && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1003
995
  ] }),
1004
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
996
+ z && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: z }),
1005
997
  _,
1006
- D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
998
+ R && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: R }),
1007
999
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1008
- ] }) : /* @__PURE__ */ l("div", { className: Z, children: [
1009
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
1000
+ ] }) : /* @__PURE__ */ d("div", { className: Z, children: [
1001
+ z && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: z }),
1010
1002
  _,
1011
- D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
1003
+ R && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: R }),
1012
1004
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1013
1005
  ] });
1014
- }, tn = (o, p, s) => {
1015
- const d = o.length;
1016
- let i = p + s;
1017
- for (; i >= 0 && i < d; ) {
1018
- if (!o[i].disable)
1019
- return i;
1020
- i += s;
1006
+ }, tn = (o, l, i) => {
1007
+ const s = o.length;
1008
+ let p = l + i;
1009
+ for (; p >= 0 && p < s; ) {
1010
+ if (!o[p].disable)
1011
+ return p;
1012
+ p += i;
1021
1013
  }
1022
- if (s === 1) {
1023
- for (let r = 0; r < d; r++)
1024
- if (!o[r].disable)
1025
- return r;
1014
+ if (i === 1) {
1015
+ for (let t = 0; t < s; t++)
1016
+ if (!o[t].disable)
1017
+ return t;
1026
1018
  } else
1027
- for (let r = d - 1; r >= 0; r--)
1028
- if (!o[r].disable)
1029
- return r;
1019
+ for (let t = s - 1; t >= 0; t--)
1020
+ if (!o[t].disable)
1021
+ return t;
1030
1022
  return -1;
1031
- }, Dn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1023
+ }, Dn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1032
1024
  /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1033
1025
  /* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
1034
1026
  ] }), sn = (o) => /* @__PURE__ */ n(
@@ -1094,5 +1086,5 @@ const On = ({
1094
1086
  }
1095
1087
  );
1096
1088
  export {
1097
- On as Dropdown
1089
+ Mn as Dropdown
1098
1090
  };
@@ -1,4 +1,4 @@
1
- (function(v,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):(v=typeof globalThis<"u"?globalThis:v||self,n(v.Dropdown={},v.jsxRuntime,v.React))})(this,function(v,n,l){"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,i){"use strict";const sn=`@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;
@@ -543,4 +543,4 @@
543
543
  display: none;
544
544
  }
545
545
 
546
- `;function dn(o){const[p,i]=l.useState(o),t=l.useRef(null),s=r=>{t.current&&!t.current.contains(r.target)&&i(!1)};return l.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:i}}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=l.forwardRef(({positionDropdown:o,dropdownLists:p,isComponentVisible:i,searchAble:t,hideSearch:s,onSearch:r,value:k,handleChangeValue:f,multiSelect:L,searchValue:B,highlightedIndex:y,footer:W,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var d;y>=0&&P.current[y]&&((d=P.current[y])==null||d.scrollIntoView({block:"nearest"}))},[y]);const T=t&&!s?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:d=>{r&&r(d.target.value)},value:B,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:i?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:d=>d.stopPropagation(),ref:G,children:[o!=="top"&&T,n.jsxs("div",{className:`sa-input-dropdown-item-container ${L?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),L&&N&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:d=>{d.stopPropagation(),N()},children:"Select all"})]}),p.map((d,A)=>{const $=!!(k!=null&&k.find(O=>O.value===d.value)),w=!!d.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",$?"active":"",A===y?"highlight":"",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>f(d.label,d.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:$&&n.jsx(ln,{width:16})}),d.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(d.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:d.label}),d.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:d.description})]})]},A)})]}),o==="top"&&T,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:d=>d.stopPropagation(),children:W})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const i=l.useRef(null);l.useEffect(()=>{var k;const s=()=>{if(i.current){let f=i.current.parentElement;for(;f&&!t(f);)f=f.parentElement;f&&p()}};let r=(k=i.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",s),s(),()=>{r&&r.removeEventListener("scroll",s)}},[]);const t=s=>s&&(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);return n.jsx("div",{ref:i,children:o})},_="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(_)){const p=document.createElement("style");p.id=_,p.textContent=o,document.head.appendChild(p)}})(sn);const wn=({dropdownLists:o,onChange:p,defaultValue:i,value:t,size:s="sm",multiSelect:r,searchAble:k,iconLeft:f,placeholder:L,onSearch:B,error:y,onBlur:W,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:d,onSelectAll:A,fullWidth:$=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:D,helperText:S,errorText:h})=>{const J=["sa-select-field",`sa-select-field-size-${s}`,$?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),vn=y||!!h,[c,j]=l.useState(E?t||[]:i||[]),[kn,on]=l.useState(""),[m,Q]=l.useState(-1),[mn,q]=l.useState(()=>{var e,a;return!r&&(t!=null&&t.length||i!=null&&i.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((a=i==null?void 0:i[0])==null?void 0:a.label)??"":""}),g=l.useRef(null),{isComponentVisible:u,ref:X,setIsComponentVisible:C}=dn(!1),I=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&q(""),U==null||U()},Nn=()=>{I&&C(e=>!e)},H=(e,a)=>{if(r){if(c==null?void 0:c.find(x=>x.value===a)){const x=c.filter(Ln=>Ln.value!==a);E||j(x),p(x)}else{const x=[...c,{label:e,value:a}];E||j(x),p(x)}w&&q("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&q(O?"":e),C(!1)}};l.useEffect(()=>{E&&j(t||[])},[t]),l.useEffect(()=>{E||JSON.stringify(Z.current)===JSON.stringify(i)||(Z.current=i,j(Z.current||[]))},[i]);const En=()=>c.length?r?c==null?void 0:c.map((e,a)=>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:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),x=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,x>=e-10?(g.current.style.top=`${a.top-b.height-5}px`,on("top")):(g.current.style.top=`${a.top+a.height+4}px`,on("bottom"))}};l.useEffect(()=>(window.addEventListener("scroll",z),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",z),window.removeEventListener("resize",z)}),[]),l.useEffect(()=>{z()},[u]),l.useEffect(()=>{if(!u||!g.current)return;const e=new ResizeObserver(()=>{z()});return e.observe(g.current),()=>e.disconnect()},[u]),l.useEffect(()=>{u||Q(-1)},[u]);const an=e=>{if(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,m,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,m,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&H(o[m].label,o[m].value);break}case"Escape":C(!1);break}}},M=s==="lg"||s==="xl"?20:s==="xs"?14:16,Cn=gn&&!N?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:[r&&c.map((e,a)=>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:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const a=e.target.value;q(a),B==null||B(a),!u&&I&&C(!0)},onFocus:()=>{!N&&I&&C(!0)},onBlur:()=>{r||setTimeout(()=>C(!1),150)},onKeyDown:an,placeholder:c.length===0||r?L:void 0,disabled:N})]}):null,Y=n.jsx(cn,{handleChangePosition:z,children:n.jsxs("div",{className:["sa-input-dropdown-container",P,`sa-input-dropdown-size-${s}`,w?"trigger-input":"",u?"active":"",vn?"error":"",N?"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:[f?l.cloneElement(f,{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:u?n.jsx(un,{width:M}):n.jsx(hn,{width:M})})]}),I&&n.jsx(pn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:m,footer:T,groupLabel:d,onSelectAll:A})]})});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:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),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:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),Y,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:J,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),Y,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},V=(o,p,i)=>{const t=o.length;let s=p+i;for(;s>=0&&s<t;){if(!o[s].disable)return s;s+=i}if(i===1){for(let r=0;r<t;r++)if(!o[r].disable)return r}else for(let r=t-1;r>=0;r--)if(!o[r].disable)return r;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"})});v.Dropdown=wn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.5.3",
3
+ "version": "5.5.5",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",