@starasia/dropdown 5.5.5 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@ interface IProps {
18
18
  footer?: React.ReactNode;
19
19
  groupLabel?: string;
20
20
  onSelectAll?: () => void;
21
+ emptyState?: React.ReactNode;
21
22
  }
22
23
  declare const DropdownList: React.ForwardRefExoticComponent<IProps & React.RefAttributes<HTMLDivElement>>;
23
24
  export default DropdownList;
@@ -1,6 +1,6 @@
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
- const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ import { jsxs as d, jsx as n, Fragment as rn } from "react/jsx-runtime";
2
+ import hn, { useState as L, useRef as J, useEffect as x, forwardRef as Nn } from "react";
3
+ const Cn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
  * {
5
5
  margin: 0;
6
6
  padding: 0;
@@ -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;
@@ -308,6 +323,24 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
308
323
  gap: 4px;
309
324
  }
310
325
 
326
+ /* === EMPTY STATE ===
327
+ Rendered inside the list container, so an empty panel is just the search bar
328
+ plus this message — no leftover padding strip, no footer border to collide
329
+ with. */
330
+ .sa-input-dropdown-empty {
331
+ padding: 20px 12px;
332
+ text-align: center;
333
+ font-size: 12px;
334
+ font-weight: 400;
335
+ line-height: 1.5;
336
+ color: var(--sa-dropdown-placeholder-subtle);
337
+ overflow-wrap: anywhere;
338
+ }
339
+ .sa-input-dropdown-empty-query {
340
+ color: var(--sa-dropdown-text-primary);
341
+ font-weight: 500;
342
+ }
343
+
311
344
  /* === SECTION HEADER === */
312
345
  .sa-input-dropdown-section-header {
313
346
  display: flex;
@@ -546,15 +579,15 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
546
579
  }
547
580
 
