@starasia/dropdown 5.5.6 → 6.0.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,10 +1,9 @@
1
- import { jsxs as d, jsx as n, Fragment as pn } from "react/jsx-runtime";
2
- import cn, { useState as j, useRef as J, useEffect as b, forwardRef as yn } from "react";
3
- const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
- * {
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 v, forwardRef as Nn } from "react";
3
+ const Cn = `* {
5
4
  margin: 0;
6
5
  padding: 0;
7
- font-family: "Poppins", sans-serif;
6
+ font-family: var(--sa-font-family, "Inter", sans-serif);
8
7
  box-sizing: border-box;
9
8
  }
10
9
 
@@ -265,7 +264,7 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
265
264
  width: 100%;
266
265
  display: flex;
267
266
  flex-direction: column;
268
- font-family: "Poppins", sans-serif;
267
+ font-family: var(--sa-font-family, "Inter", sans-serif);
269
268
  }
270
269
 
271
270
  /* === SEARCH BAR === */
@@ -323,6 +322,24 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
323
322
  gap: 4px;
324
323
  }
325
324
 
325
+ /* === EMPTY STATE ===
326
+ Rendered inside the list container, so an empty panel is just the search bar
327
+ plus this message — no leftover padding strip, no footer border to collide
328
+ with. */
329
+ .sa-input-dropdown-empty {
330
+ padding: 20px 12px;
331
+ text-align: center;
332
+ font-size: 12px;
333
+ font-weight: 400;
334
+ line-height: 1.5;
335
+ color: var(--sa-dropdown-placeholder-subtle);
336
+ overflow-wrap: anywhere;
337
+ }
338
+ .sa-input-dropdown-empty-query {
339
+ color: var(--sa-dropdown-text-primary);
340
+ font-weight: 500;
341
+ }
342
+
326
343
  /* === SECTION HEADER === */
327
344
  .sa-input-dropdown-section-header {
328
345
  display: flex;
@@ -442,7 +459,7 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
442
459
  flex-direction: column;
443
460
  gap: 8px;
444
461
  width: max-content;
445
- font-family: "Poppins", sans-serif;
462
+ font-family: var(--sa-font-family, "Inter", sans-serif);
446
463
  }
447
464
  .sa-select-field-fullwidth {
448
465
  width: 100%;
@@ -561,15 +578,15 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
561
578
  }
562
579
 
563
580
  `;
564
- function Cn(o) {
565
- const [l, t] = j(o), s = J(null), p = (i) => {
566
- s.current && !s.current.contains(i.target) && t(!1);
581
+ function En(o) {
582
+ const [t, i] = L(o), l = J(null), p = (s) => {
583
+ l.current && !l.current.contains(s.target) && i(!1);
567
584
  };
568
- return b(() => (document.addEventListener("click", p, !0), () => {
585
+ return v(() => (document.addEventListener("click", p, !0), () => {
569
586
  document.removeEventListener("click", p, !0);
570
- }), []), { ref: s, isComponentVisible: l, setIsComponentVisible: t };
587
+ }), []), { ref: l, isComponentVisible: t, setIsComponentVisible: i };
571
588
  }
572
- const En = ({ ...o }) => /* @__PURE__ */ d(
589
+ const zn = ({ ...o }) => /* @__PURE__ */ d(
573
590
  "svg",
574
591
  {
575
592
  xmlns: "http://www.w3.org/2000/svg",
@@ -601,7 +618,7 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
601
618
  )
602
619
  ]
603
620
  }
604
- ), zn = ({ width: o = 16 }) => /* @__PURE__ */ n(
621
+ ), Rn = ({ width: o = 16 }) => /* @__PURE__ */ n(
605
622
  "svg",
606
623
  {
607
624
  xmlns: "http://www.w3.org/2000/svg",
@@ -620,45 +637,44 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
620
637
  }
621
638
  )
622
639
  }