548
581
  `;
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);
582
+ function En(o) {
583
+ const [t, i] = L(o), l = J(null), p = (s) => {
584
+ l.current && !l.current.contains(s.target) && i(!1);
552
585
  };
553
586
  return x(() => (document.addEventListener("click", p, !0), () => {
554
587
  document.removeEventListener("click", p, !0);
555
- }), []), { ref: s, isComponentVisible: l, setIsComponentVisible: i };
588
+ }), []), { ref: l, isComponentVisible: t, setIsComponentVisible: i };
556
589
  }
557
- const En = ({ ...o }) => /* @__PURE__ */ d(
590
+ const zn = ({ ...o }) => /* @__PURE__ */ d(
558
591
  "svg",
559
592
  {
560
593
  xmlns: "http://www.w3.org/2000/svg",
@@ -586,7 +619,7 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
586
619
  )
587
620
  ]
588
621
  }
589
- ), zn = ({ width: o = 16 }) => /* @__PURE__ */ n(
622
+ ), Rn = ({ width: o = 16 }) => /* @__PURE__ */ n(
590
623
  "svg",
591
624
  {
592
625
  xmlns: "http://www.w3.org/2000/svg",
@@ -605,87 +638,105 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
605
638
  }
606
639
  )
607
640
  }
608
- ), Rn = yn(
641
+ ), Bn = Nn(
609
642
  ({
610
643
  positionDropdown: o,
611
- dropdownLists: l,
644
+ dropdownLists: t,
612
645
  isComponentVisible: i,
613
- searchAble: s,
646
+ searchAble: l,
614
647
  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([]);
648
+ onSearch: s,
649
+ value: j,
650
+ handleChangeValue: T,
651
+ multiSelect: E,
652
+ searchValue: m,
653
+ highlightedIndex: k,
654
+ footer: $,
655
+ groupLabel: q,
656
+ onSelectAll: y,
657
+ emptyState: K
658
+ }, X) => {
659
+ const A = J([]), H = m !== void 0, [Y, Z] = L(""), M = H ? m : Y, c = !t || t.length === 0;
626
660
  x(() => {
627
661
  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)" } }),
662
+ k >= 0 && A.current[k] && ((a = A.current[k]) == null || a.scrollIntoView({ block: "nearest" }));
663
+ }, [k]);
664
+ const Q = l && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
665
+ /* @__PURE__ */ n(zn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
632
666
  /* @__PURE__ */ n(
633
667
  "input",
634
668
  {
635
669
  onChange: (a) => {
636
- t && t(a.target.value);
670
+ H || Z(a.target.value), s && s(a.target.value);
637
671
  },
638
- value: E,
672
+ value: M,
639
673
  autoFocus: !0,
640
674
  placeholder: "Search..."
641
675
  }
642
676
  )
643
677
  ] }) : null;
644
- return /* @__PURE__ */ n(dn, { children: i ? /* @__PURE__ */ d(
678
+ return /* @__PURE__ */ n(rn, { children: i ? /* @__PURE__ */ d(
645
679
  "div",
646
680
  {
647
- className: "sa-input-dropdown-lists-container",
681
+ className: [
682
+ "sa-input-dropdown-lists-container",
683
+ /* When the panel opens upward the search bar sits below the
684
+ list. That is a CSS `order` swap, never a second JSX slot —
685
+ moving the node between slots would remount the input and
686
+ drop both the typed text and the caret every time the panel
687
+ flips (which it does whenever filtering resizes the panel). */
688
+ o === "top" ? "search-bottom" : ""
689
+ ].filter(Boolean).join(" "),
648
690
  onClick: (a) => a.stopPropagation(),
649
- ref: U,
691
+ ref: X,
650
692
  children: [
651
- o !== "top" && T,
693
+ Q,
652
694
  /* @__PURE__ */ d(
653
695
  "div",
654
696
  {
655
- className: `sa-input-dropdown-item-container ${C ? "multi" : ""}`,
697
+ className: `sa-input-dropdown-item-container ${E ? "multi" : ""}`,
656
698
  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(
699
+ c && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: K ?? (M ? /* @__PURE__ */ d(rn, { children: [
700
+ "No results for",
701
+ " ",
702
+ /* @__PURE__ */ d("span", { className: "sa-input-dropdown-empty-query", children: [
703
+ "“",
704
+ M,
705
+ "”"
706
+ ] })
707
+ ] }) : "No data available") }),
708
+ q && !c && /* @__PURE__ */ d("div", { className: "sa-input-dropdown-section-header", children: [
709
+ /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: q }),
710
+ E && y && /* @__PURE__ */ n(
660
711
  "button",
661
712
  {
662
713
  className: "sa-input-dropdown-section-select-all",
663
714
  onClick: (a) => {
664
- a.stopPropagation(), k();
715
+ a.stopPropagation(), y();
665
716
  },
666
717
  children: "Select all"
667
718
  }
668
719
  )
669
720
  ] }),
670
- l.map((a, j) => {
671
- const $ = !!(L != null && L.find((A) => A.value === a.value)), u = !!a.description;
721
+ t == null ? void 0 : t.map((a, O) => {
722
+ const z = !!(j != null && j.find((S) => S.value === a.value)), P = !!a.description;
672
723
  return /* @__PURE__ */ d(
673
724
  "div",
674
725
  {
675
726
  className: [
676
727
  "sa-input-dropdown-item",
677
- u ? "has-description" : "",
678
- $ ? "active" : "",
679
- j === m ? "highlight" : "",
728
+ P ? "has-description" : "",
729
+ z ? "active" : "",
730
+ O === k ? "highlight" : "",
680
731
  a.disable ? "sa-input-dropdown-item-disable" : ""
681
732
  ].filter(Boolean).join(" "),
682
- ref: (A) => {
683
- D.current[j] = A;
733
+ ref: (S) => {
734
+ A.current[O] = S;
684
735
  },
685
- onClick: () => W(a.label, a.value),
736
+ onClick: () => T(a.label, a.value),
686
737
  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 }) }),
738
+ E && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: z && /* @__PURE__ */ n(Rn, { width: 16 }) }),
739
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: hn.cloneElement(a.icon, { width: 16 }) }),
689
740
  /* @__PURE__ */ d("div", { style: { minWidth: 0, flex: 1 }, children: [
690
741
  /* @__PURE__ */ n(
691
742
  "p",
@@ -710,187 +761,187 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
710
761
  ] })
711
762
  ]
712
763
  },
713
- j
764
+ O
714
765
  );
715
766
  })
716
767
  ]
717
768
  }
718
769
  ),
719
- o === "top" && T,
720
- F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: F })
770
+ $ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: $ })
721
771
  ]
722
772
  }
723
773
  ) : null });
724
774
  }
725
- ), Bn = ({
775
+ ), Dn = ({
726
776
  children: o,
727
- handleChangePosition: l,
777
+ handleChangePosition: t,
728
778
  enabled: i = !0
729
779
  }) => (x(() => {
730
780
  if (i)
731
- return window.addEventListener("scroll", l, !0), () => {
732
- window.removeEventListener("scroll", l, !0);
781
+ return window.addEventListener("scroll", t, !0), () => {
782
+ window.removeEventListener("scroll", t, !0);
733
783
  };
734
- }, [i, l]), /* @__PURE__ */ n("div", { children: o })), an = "sa-input-dropdown-styles", Ln = (o) => {
735
- if (!(typeof document > "u") && !document.getElementById(an)) {
736
- const l = document.createElement("style");
737
- l.id = an, l.textContent = o, document.head.appendChild(l);
784
+ }, [i, t]), /* @__PURE__ */ n("div", { children: o })), cn = "sa-input-dropdown-styles", Ln = (o) => {
785
+ if (!(typeof document > "u") && !document.getElementById(cn)) {
786
+ const t = document.createElement("style");
787
+ t.id = cn, t.textContent = o, document.head.appendChild(t);
738
788
  }
739
789
  };
740
- Ln(Nn);
741
- const Mn = ({
790
+ Ln(Cn);
791
+ const Sn = ({
742
792
  dropdownLists: o,
743
- onChange: l,
793
+ onChange: t,
744
794
  defaultValue: i,
745
- value: s,
795
+ value: l,
746
796
  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,
797
+ multiSelect: s,
798
+ searchAble: j,
799
+ iconLeft: T,
800
+ placeholder: E,
801
+ onSearch: m,
802
+ error: k,
803
+ onBlur: $,
804
+ onFocus: q,
805
+ disable: y,
806
+ searchValue: K,
807
+ variant: X = "outline",
808
+ footer: A,
809
+ groupLabel: H,
810
+ onSelectAll: Y,
811
+ emptyState: Z,
812
+ fullWidth: M = !0,
813
+ triggerInput: c = !1,
814
+ clearOnSelect: Q = !1,
815
+ hideChevronIcon: a = !1,
816
+ clearable: O = !1,
817
+ onClear: z,
767
818
  /* field wrapper */
768
- label: J,
769
- labelPosition: un = "outside-top",
770
- required: V,
771
- optional: nn,
772
- description: z,
773
- helperText: R,
819
+ label: P,
820
+ labelPosition: S = "outside-top",
821
+ required: an,
822
+ optional: tn,
823
+ description: R,
824
+ helperText: B,
774
825
  errorText: h
775
826
  }) => {
776
- const Z = [
827
+ const _ = [
777
828
  "sa-select-field",
778
829
  `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(
830
+ M ? "sa-select-field-fullwidth" : ""
831
+ ].filter(Boolean).join(" "), N = l !== void 0, V = J(), fn = k || !!h, [u, D] = L(
832
+ N ? l || [] : i || []
833
+ ), [bn, sn] = L(""), [v, nn] = L(-1), [dn, G] = L(
783
834
  () => {
784
835
  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) ?? "" : "";
836
+ return !s && (l != null && l.length || i != null && i.length) ? ((e = l == null ? void 0 : l[0]) == null ? void 0 : e.label) ?? ((r = i == null ? void 0 : i[0]) == null ? void 0 : r.label) ?? "" : "";
786
837
  }
787
- ), b = G(null), { isComponentVisible: w, ref: Y, setIsComponentVisible: N } = Cn(!1), I = o !== void 0, on = c.length > 0, bn = (e) => {
838
+ ), b = J(null), { isComponentVisible: w, ref: en, setIsComponentVisible: C } = En(!1), I = o !== void 0, ln = u.length > 0, gn = (e) => {
788
839
  e.stopPropagation();
789
840
  const r = [];
790
- y || B(r), l(r), u && q(""), K == null || K();
791
- }, 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);
841
+ N || D(r), t(r), c && G(""), z == null || z();
842
+ }, xn = () => {
843
+ I && C((e) => !e);
844
+ }, U = (e, r) => {
845
+ if (s) {
846
+ if (u == null ? void 0 : u.find((g) => g.value === r)) {
847
+ const g = u.filter((yn) => yn.value !== r);
848
+ N || D(g), t(g);
798
849
  } else {
799
- const g = [...c, { label: e, value: r }];
800
- y || B(g), l(g);
850
+ const g = [...u, { label: e, value: r }];
851
+ N || D(g), t(g);
801
852
  }
802
- u && q("");
853
+ c && G("");
803
854
  } else {
804
855
  const f = [{ label: e, value: r }];
805
- y || B(f), l(f), u && q(A ? "" : e), N(!1);
856
+ N || D(f), t(f), c && G(Q ? "" : e), C(!1);
806
857
  }
807
858
  };