623
- ), Rn = yn(
640
+ ), Bn = Nn(
624
641
  ({
625
642
  positionDropdown: o,
626
- dropdownLists: l,
627
- isComponentVisible: t,
628
- searchAble: s,
643
+ dropdownLists: t,
644
+ isComponentVisible: i,
645
+ searchAble: l,
629
646
  hideSearch: p,
630
- onSearch: i,
631
- value: A,
632
- handleChangeValue: F,
633
- multiSelect: z,
647
+ onSearch: s,
648
+ value: j,
649
+ handleChangeValue: T,
650
+ multiSelect: E,
634
651
  searchValue: m,
635
- highlightedIndex: k,
636
- footer: T,
637
- groupLabel: $,
638
- onSelectAll: y
639
- }, K) => {
640
- const I = J([]), R = m !== void 0, [X, q] = j(""), Z = R ? m : X;
641
- b(() => {
652
+ highlightedIndex: y,
653
+ footer: $,
654
+ groupLabel: q,
655
+ onSelectAll: k,
656
+ emptyState: K
657
+ }, X) => {
658
+ const I = J([]), H = m !== void 0, [Y, Z] = L(""), A = H ? m : Y, c = !t || t.length === 0;
659
+ v(() => {
642
660
  var a;
643
- k >= 0 && I.current[k] && ((a = I.current[k]) == null || a.scrollIntoView({ block: "nearest" }));
644
- }, [k]), b(() => {
645
- !t && !R && q("");
646
- }, [t, R]);
647
- const w = s && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
648
- /* @__PURE__ */ n(En, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
661
+ y >= 0 && I.current[y] && ((a = I.current[y]) == null || a.scrollIntoView({ block: "nearest" }));
662
+ }, [y]);
663
+ const Q = l && !p ? /* @__PURE__ */ d("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
664
+ /* @__PURE__ */ n(zn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
649
665
  /* @__PURE__ */ n(
650
666
  "input",
651
667
  {
652
668
  onChange: (a) => {
653
- R || q(a.target.value), i && i(a.target.value);
669
+ H || Z(a.target.value), s && s(a.target.value);
654
670
  },
655
- value: Z,
671
+ value: A,
656
672
  autoFocus: !0,
657
673
  placeholder: "Search..."
658
674
  }
659
675
  )
660
676
  ] }) : null;
661
- return /* @__PURE__ */ n(pn, { children: t ? /* @__PURE__ */ d(
677
+ return /* @__PURE__ */ n(rn, { children: i ? /* @__PURE__ */ d(
662
678
  "div",
663
679
  {
664
680
  className: [
@@ -671,46 +687,55 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
671
687
  o === "top" ? "search-bottom" : ""
672
688
  ].filter(Boolean).join(" "),
673
689
  onClick: (a) => a.stopPropagation(),
674
- ref: K,
690
+ ref: X,
675
691
  children: [
676
- w,
692
+ Q,
677
693
  /* @__PURE__ */ d(
678
694
  "div",
679
695
  {
680
- className: `sa-input-dropdown-item-container ${z ? "multi" : ""}`,
696
+ className: `sa-input-dropdown-item-container ${E ? "multi" : ""}`,
681
697
  children: [
682
- $ && /* @__PURE__ */ d("div", { className: "sa-input-dropdown-section-header", children: [
683
- /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: $ }),
684
- z && y && /* @__PURE__ */ n(
698
+ c && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-empty", children: K ?? (A ? /* @__PURE__ */ d(rn, { children: [
699
+ "No results for",
700
+ " ",
701
+ /* @__PURE__ */ d("span", { className: "sa-input-dropdown-empty-query", children: [
702
+ "“",
703
+ A,
704
+ "”"
705
+ ] })
706
+ ] }) : "No data available") }),
707
+ q && !c && /* @__PURE__ */ d("div", { className: "sa-input-dropdown-section-header", children: [
708
+ /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: q }),
709
+ E && k && /* @__PURE__ */ n(
685
710
  "button",
686
711
  {
687
712
  className: "sa-input-dropdown-section-select-all",
688
713
  onClick: (a) => {
689
- a.stopPropagation(), y();
714
+ a.stopPropagation(), k();
690
715
  },
691
716
  children: "Select all"
692
717
  }
693
718
  )
694
719
  ] }),
695
- l.map((a, O) => {
696
- const H = !!(A != null && A.find((N) => N.value === a.value)), M = !!a.description;
720
+ t == null ? void 0 : t.map((a, M) => {
721
+ const z = !!(j != null && j.find((S) => S.value === a.value)), O = !!a.description;
697
722
  return /* @__PURE__ */ d(
698
723
  "div",
699
724
  {
700
725
  className: [
701
726
  "sa-input-dropdown-item",
702
- M ? "has-description" : "",
703
- H ? "active" : "",
704
- O === k ? "highlight" : "",
727
+ O ? "has-description" : "",
728
+ z ? "active" : "",
729
+ M === y ? "highlight" : "",
705
730
  a.disable ? "sa-input-dropdown-item-disable" : ""
706
731
  ].filter(Boolean).join(" "),
707
- ref: (N) => {
708
- I.current[O] = N;
732
+ ref: (S) => {
733
+ I.current[M] = S;
709
734
  },
710
- onClick: () => F(a.label, a.value),
735
+ onClick: () => T(a.label, a.value),
711
736
  children: [
712
- z && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: H && /* @__PURE__ */ n(zn, { width: 16 }) }),
713
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: cn.cloneElement(a.icon, { width: 16 }) }),
737
+ E && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: z && /* @__PURE__ */ n(Rn, { width: 16 }) }),
738
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: hn.cloneElement(a.icon, { width: 16 }) }),
714
739
  /* @__PURE__ */ d("div", { style: { minWidth: 0, flex: 1 }, children: [
715
740
  /* @__PURE__ */ n(
716
741
  "p",
@@ -735,183 +760,184 @@ const En = ({ ...o }) => /* @__PURE__ */ d(
735
760
  ] })
736
761
  ]
737
762
  },
738
- O
763
+ M
739
764
  );
740
765
  })
741
766
  ]
742
767
  }
743
768
  ),
744
- T && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: T })
769
+ $ && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: $ })
745
770
  ]
746
771
  }
747
772
  ) : null });
748
773
  }
749
- ), Bn = ({
774
+ ), Dn = ({
750
775
  children: o,
751
- handleChangePosition: l,
752
- enabled: t = !0
753
- }) => (b(() => {
754
- if (t)
755
- return window.addEventListener("scroll", l, !0), () => {
756
- window.removeEventListener("scroll", l, !0);
776
+ handleChangePosition: t,
777
+ enabled: i = !0
778
+ }) => (v(() => {
779
+ if (i)
780
+ return window.addEventListener("scroll", t, !0), () => {
781
+ window.removeEventListener("scroll", t, !0);
757
782
  };
758
- }, [t, l]), /* @__PURE__ */ n("div", { children: o })), sn = "sa-input-dropdown-styles", Ln = (o) => {
759
- if (!(typeof document > "u") && !document.getElementById(sn)) {
760
- const l = document.createElement("style");
761
- l.id = sn, l.textContent = o, document.head.appendChild(l);
783
+ }, [i, t]), /* @__PURE__ */ n("div", { children: o })), cn = "sa-input-dropdown-styles", Ln = (o) => {
784
+ if (!(typeof document > "u") && !document.getElementById(cn)) {
785
+ const t = document.createElement("style");
786
+ t.id = cn, t.textContent = o, document.head.appendChild(t);
762
787
  }
763
788
  };
764
- Ln(Nn);
765
- const Mn = ({
789
+ Ln(Cn);
790
+ const Sn = ({
766
791
  dropdownLists: o,
767
- onChange: l,
768
- defaultValue: t,
769
- value: s,
792
+ onChange: t,
793
+ defaultValue: i,
794
+ value: l,
770
795
  size: p = "sm",
771
- multiSelect: i,
772
- searchAble: A,
773
- iconLeft: F,
774
- placeholder: z,
796
+ multiSelect: s,
797
+ searchAble: j,
798
+ iconLeft: T,
799
+ placeholder: E,
775
800
  onSearch: m,
776
- error: k,
777
- onBlur: T,
778
- onFocus: $,
779
- disable: y,
801
+ error: y,
802
+ onBlur: $,
803
+ onFocus: q,
804
+ disable: k,
780
805
  searchValue: K,
781
- variant: I = "outline",
782
- footer: R,
783
- groupLabel: X,
784
- onSelectAll: q,
785
- fullWidth: Z = !0,
786
- triggerInput: w = !1,
787
- clearOnSelect: a = !1,
788
- hideChevronIcon: O = !1,
789
- clearable: H = !1,
790
- onClear: M,
806
+ variant: X = "outline",
807
+ footer: I,
808
+ groupLabel: H,
809
+ onSelectAll: Y,
810
+ emptyState: Z,
811
+ fullWidth: A = !0,
812
+ triggerInput: c = !1,
813
+ clearOnSelect: Q = !1,
814
+ hideChevronIcon: a = !1,
815
+ clearable: M = !1,
816
+ onClear: z,
791
817
  /* field wrapper */
792
- label: N,
793
- labelPosition: wn = "outside-top",
794
- required: en,
795
- optional: on,
796
- description: B,
797
- helperText: L,
818
+ label: O,
819
+ labelPosition: S = "outside-top",
820
+ required: an,
821
+ optional: tn,
822
+ description: R,
823
+ helperText: B,
798
824
  errorText: h
799
825
  }) => {
800
- const Q = [
826
+ const _ = [
801
827
  "sa-select-field",
802
828
  `sa-select-field-size-${p}`,
803
- Z ? "sa-select-field-fullwidth" : ""
804
- ].filter(Boolean).join(" "), C = s !== void 0, Y = J(), un = k || !!h, [c, D] = j(
805
- C ? s || [] : t || []
806
- ), [hn, rn] = j(""), [v, _] = j(-1), [fn, G] = j(
829
+ A ? "sa-select-field-fullwidth" : ""
830
+ ].filter(Boolean).join(" "), N = l !== void 0, V = J(), fn = y || !!h, [u, D] = L(
831
+ N ? l || [] : i || []
832
+ ), [bn, sn] = L(""), [x, nn] = L(-1), [dn, G] = L(
807
833
  () => {
808
834
  var e, r;
809
- return !i && (s != null && s.length || t != null && t.length) ? ((e = s == null ? void 0 : s[0]) == null ? void 0 : e.label) ?? ((r = t == null ? void 0 : t[0]) == null ? void 0 : r.label) ?? "" : "";
835
+ 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) ?? "" : "";
810
836
  }
811
- ), g = J(null), { isComponentVisible: u, ref: V, setIsComponentVisible: E } = Cn(!1), P = o !== void 0, an = c.length > 0, bn = (e) => {
837
+ ), b = J(null), { isComponentVisible: w, ref: en, setIsComponentVisible: C } = En(!1), W = o !== void 0, ln = u.length > 0, gn = (e) => {
812
838
  e.stopPropagation();
813
839
  const r = [];
814
- C || D(r), l(r), w && G(""), M == null || M();
815
- }, gn = () => {
816
- P && E((e) => !e);
840
+ N || D(r), t(r), c && G(""), z == null || z();
841
+ }, vn = () => {
842
+ W && C((e) => !e);
817
843
  }, U = (e, r) => {
818
- if (i) {
819
- if (c == null ? void 0 : c.find((x) => x.value === r)) {
820
- const x = c.filter((kn) => kn.value !== r);
821
- C || D(x), l(x);
844
+ if (s) {
845
+ if (u == null ? void 0 : u.find((g) => g.value === r)) {
846
+ const g = u.filter((kn) => kn.value !== r);
847
+ N || D(g), t(g);
822
848
  } else {
823
- const x = [...c, { label: e, value: r }];
824
- C || D(x), l(x);
849
+ const g = [...u, { label: e, value: r }];
850
+ N || D(g), t(g);
825
851
  }
826
- w && G("");
852
+ c && G("");
827
853
  } else {
828
854
  const f = [{ label: e, value: r }];
829
- C || D(f), l(f), w && G(a ? "" : e), E(!1);
855
+ N || D(f), t(f), c && G(Q ? "" : e), C(!1);
830
856
  }
831
857
  };
832
- b(() => {
833
- C && D(s || []);
834
- }, [s]), b(() => {
835
- C || JSON.stringify(Y.current) === JSON.stringify(t) || (Y.current = t, D(Y.current || []));
836
- }, [t]);
837
- const xn = () => c.length ? i ? c == null ? void 0 : c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
858
+ v(() => {
859
+ N && D(l || []);
860
+ }, [l]), v(() => {
861
+ N || JSON.stringify(V.current) === JSON.stringify(i) || (V.current = i, D(V.current || []));
862
+ }, [i]);
863
+ const xn = () => u.length ? s ? u == null ? void 0 : u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
838
864
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
839
865
  /* @__PURE__ */ n(
840
- ln,
866
+ wn,
841
867
  {
842
868
  onClick: (f) => {
843
869
  f.stopPropagation(), U(e.label, e.value);
844
870
  }
845
871
  }
846
872
  )
847
- ] }, r)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: z }), S = () => {
848
- if (V.current && g.current) {
849
- const e = window.innerHeight, r = V.current.getBoundingClientRect(), f = g.current.getBoundingClientRect(), x = r.bottom + f.height;
850
- g.current.style.left = `${r.left}px`, g.current.style.width = `${r.width}px`, x >= e - 10 ? (g.current.style.top = `${r.top - f.height - 5}px`, rn("top")) : (g.current.style.top = `${r.top + r.height + 4}px`, rn("bottom"));
873
+ ] }, 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 }), P = () => {
874
+ if (en.current && b.current) {
875
+ const e = window.innerHeight, r = en.current.getBoundingClientRect(), f = b.current.getBoundingClientRect(), g = r.bottom + f.height;
876
+ 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"));
851
877
  }
852
878
  };