808
859
  x(() => {
809
- y && B(s || []);
810
- }, [s]), x(() => {
811
- y || JSON.stringify(Q.current) === JSON.stringify(i) || (Q.current = i, B(Q.current || []));
860
+ N && D(l || []);
861
+ }, [l]), x(() => {
862
+ N || JSON.stringify(V.current) === JSON.stringify(i) || (V.current = i, D(V.current || []));
812
863
  }, [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: [
864
+ const vn = () => u.length ? s ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
814
865
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
815
866
  /* @__PURE__ */ n(
816
- sn,
867
+ wn,
817
868
  {
818
869
  onClick: (f) => {
819
- f.stopPropagation(), H(e.label, e.value);
870
+ f.stopPropagation(), U(e.label, e.value);
820
871
  }
821
872
  }
822
873
  )
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"));
874
+ ] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: u == null ? void 0 : u[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: E }), W = () => {
875
+ if (en.current && b.current) {
876
+ const e = window.innerHeight, r = en.current.getBoundingClientRect(), f = b.current.getBoundingClientRect(), g = r.bottom + f.height;
877
+ 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`, sn("top")) : (b.current.style.top = `${r.top + r.height + 4}px`, sn("bottom"));
827
878
  }
828
879
  };
829
- x(() => (window.addEventListener("resize", O), () => {
830
- window.removeEventListener("resize", O);
880
+ x(() => (window.addEventListener("resize", W), () => {
881
+ window.removeEventListener("resize", W);
831
882
  }), []), x(() => {
832
- O();
883
+ W();
833
884
  }, [w]), x(() => {
834
885
  if (!w || !b.current)
835
886
  return;
836
887
  const e = new ResizeObserver(() => {
837
- O();
888
+ W();
838
889
  });
839
890
  return e.observe(b.current), () => e.disconnect();
840
891
  }, [w]), x(() => {
841
- w || X(-1);
892
+ w || nn(-1);
842
893
  }, [w]);
843
- const rn = (e) => {
894
+ const pn = (e) => {
844
895
  if (I) {
845
896
  if (!w) {
846
- (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), N(!0));
897
+ (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
847
898
  return;
848
899
  }
849
900
  switch (e.key) {
850
901
  case "ArrowDown": {
851
902
  e.preventDefault();
852
- const r = tn(o, v, 1);
853
- r !== -1 && X(r);
903
+ const r = un(o, v, 1);
904
+ r !== -1 && nn(r);
854
905
  break;
855
906
  }
856
907
  case "ArrowUp": {
857
908
  e.preventDefault();
858
- const r = tn(o, v, -1);
859
- r !== -1 && X(r);
909
+ const r = un(o, v, -1);
910
+ r !== -1 && nn(r);
860
911
  break;
861
912
  }
862
913
  case "Enter": {
863
- e.preventDefault(), v >= 0 && o[v] && !o[v].disable && H(
914
+ e.preventDefault(), v >= 0 && o[v] && !o[v].disable && U(
864
915
  o[v].label,
865
916
  o[v].value
866
917
  );
867
918
  break;
868
919
  }
869
920
  case "Escape":
870
- N(!1);
921
+ C(!1);
871
922
  break;
872
923
  }
873
924
  }
874
- }, M = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, vn = cn && !k ? /* @__PURE__ */ n(
925
+ }, F = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, mn = O && !y ? /* @__PURE__ */ n(
875
926
  "button",
876
927
  {
877
928
  type: "button",
878
- className: `sa-input-dropdown-clear${on ? "" : " sa-input-dropdown-clear-hidden"}`,
929
+ className: `sa-input-dropdown-clear${ln ? "" : " sa-input-dropdown-clear-hidden"}`,
879
930
  "aria-label": "Clear selection",
880
- "aria-hidden": !on,
931
+ "aria-hidden": !ln,
881
932
  tabIndex: -1,
882
- onClick: bn,
933
+ onClick: gn,
883
934
  onMouseDown: (e) => e.preventDefault(),
884
- children: /* @__PURE__ */ n(Dn, { width: M, height: M })
935
+ children: /* @__PURE__ */ n(jn, { width: F, height: F })
885
936
  }
886
- ) : null, mn = u ? /* @__PURE__ */ d(dn, { children: [
887
- t && c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
937
+ ) : null, kn = c ? /* @__PURE__ */ d(rn, { children: [
938
+ s && u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
888
939
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
889
940
  /* @__PURE__ */ n(
890
- sn,
941
+ wn,
891
942
  {
892
943
  onClick: (f) => {
893
- f.stopPropagation(), H(e.label, e.value);
944
+ f.stopPropagation(), U(e.label, e.value);
894
945
  }
895
946
  }
896
947
  )
@@ -899,73 +950,74 @@ const Mn = ({
899
950
  "input",
900
951
  {
901
952
  className: "sa-input-dropdown-trigger-input",
902
- value: fn,
953
+ value: dn,
903
954
  onChange: (e) => {
904
955
  const r = e.target.value;
905
- q(r), E == null || E(r), !w && I && N(!0);
956
+ G(r), m == null || m(r), !w && I && C(!0);
906
957
  },
907
958
  onFocus: () => {
908
- !k && I && N(!0);
959
+ !y && I && C(!0);
909
960
  },
910
961
  onBlur: () => {
911
- t || setTimeout(() => N(!1), 150);
962
+ s || setTimeout(() => C(!1), 150);
912
963
  },
913
- onKeyDown: rn,
914
- placeholder: c.length === 0 || t ? C : void 0,
915
- disabled: k
964
+ onKeyDown: pn,
965
+ placeholder: u.length === 0 || s ? E : void 0,
966
+ disabled: y
916
967
  }
917
968
  )
918
- ] }) : null, _ = /* @__PURE__ */ n(
919
- Bn,
969
+ ] }) : null, on = /* @__PURE__ */ n(
970
+ Dn,
920
971
  {
921
- handleChangePosition: O,
972
+ handleChangePosition: W,
922
973
  enabled: w,
923
974
  children: /* @__PURE__ */ d(
924
975
  "div",
925
976
  {
926
977
  className: [
927
978
  "sa-input-dropdown-container",
928
- D,
979
+ X,
929
980
  `sa-input-dropdown-size-${p}`,
930
- u ? "trigger-input" : "",
981
+ c ? "trigger-input" : "",
931
982
  w ? "active" : "",
932
- wn ? "error" : "",
933
- k ? "disable" : ""
983
+ fn ? "error" : "",
984
+ y ? "disable" : ""
934
985
  ].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,
986
+ ref: en,
987
+ onClick: c ? void 0 : xn,
988
+ onKeyDown: c ? void 0 : pn,
989
+ tabIndex: c ? void 0 : 0,
990
+ onBlur: c ? void 0 : $,
991
+ onFocus: c ? void 0 : q,
941
992
  children: [
942
993
  /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-container", children: [
943
- W ? ln.cloneElement(W, {
944
- width: M,
994
+ T ? hn.cloneElement(T, {
995
+ width: F,
945
996
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
946
997
  }) : 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 }) })
998
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: c ? kn : vn() }),
999
+ mn,
1000
+ !a && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(Mn, { width: F }) : /* @__PURE__ */ n(An, { width: F }) })
950
1001
  ] }),
951
1002
  I && /* @__PURE__ */ n(
952
- Rn,
1003
+ Bn,
953
1004
  {
954
1005
  dropdownLists: o,
955
- handleChangeValue: H,
1006
+ handleChangeValue: U,
956
1007
  isComponentVisible: w,
957
- positionDropdown: hn,
958
- searchAble: !!L,
959
- hideSearch: u,
960
- value: c,
961
- onSearch: E,
1008
+ positionDropdown: bn,
1009
+ searchAble: !!j,
1010
+ hideSearch: c,
1011
+ value: u,
1012
+ onSearch: m,
962
1013
  ref: b,
963
- multiSelect: t,
964
- searchValue: U,
1014
+ multiSelect: s,
1015
+ searchValue: c ? dn : K,
965
1016
  highlightedIndex: v,
966
- footer: T,
967
- groupLabel: a,
968
- onSelectAll: j
1017
+ footer: A,
1018
+ groupLabel: H,
1019
+ onSelectAll: Y,
1020
+ emptyState: Z
969
1021
  }
970
1022
  )
971
1023
  ]
@@ -973,57 +1025,57 @@ const Mn = ({
973
1025
  )
974
1026
  }
975
1027
  );
976
- return J ? un === "outside-left" ? /* @__PURE__ */ d("div", { className: `${Z} sa-select-field-left`, children: [
1028
+ return P ? S === "outside-left" ? /* @__PURE__ */ d("div", { className: `${_} sa-select-field-left`, children: [
977
1029
  /* @__PURE__ */ d("div", { className: "sa-select-field-left-label", children: [
978
1030
  /* @__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: "*" })
1031
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: P }),
1032
+ tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1033
+ an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
982
1034
  ] }),
983
- z && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: z })
1035
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R })
984
1036
  ] }),
985
1037
  /* @__PURE__ */ d("div", { className: "sa-select-field-input-wrap", children: [
986
- _,
987
- R && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: R }),
1038
+ on,
1039
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
988
1040
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
989
1041
  ] })
990
- ] }) : /* @__PURE__ */ d("div", { className: Z, children: [
1042
+ ] }) : /* @__PURE__ */ d("div", { className: _, children: [
991
1043
  /* @__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: "*" })
1044
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: P }),
1045
+ tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1046
+ an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
995
1047
  ] }),
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 }),
1048
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
1049
+ on,
1050
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
999
1051
  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 }),
1052
+ ] }) : /* @__PURE__ */ d("div", { className: _, children: [
1053
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
1054
+ on,
1055
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
1004
1056
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1005
1057
  ] });
1006
- }, tn = (o, l, i) => {
1007
- const s = o.length;
1008
- let p = l + i;
1009
- for (; p >= 0 && p < s; ) {
1058
+ }, un = (o, t, i) => {
1059
+ const l = o.length;
1060
+ let p = t + i;
1061
+ for (; p >= 0 && p < l; ) {
1010
1062
  if (!o[p].disable)
1011
1063
  return p;
1012
1064
  p += i;
1013
1065
  }
1014
1066
  if (i === 1) {
1015
- for (let t = 0; t < s; t++)
1016
- if (!o[t].disable)
1017
- return t;
1067
+ for (let s = 0; s < l; s++)
1068
+ if (!o[s].disable)
1069
+ return s;
1018
1070
  } else
1019
- for (let t = s - 1; t >= 0; t--)
1020
- if (!o[t].disable)
1021
- return t;
1071
+ for (let s = l - 1; s >= 0; s--)
1072
+ if (!o[s].disable)
1073
+ return s;
1022
1074
  return -1;
1023
- }, Dn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1075
+ }, jn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1024
1076
  /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1025
1077
  /* @__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(
1078
+ ] }), wn = (o) => /* @__PURE__ */ n(
1027
1079
  "svg",
1028
1080
  {
1029
1081
  xmlns: "http://www.w3.org/2000/svg",
@@ -1044,7 +1096,7 @@ const Mn = ({
1044
1096
  }
1045
1097
  )
1046
1098
  }
1047
- ), jn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1099
+ ), An = ({ width: o = 16 }) => /* @__PURE__ */ n(
1048
1100
  "svg",
1049
1101
  {
1050
1102
  xmlns: "http://www.w3.org/2000/svg",
@@ -1064,7 +1116,7 @@ const Mn = ({
1064
1116
  }
1065
1117
  )
1066
1118
  }
1067
- ), An = ({ width: o = 16 }) => /* @__PURE__ */ n(
1119
+ ), Mn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1068
1120
  "svg",
1069
1121
  {
1070
1122
  xmlns: "http://www.w3.org/2000/svg",
@@ -1086,5 +1138,5 @@ const Mn = ({
1086
1138
  }
1087
1139
  );
1088
1140
  export {
1089
- Mn as Dropdown
1141
+ Sn as Dropdown
1090
1142
  };
@@ -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,s){"use strict";const cn=`@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;
@@ -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;
@@ -306,6 +321,24 @@
306
321
  gap: 4px;
307
322
  }
308
323
 
324
+ /* === EMPTY STATE ===
325
+ Rendered inside the list container, so an empty panel is just the search bar
326
+ plus this message — no leftover padding strip, no footer border to collide
327
+ with. */
328
+ .sa-input-dropdown-empty {
329
+ padding: 20px 12px;
330
+ text-align: center;
331
+ font-size: 12px;
332
+ font-weight: 400;
333
+ line-height: 1.5;
334
+ color: var(--sa-dropdown-placeholder-subtle);
335
+ overflow-wrap: anywhere;
336
+ }
337
+ .sa-input-dropdown-empty-query {
338
+ color: var(--sa-dropdown-text-primary);
339
+ font-weight: 500;
340
+ }
341
+
309
342
  /* === SECTION HEADER === */
310
343
  .sa-input-dropdown-section-header {
311
344
  display: flex;
@@ -543,4 +576,4 @@
543
576
  display: none;
544
577
  }
545
578
 
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"})});
579
+ `;function wn(o){const[t,d]=s.useState(o),l=s.useRef(null),p=i=>{l.current&&!l.current.contains(i.target)&&d(!1)};return s.useEffect(()=>(document.addEventListener("click",p,!0),()=>{document.removeEventListener("click",p,!0)}),[]),{ref:l,isComponentVisible:t,setIsComponentVisible:d}}const hn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),fn=({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"})}),un=s.forwardRef(({positionDropdown:o,dropdownLists:t,isComponentVisible:d,searchAble:l,hideSearch:p,onSearch:i,value:L,handleChangeValue:T,multiSelect:C,searchValue:m,highlightedIndex:y,footer:q,groupLabel:$,onSelectAll:k,emptyState:J},K)=>{const j=s.useRef([]),H=m!==void 0,[X,Y]=s.useState(""),A=H?m:X,c=!t||t.length===0;s.useEffect(()=>{var a;y>=0&&j.current[y]&&((a=j.current[y])==null||a.scrollIntoView({block:"nearest"}))},[y]);const Z=l&&!p?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(hn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{H||Y(a.target.value),i&&i(a.target.value)},value:A,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:K,children:[Z,n.jsxs("div",{className:`sa-input-dropdown-item-container ${C?"multi":""}`,children:[c&&n.jsx("div",{className:"sa-input-dropdown-empty",children:J??(A?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",A,"”"]})]}):"No data available")}),$&&!c&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:$}),C&&k&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),k()},children:"Select all"})]}),t==null?void 0:t.map((a,M)=>{const z=!!(L!=null&&L.find(P=>P.value===a.value)),O=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",O?"has-description":"",z?"active":"",M===y?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:P=>{j.current[M]=P},onClick:()=>T(a.label,a.value),children:[C&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:z&&n.jsx(fn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:s.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},M)})]}),q&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:q})]}):null})}),bn=({children:o,handleChangePosition:t,enabled:d=!0})=>(s.useEffect(()=>{if(d)return window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("scroll",t,!0)}},[d,t]),n.jsx("div",{children:o})),en="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(en)){const t=document.createElement("style");t.id=en,t.textContent=o,document.head.appendChild(t)}})(cn);const gn=({dropdownLists:o,onChange:t,defaultValue:d,value:l,size:p="sm",multiSelect:i,searchAble:L,iconLeft:T,placeholder:C,onSearch:m,error:y,onBlur:q,onFocus:$,disable:k,searchValue:J,variant:K="outline",footer:j,groupLabel:H,onSelectAll:X,emptyState:Y,fullWidth:A=!0,triggerInput:c=!1,clearOnSelect:Z=!1,hideChevronIcon:a=!1,clearable:M=!1,onClear:z,label:O,labelPosition:P="outside-top",required:an,optional:sn,description:B,helperText:D,errorText:f})=>{const Q=["sa-select-field",`sa-select-field-size-${p}`,A?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),N=l!==void 0,_=s.useRef(),yn=y||!!f,[w,S]=s.useState(N?l||[]:d||[]),[kn,tn]=s.useState(""),[v,V]=s.useState(-1),[dn,G]=s.useState(()=>{var e,r;return!i&&(l!=null&&l.length||d!=null&&d.length)?((e=l==null?void 0:l[0])==null?void 0:e.label)??((r=d==null?void 0:d[0])==null?void 0:r.label)??"":""}),b=s.useRef(null),{isComponentVisible:h,ref:R,setIsComponentVisible:E}=wn(!1),I=o!==void 0,ln=w.length>0,Nn=e=>{e.stopPropagation();const r=[];N||S(r),t(r),c&&G(""),z==null||z()},En=()=>{I&&E(e=>!e)},U=(e,r)=>{if(i){if(w==null?void 0:w.find(g=>g.value===r)){const g=w.filter(Dn=>Dn.value!==r);N||S(g),t(g)}else{const g=[...w,{label:e,value:r}];N||S(g),t(g)}c&&G("")}else{const u=[{label:e,value:r}];N||S(u),t(u),c&&G(Z?"":e),E(!1)}};s.useEffect(()=>{N&&S(l||[])},[l]),s.useEffect(()=>{N||JSON.stringify(_.current)===JSON.stringify(d)||(_.current=d,S(_.current||[]))},[d]);const Cn=()=>w.length?i?w==null?void 0:w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(rn,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:w==null?void 0:w[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:C}),F=()=>{if(R.current&&b.current){const e=window.innerHeight,r=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`,tn("top")):(b.current.style.top=`${r.top+r.height+4}px`,tn("bottom"))}};s.useEffect(()=>(window.addEventListener("resize",F),()=>{window.removeEventListener("resize",F)}),[]),s.useEffect(()=>{F()},[h]),s.useEffect(()=>{if(!h||!b.current)return;const e=new ResizeObserver(()=>{F()});return e.observe(b.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||V(-1)},[h]);const pn=e=>{if(I){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=on(o,v,1);r!==-1&&V(r);break}case"ArrowUp":{e.preventDefault();const r=on(o,v,-1);r!==-1&&V(r);break}case"Enter":{e.preventDefault(),v>=0&&o[v]&&!o[v].disable&&U(o[v].label,o[v].value);break}case"Escape":E(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,zn=M&&!k?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${ln?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!ln,tabIndex:-1,onClick:Nn,onMouseDown:e=>e.preventDefault(),children:n.jsx(xn,{width:W,height:W})}):null,Bn=c?n.jsxs(n.Fragment,{children:[i&&w.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(rn,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:dn,onChange:e=>{const r=e.target.value;G(r),m==null||m(r),!h&&I&&E(!0)},onFocus:()=>{!k&&I&&E(!0)},onBlur:()=>{i||setTimeout(()=>E(!1),150)},onKeyDown:pn,placeholder:w.length===0||i?C:void 0,disabled:k})]}):null,nn=n.jsx(bn,{handleChangePosition:F,enabled:h,children:n.jsxs("div",{className:["sa-input-dropdown-container",K,`sa-input-dropdown-size-${p}`,c?"trigger-input":"",h?"active":"",yn?"error":"",k?"disable":""].filter(Boolean).join(" "),ref:R,onClick:c?void 0:En,onKeyDown:c?void 0:pn,tabIndex:c?void 0:0,onBlur:c?void 0:q,onFocus:c?void 0:$,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[T?s.cloneElement(T,{width:W,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:c?Bn:Cn()}),zn,!a&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:h?n.jsx(mn,{width:W}):n.jsx(vn,{width:W})})]}),I&&n.jsx(un,{dropdownLists:o,handleChangeValue:U,isComponentVisible:h,positionDropdown:kn,searchAble:!!L,hideSearch:c,value:w,onSearch:m,ref:b,multiSelect:i,searchValue:c?dn:J,highlightedIndex:v,footer:j,groupLabel:H,onSelectAll:X,emptyState:Y})]})});return O?P==="outside-left"?n.jsxs("div",{className:`${Q} 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:O}),sn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),an&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[nn,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:Q,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:O}),sn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),an&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),nn,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:Q,children:[B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),nn,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},on=(o,t,d)=>{const l=o.length;let p=t+d;for(;p>=0&&p<l;){if(!o[p].disable)return p;p+=d}if(d===1){for(let i=0;i<l;i++)if(!o[i].disable)return i}else for(let i=l-1;i>=0;i--)if(!o[i].disable)return i;return-1},xn=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"})]}),rn=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"})}),vn=({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"})}),mn=({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=gn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
@@ -45,6 +45,18 @@ export interface IDropdown {
45
45
  footer?: React.ReactNode;
46
46
  groupLabel?: string;
47
47
  onSelectAll?: () => void;
48
+ /**
49
+ * Rendered inside the panel when `dropdownLists` is empty. Any node — text,
50
+ * an illustration, a "create new" button.
51
+ *
52
+ * The built-in default only covers the two cases the component can actually
53
+ * tell apart: a search that matched nothing, and a genuinely empty list.
54
+ * It cannot see whether a request is still in flight, whether one failed, or
55
+ * whether a lazy dropdown has not fetched yet — those all look identical
56
+ * from in here. Pass this prop to speak for the states only you know about;
57
+ * leave it `undefined` for the rest and the default takes over.
58
+ */
59
+ emptyState?: React.ReactNode;
48
60
  fullWidth?: boolean;
49
61
  triggerInput?: boolean;
50
62
  clearOnSelect?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.5.5",
3
+ "version": "5.6.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",