853
- b(() => (window.addEventListener("resize", S), () => {
854
- window.removeEventListener("resize", S);
855
- }), []), b(() => {
856
- S();
857
- }, [u]), b(() => {
858
- if (!u || !g.current)
879
+ v(() => (window.addEventListener("resize", P), () => {
880
+ window.removeEventListener("resize", P);
881
+ }), []), v(() => {
882
+ P();
883
+ }, [w]), v(() => {
884
+ if (!w || !b.current)
859
885
  return;
860
886
  const e = new ResizeObserver(() => {
861
- S();
887
+ P();
862
888
  });
863
- return e.observe(g.current), () => e.disconnect();
864
- }, [u]), b(() => {
865
- u || _(-1);
866
- }, [u]);
867
- const tn = (e) => {
868
- if (P) {
869
- if (!u) {
870
- (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), E(!0));
889
+ return e.observe(b.current), () => e.disconnect();
890
+ }, [w]), v(() => {
891
+ w || nn(-1);
892
+ }, [w]);
893
+ const pn = (e) => {
894
+ if (W) {
895
+ if (!w) {
896
+ (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
871
897
  return;
872
898
  }
873
899
  switch (e.key) {
874
900
  case "ArrowDown": {
875
901
  e.preventDefault();
876
- const r = dn(o, v, 1);
877
- r !== -1 && _(r);
902
+ const r = un(o, x, 1);
903
+ r !== -1 && nn(r);
878
904
  break;
879
905
  }
880
906
  case "ArrowUp": {
881
907
  e.preventDefault();
882
- const r = dn(o, v, -1);
883
- r !== -1 && _(r);
908
+ const r = un(o, x, -1);
909
+ r !== -1 && nn(r);
884
910
  break;
885
911
  }
886
912
  case "Enter": {
887
- e.preventDefault(), v >= 0 && o[v] && !o[v].disable && U(
888
- o[v].label,
889
- o[v].value
913
+ e.preventDefault(), x >= 0 && o[x] && !o[x].disable && U(
914
+ o[x].label,
915
+ o[x].value
890
916
  );
891
917
  break;
892
918
  }
893
919
  case "Escape":
894
- E(!1);
920
+ C(!1);
895
921
  break;
896
922
  }
897
923
  }
898
- }, W = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, vn = H && !y ? /* @__PURE__ */ n(
924
+ }, F = p === "lg" || p === "xl" ? 20 : p === "xs" ? 14 : 16, mn = M && !k ? /* @__PURE__ */ n(
899
925
  "button",
900
926
  {
901
927
  type: "button",
902
- className: `sa-input-dropdown-clear${an ? "" : " sa-input-dropdown-clear-hidden"}`,
928
+ className: `sa-input-dropdown-clear${ln ? "" : " sa-input-dropdown-clear-hidden"}`,
903
929
  "aria-label": "Clear selection",
904
- "aria-hidden": !an,
930
+ "aria-hidden": !ln,
905
931
  tabIndex: -1,
906
- onClick: bn,
932
+ onClick: gn,
907
933
  onMouseDown: (e) => e.preventDefault(),
908
- children: /* @__PURE__ */ n(Dn, { width: W, height: W })
934
+ children: /* @__PURE__ */ n(jn, { width: F, height: F })
909
935
  }
910
- ) : null, mn = w ? /* @__PURE__ */ d(pn, { children: [
911
- i && c.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
936
+ ) : null, yn = c ? /* @__PURE__ */ d(rn, { children: [
937
+ s && u.map((e, r) => /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-item", children: [
912
938
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
913
939
  /* @__PURE__ */ n(
914
- ln,
940
+ wn,
915
941
  {
916
942
  onClick: (f) => {
917
943
  f.stopPropagation(), U(e.label, e.value);
@@ -923,73 +949,74 @@ const Mn = ({
923
949
  "input",
924
950
  {
925
951
  className: "sa-input-dropdown-trigger-input",
926
- value: fn,
952
+ value: dn,
927
953
  onChange: (e) => {
928
954
  const r = e.target.value;
929
- G(r), m == null || m(r), !u && P && E(!0);
955
+ G(r), m == null || m(r), !w && W && C(!0);
930
956
  },
931
957
  onFocus: () => {
932
- !y && P && E(!0);
958
+ !k && W && C(!0);
933
959
  },
934
960
  onBlur: () => {
935
- i || setTimeout(() => E(!1), 150);
961
+ s || setTimeout(() => C(!1), 150);
936
962
  },
937
- onKeyDown: tn,
938
- placeholder: c.length === 0 || i ? z : void 0,
939
- disabled: y
963
+ onKeyDown: pn,
964
+ placeholder: u.length === 0 || s ? E : void 0,
965
+ disabled: k
940
966
  }
941
967
  )
942
- ] }) : null, nn = /* @__PURE__ */ n(
943
- Bn,
968
+ ] }) : null, on = /* @__PURE__ */ n(
969
+ Dn,
944
970
  {
945
- handleChangePosition: S,
946
- enabled: u,
971
+ handleChangePosition: P,
972
+ enabled: w,
947
973
  children: /* @__PURE__ */ d(
948
974
  "div",
949
975
  {
950
976
  className: [
951
977
  "sa-input-dropdown-container",
952
- I,
978
+ X,
953
979
  `sa-input-dropdown-size-${p}`,
954
- w ? "trigger-input" : "",
955
- u ? "active" : "",
956
- un ? "error" : "",
957
- y ? "disable" : ""
980
+ c ? "trigger-input" : "",
981
+ w ? "active" : "",
982
+ fn ? "error" : "",
983
+ k ? "disable" : ""
958
984
  ].filter(Boolean).join(" "),
959
- ref: V,
960
- onClick: w ? void 0 : gn,
961
- onKeyDown: w ? void 0 : tn,
962
- tabIndex: w ? void 0 : 0,
963
- onBlur: w ? void 0 : T,
964
- onFocus: w ? void 0 : $,
985
+ ref: en,
986
+ onClick: c ? void 0 : vn,
987
+ onKeyDown: c ? void 0 : pn,
988
+ tabIndex: c ? void 0 : 0,
989
+ onBlur: c ? void 0 : $,
990
+ onFocus: c ? void 0 : q,
965
991
  children: [
966
992
  /* @__PURE__ */ d("div", { className: "sa-input-dropdown-preview-container", children: [
967
- F ? cn.cloneElement(F, {
968
- width: W,
993
+ T ? hn.cloneElement(T, {
994
+ width: F,
969
995
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
970
996
  }) : null,
971
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : xn() }),
972
- vn,
973
- !O && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: u ? /* @__PURE__ */ n(An, { width: W }) : /* @__PURE__ */ n(jn, { width: W }) })
997
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: c ? yn : xn() }),
998
+ mn,
999
+ !a && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: w ? /* @__PURE__ */ n(An, { width: F }) : /* @__PURE__ */ n(In, { width: F }) })
974
1000
  ] }),
975
- P && /* @__PURE__ */ n(
976
- Rn,
1001
+ W && /* @__PURE__ */ n(
1002
+ Bn,
977
1003
  {
978
1004
  dropdownLists: o,
979
1005
  handleChangeValue: U,
980
- isComponentVisible: u,
981
- positionDropdown: hn,
982
- searchAble: !!A,
983
- hideSearch: w,
984
- value: c,
1006
+ isComponentVisible: w,
1007
+ positionDropdown: bn,
1008
+ searchAble: !!j,
1009
+ hideSearch: c,
1010
+ value: u,
985
1011
  onSearch: m,
986
- ref: g,
987
- multiSelect: i,
988
- searchValue: K,
989
- highlightedIndex: v,
990
- footer: R,
991
- groupLabel: X,
992
- onSelectAll: q
1012
+ ref: b,
1013
+ multiSelect: s,
1014
+ searchValue: c ? dn : K,
1015
+ highlightedIndex: x,
1016
+ footer: I,
1017
+ groupLabel: H,
1018
+ onSelectAll: Y,
1019
+ emptyState: Z
993
1020
  }
994
1021
  )
995
1022
  ]
@@ -997,57 +1024,57 @@ const Mn = ({
997
1024
  )
998
1025
  }
999
1026
  );
1000
- return N ? wn === "outside-left" ? /* @__PURE__ */ d("div", { className: `${Q} sa-select-field-left`, children: [
1027
+ return O ? S === "outside-left" ? /* @__PURE__ */ d("div", { className: `${_} sa-select-field-left`, children: [
1001
1028
  /* @__PURE__ */ d("div", { className: "sa-select-field-left-label", children: [
1002
1029
  /* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
1003
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: N }),
1004
- on && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1005
- en && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1030
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: O }),
1031
+ tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1032
+ an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1006
1033
  ] }),
1007
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B })
1034
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R })
1008
1035
  ] }),
1009
1036
  /* @__PURE__ */ d("div", { className: "sa-select-field-input-wrap", children: [
1010
- nn,
1011
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1037
+ on,
1038
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
1012
1039
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1013
1040
  ] })
1014
- ] }) : /* @__PURE__ */ d("div", { className: Q, children: [
1041
+ ] }) : /* @__PURE__ */ d("div", { className: _, children: [
1015
1042
  /* @__PURE__ */ d("div", { className: "sa-select-field-label-row", children: [
1016
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: N }),
1017
- on && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1018
- en && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1043
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: O }),
1044
+ tn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
1045
+ an && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
1019
1046
  ] }),
1020
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
1021
- nn,
1022
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1047
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
1048
+ on,
1049
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
1023
1050
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1024
- ] }) : /* @__PURE__ */ d("div", { className: Q, children: [
1025
- B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
1026
- nn,
1027
- L && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: L }),
1051
+ ] }) : /* @__PURE__ */ d("div", { className: _, children: [
1052
+ R && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: R }),
1053
+ on,
1054
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
1028
1055
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
1029
1056
  ] });
1030
- }, dn = (o, l, t) => {
1031
- const s = o.length;
1032
- let p = l + t;
1033
- for (; p >= 0 && p < s; ) {
1057
+ }, un = (o, t, i) => {
1058
+ const l = o.length;
1059
+ let p = t + i;
1060
+ for (; p >= 0 && p < l; ) {
1034
1061
  if (!o[p].disable)
1035
1062
  return p;
1036
- p += t;
1063
+ p += i;
1037
1064
  }
1038
- if (t === 1) {
1039
- for (let i = 0; i < s; i++)
1040
- if (!o[i].disable)
1041
- return i;
1065
+ if (i === 1) {
1066
+ for (let s = 0; s < l; s++)
1067
+ if (!o[s].disable)
1068
+ return s;
1042
1069
  } else
1043
- for (let i = s - 1; i >= 0; i--)
1044
- if (!o[i].disable)
1045
- return i;
1070
+ for (let s = l - 1; s >= 0; s--)
1071
+ if (!o[s].disable)
1072
+ return s;
1046
1073
  return -1;
1047
- }, Dn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1074
+ }, jn = (o) => /* @__PURE__ */ d("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1048
1075
  /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1049
1076
  /* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
1050
- ] }), ln = (o) => /* @__PURE__ */ n(
1077
+ ] }), wn = (o) => /* @__PURE__ */ n(
1051
1078
  "svg",
1052
1079
  {
1053
1080
  xmlns: "http://www.w3.org/2000/svg",
@@ -1068,7 +1095,7 @@ const Mn = ({
1068
1095
  }
1069
1096
  )
1070
1097
  }
1071
- ), jn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1098
+ ), In = ({ width: o = 16 }) => /* @__PURE__ */ n(
1072
1099
  "svg",
1073
1100
  {
1074
1101
  xmlns: "http://www.w3.org/2000/svg",
@@ -1110,5 +1137,5 @@ const Mn = ({
1110
1137
  }
1111
1138
  );
1112
1139
  export {
1113
- Mn as Dropdown
1140
+ Sn as Dropdown
1114
1141
  };
@@ -1,8 +1,7 @@
1
- (function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Dropdown={},x.jsxRuntime,x.React))})(this,function(x,n,d){"use strict";const tn=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
2
- * {
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,s){"use strict";const cn=`* {
3
2
  margin: 0;
4
3
  padding: 0;
5
- font-family: "Poppins", sans-serif;
4
+ font-family: var(--sa-font-family, "Inter", sans-serif);
6
5
  box-sizing: border-box;
7
6
  }
8
7
 
@@ -263,7 +262,7 @@
263
262
  width: 100%;
264
263
  display: flex;
265
264
  flex-direction: column;
266
- font-family: "Poppins", sans-serif;
265
+ font-family: var(--sa-font-family, "Inter", sans-serif);
267
266
  }
268
267
 
269
268
  /* === SEARCH BAR === */
@@ -321,6 +320,24 @@
321
320
  gap: 4px;
322
321
  }
323
322
 
323
+ /* === EMPTY STATE ===
324
+ Rendered inside the list container, so an empty panel is just the search bar
325
+ plus this message — no leftover padding strip, no footer border to collide
326
+ with. */
327
+ .sa-input-dropdown-empty {
328
+ padding: 20px 12px;
329
+ text-align: center;
330
+ font-size: 12px;
331
+ font-weight: 400;
332
+ line-height: 1.5;
333
+ color: var(--sa-dropdown-placeholder-subtle);
334
+ overflow-wrap: anywhere;
335
+ }
336
+ .sa-input-dropdown-empty-query {
337
+ color: var(--sa-dropdown-text-primary);
338
+ font-weight: 500;
339
+ }
340
+
324
341
  /* === SECTION HEADER === */
325
342
  .sa-input-dropdown-section-header {
326
343
  display: flex;
@@ -440,7 +457,7 @@
440
457
  flex-direction: column;
441
458
  gap: 8px;
442
459
  width: max-content;
443
- font-family: "Poppins", sans-serif;
460
+ font-family: var(--sa-font-family, "Inter", sans-serif);
444
461
  }
445
462
  .sa-select-field-fullwidth {
446
463
  width: 100%;
@@ -558,4 +575,4 @@
558
575
  display: none;
559
576
  }
560
577
 
561
- `;function ln(o){const[l,s]=d.useState(o),i=d.useRef(null),p=t=>{i.current&&!i.current.contains(t.target)&&s(!1)};return d.useEffect(()=>(document.addEventListener("click",p,!0),()=>{document.removeEventListener("click",p,!0)}),[]),{ref:i,isComponentVisible:l,setIsComponentVisible:s}}const pn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),cn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),wn=d.forwardRef(({positionDropdown:o,dropdownLists:l,isComponentVisible:s,searchAble:i,hideSearch:p,onSearch:t,value:j,handleChangeValue:F,multiSelect:z,searchValue:m,highlightedIndex:k,footer:T,groupLabel:$,onSelectAll:y},J)=>{const O=d.useRef([]),B=m!==void 0,[K,q]=d.useState(""),X=B?m:K;d.useEffect(()=>{var a;k>=0&&O.current[k]&&((a=O.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]),d.useEffect(()=>{!s&&!B&&q("")},[s,B]);const w=i&&!p?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(pn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{B||q(a.target.value),t&&t(a.target.value)},value:X,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:s?n.jsxs("div",{className:["sa-input-dropdown-lists-container",o==="top"?"search-bottom":""].filter(Boolean).join(" "),onClick:a=>a.stopPropagation(),ref:J,children:[w,n.jsxs("div",{className:`sa-input-dropdown-item-container ${z?"multi":""}`,children:[$&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:$}),z&&y&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),y()},children:"Select all"})]}),l.map((a,A)=>{const H=!!(j!=null&&j.find(N=>N.value===a.value)),I=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",I?"has-description":"",H?"active":"",A===k?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:N=>{O.current[A]=N},onClick:()=>F(a.label,a.value),children:[z&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:H&&n.jsx(cn,{width:16})}),a.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:d.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},A)})]}),T&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:T})]}):null})}),fn=({children:o,handleChangePosition:l,enabled:s=!0})=>(d.useEffect(()=>{if(s)return window.addEventListener("scroll",l,!0),()=>{window.removeEventListener("scroll",l,!0)}},[s,l]),n.jsx("div",{children:o})),R="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!document.getElementById(R)){const l=document.createElement("style");l.id=R,l.textContent=o,document.head.appendChild(l)}})(tn);const hn=({dropdownLists:o,onChange:l,defaultValue:s,value:i,size:p="sm",multiSelect:t,searchAble:j,iconLeft:F,placeholder:z,onSearch:m,error:k,onBlur:T,onFocus:$,disable:y,searchValue:J,variant:O="outline",footer:B,groupLabel:K,onSelectAll:q,fullWidth:X=!0,triggerInput:w=!1,clearOnSelect:a=!1,hideChevronIcon:A=!1,clearable:H=!1,onClear:I,label:N,labelPosition:xn="outside-top",required:on,optional:rn,description:L,helperText:D,errorText:h})=>{const Z=["sa-select-field",`sa-select-field-size-${p}`,X?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=i!==void 0,Q=d.useRef(),vn=k||!!h,[c,S]=d.useState(E?i||[]:s||[]),[mn,an]=d.useState(""),[v,Y]=d.useState(-1),[kn,G]=d.useState(()=>{var e,r;return!t&&(i!=null&&i.length||s!=null&&s.length)?((e=i==null?void 0:i[0])==null?void 0:e.label)??((r=s==null?void 0:s[0])==null?void 0:r.label)??"":""}),b=d.useRef(null),{isComponentVisible:f,ref:_,setIsComponentVisible:C}=ln(!1),M=o!==void 0,sn=c.length>0,yn=e=>{e.stopPropagation();const r=[];E||S(r),l(r),w&&G(""),I==null||I()},Nn=()=>{M&&C(e=>!e)},U=(e,r)=>{if(t){if(c==null?void 0:c.find(g=>g.value===r)){const g=c.filter(Bn=>Bn.value!==r);E||S(g),l(g)}else{const g=[...c,{label:e,value:r}];E||S(g),l(g)}w&&G("")}else{const u=[{label:e,value:r}];E||S(u),l(u),w&&G(a?"":e),C(!1)}};d.useEffect(()=>{E&&S(i||[])},[i]),d.useEffect(()=>{E||JSON.stringify(Q.current)===JSON.stringify(s)||(Q.current=s,S(Q.current||[]))},[s]);const En=()=>c.length?t?c==null?void 0:c.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(en,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:z}),P=()=>{if(_.current&&b.current){const e=window.innerHeight,r=_.current.getBoundingClientRect(),u=b.current.getBoundingClientRect(),g=r.bottom+u.height;b.current.style.left=`${r.left}px`,b.current.style.width=`${r.width}px`,g>=e-10?(b.current.style.top=`${r.top-u.height-5}px`,an("top")):(b.current.style.top=`${r.top+r.height+4}px`,an("bottom"))}};d.useEffect(()=>(window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P)}),[]),d.useEffect(()=>{P()},[f]),d.useEffect(()=>{if(!f||!b.current)return;const e=new ResizeObserver(()=>{P()});return e.observe(b.current),()=>e.disconnect()},[f]),d.useEffect(()=>{f||Y(-1)},[f]);const dn=e=>{if(M){if(!f){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=nn(o,v,1);r!==-1&&Y(r);break}case"ArrowUp":{e.preventDefault();const r=nn(o,v,-1);r!==-1&&Y(r);break}case"Enter":{e.preventDefault(),v>=0&&o[v]&&!o[v].disable&&U(o[v].label,o[v].value);break}case"Escape":C(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,Cn=H&&!y?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${sn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!sn,tabIndex:-1,onClick:yn,onMouseDown:e=>e.preventDefault(),children:n.jsx(un,{width:W,height:W})}):null,zn=w?n.jsxs(n.Fragment,{children:[t&&c.map((e,r)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(en,{onClick:u=>{u.stopPropagation(),U(e.label,e.value)}})]},r)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:kn,onChange:e=>{const r=e.target.value;G(r),m==null||m(r),!f&&M&&C(!0)},onFocus:()=>{!y&&M&&C(!0)},onBlur:()=>{t||setTimeout(()=>C(!1),150)},onKeyDown:dn,placeholder:c.length===0||t?z:void 0,disabled:y})]}):null,V=n.jsx(fn,{handleChangePosition:P,enabled:f,children:n.jsxs("div",{className:["sa-input-dropdown-container",O,`sa-input-dropdown-size-${p}`,w?"trigger-input":"",f?"active":"",vn?"error":"",y?"disable":""].filter(Boolean).join(" "),ref:_,onClick:w?void 0:Nn,onKeyDown:w?void 0:dn,tabIndex:w?void 0:0,onBlur:w?void 0:T,onFocus:w?void 0:$,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[F?d.cloneElement(F,{width:W,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?zn:En()}),Cn,!A&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:f?n.jsx(gn,{width:W}):n.jsx(bn,{width:W})})]}),M&&n.jsx(wn,{dropdownLists:o,handleChangeValue:U,isComponentVisible:f,positionDropdown:mn,searchAble:!!j,hideSearch:w,value:c,onSearch:m,ref:b,multiSelect:t,searchValue:J,highlightedIndex:v,footer:B,groupLabel:K,onSelectAll:q})]})});return N?xn==="outside-left"?n.jsxs("div",{className:`${Z} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:N}),rn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),on&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[V,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):n.jsxs("div",{className:Z,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:N}),rn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),on&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L}),V,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:Z,children:[L&&n.jsx("p",{className:"sa-select-field-helper-top",children:L}),V,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},nn=(o,l,s)=>{const i=o.length;let p=l+s;for(;p>=0&&p<i;){if(!o[p].disable)return p;p+=s}if(s===1){for(let t=0;t<i;t++)if(!o[t].disable)return t}else for(let t=i-1;t>=0;t--)if(!o[t].disable)return t;return-1},un=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),en=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),bn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),gn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});x.Dropdown=hn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
578
+ `;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(""),I=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:I,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??(I?n.jsxs(n.Fragment,{children:["No results for"," ",n.jsxs("span",{className:"sa-input-dropdown-empty-query",children:["“",I,"”"]})]}):"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,A)=>{const z=!!(L!=null&&L.find(O=>O.value===a.value)),M=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",M?"has-description":"",z?"active":"",A===y?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{j.current[A]=O},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})]})]},A)})]}),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:I=!0,triggerInput:c=!1,clearOnSelect:Z=!1,hideChevronIcon:a=!1,clearable:A=!1,onClear:z,label:M,labelPosition:O="outside-top",required:an,optional:sn,description:B,helperText:D,errorText:f})=>{const Q=["sa-select-field",`sa-select-field-size-${p}`,I?"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(""),[x,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),F=o!==void 0,ln=w.length>0,Nn=e=>{e.stopPropagation();const r=[];N||S(r),t(r),c&&G(""),z==null||z()},En=()=>{F&&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}),P=()=>{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",P),()=>{window.removeEventListener("resize",P)}),[]),s.useEffect(()=>{P()},[h]),s.useEffect(()=>{if(!h||!b.current)return;const e=new ResizeObserver(()=>{P()});return e.observe(b.current),()=>e.disconnect()},[h]),s.useEffect(()=>{h||V(-1)},[h]);const pn=e=>{if(F){if(!h){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const r=on(o,x,1);r!==-1&&V(r);break}case"ArrowUp":{e.preventDefault();const r=on(o,x,-1);r!==-1&&V(r);break}case"Enter":{e.preventDefault(),x>=0&&o[x]&&!o[x].disable&&U(o[x].label,o[x].value);break}case"Escape":E(!1);break}}},W=p==="lg"||p==="xl"?20:p==="xs"?14:16,zn=A&&!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(vn,{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&&F&&E(!0)},onFocus:()=>{!k&&F&&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:P,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(xn,{width:W})})]}),F&&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:x,footer:j,groupLabel:H,onSelectAll:X,emptyState:Y})]})});return M?O==="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:M}),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:M}),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},vn=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"})}),xn=({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"})});v.Dropdown=gn,Object.defineProperty(v,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.6",
3
+ "version": "6.0.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",