@starasia/dropdown 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { jsxs as p, jsx as n, Fragment as G } from "react/jsx-runtime";
2
- import J, { useState as O, useRef as L, useEffect as x, forwardRef as Y } from "react";
3
- const _ = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ import { jsxs as t, jsx as n, Fragment as sn } from "react/jsx-runtime";
2
+ import Y, { useState as P, useRef as I, useEffect as v, forwardRef as tn } from "react";
3
+ const dn = `@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;
@@ -500,15 +500,15 @@ const _ = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@30
500
500
  width: 100%;
501
501
  }
502
502
  `;
503
- function nn(e) {
504
- const [l, i] = O(e), d = L(null), o = (r) => {
505
- d.current && !d.current.contains(r.target) && i(!1);
503
+ function ln(e) {
504
+ const [p, d] = P(e), l = I(null), o = (r) => {
505
+ l.current && !l.current.contains(r.target) && d(!1);
506
506
  };
507
- return x(() => (document.addEventListener("click", o, !0), () => {
507
+ return v(() => (document.addEventListener("click", o, !0), () => {
508
508
  document.removeEventListener("click", o, !0);
509
- }), []), { ref: d, isComponentVisible: l, setIsComponentVisible: i };
509
+ }), []), { ref: l, isComponentVisible: p, setIsComponentVisible: d };
510
510
  }
511
- const en = ({ ...e }) => /* @__PURE__ */ p(
511
+ const pn = ({ ...e }) => /* @__PURE__ */ t(
512
512
  "svg",
513
513
  {
514
514
  xmlns: "http://www.w3.org/2000/svg",
@@ -540,8 +540,8 @@ const en = ({ ...e }) => /* @__PURE__ */ p(
540
540
  )
541
541
  ]
542
542
  }
543
- ), rn = ({ isChecked: e }) => /* @__PURE__ */ p("div", { className: "checkbox-wrapper-30", children: [
544
- /* @__PURE__ */ p("span", { className: "checkbox", children: [
543
+ ), cn = ({ isChecked: e }) => /* @__PURE__ */ t("div", { className: "checkbox-wrapper-30", children: [
544
+ /* @__PURE__ */ t("span", { className: "checkbox", children: [
545
545
  /* @__PURE__ */ n(
546
546
  "input",
547
547
  {
@@ -560,92 +560,92 @@ const en = ({ ...e }) => /* @__PURE__ */ p(
560
560
  d: "M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"
561
561
  }
562
562
  ) }) })
563
- ] }), on = Y(
563
+ ] }), hn = tn(
564
564
  ({
565
565
  positionDropdown: e,
566
- dropdownLists: l,
567
- isComponentVisible: i,
568
- searchAble: d,
566
+ dropdownLists: p,
567
+ isComponentVisible: d,
568
+ searchAble: l,
569
569
  onSearch: o,
570
570
  value: r,
571
- handleChangeValue: c,
572
- multiSelect: u,
573
- searchValue: y,
574
- highlightedIndex: h,
575
- footer: g,
576
- groupLabel: S,
577
- onSelectAll: I
578
- }, j) => {
579
- const z = L([]);
580
- x(() => {
571
+ handleChangeValue: y,
572
+ multiSelect: h,
573
+ searchValue: F,
574
+ highlightedIndex: x,
575
+ footer: A,
576
+ groupLabel: O,
577
+ onSelectAll: D
578
+ }, H) => {
579
+ const R = I([]);
580
+ v(() => {
581
581
  var a;
582
- h >= 0 && z.current[h] && ((a = z.current[h]) == null || a.scrollIntoView({ block: "nearest" }));
583
- }, [h]);
584
- const A = d ? /* @__PURE__ */ p("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
585
- /* @__PURE__ */ n(en, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
582
+ x >= 0 && R.current[x] && ((a = R.current[x]) == null || a.scrollIntoView({ block: "nearest" }));
583
+ }, [x]);
584
+ const j = l ? /* @__PURE__ */ t("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
585
+ /* @__PURE__ */ n(pn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
586
586
  /* @__PURE__ */ n(
587
587
  "input",
588
588
  {
589
589
  onChange: (a) => {
590
590
  o && o(a.target.value);
591
591
  },
592
- value: y,
592
+ value: F,
593
593
  autoFocus: !0,
594
594
  placeholder: "Search..."
595
595
  }
596
596
  )
597
597
  ] }) : null;
598
- return /* @__PURE__ */ n(G, { children: i ? /* @__PURE__ */ p(
598
+ return /* @__PURE__ */ n(sn, { children: d ? /* @__PURE__ */ t(
599
599
  "div",
600
600
  {
601
601
  className: "sa-input-dropdown-lists-container",
602
602
  onClick: (a) => a.stopPropagation(),
603
- ref: j,
603
+ ref: H,
604
604
  children: [
605
- e !== "top" && A,
606
- /* @__PURE__ */ p(
605
+ e !== "top" && j,
606
+ /* @__PURE__ */ t(
607
607
  "div",
608
608
  {
609
- className: `sa-input-dropdwon-item-container ${u ? "multi" : ""}`,
609
+ className: `sa-input-dropdwon-item-container ${h ? "multi" : ""}`,
610
610
  children: [
611
- S && /* @__PURE__ */ p("div", { className: "sa-input-dropdown-section-header", children: [
612
- /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: S }),
613
- u && I && /* @__PURE__ */ n(
611
+ O && /* @__PURE__ */ t("div", { className: "sa-input-dropdown-section-header", children: [
612
+ /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: O }),
613
+ h && D && /* @__PURE__ */ n(
614
614
  "button",
615
615
  {
616
616
  className: "sa-input-dropdown-section-select-all",
617
617
  onClick: (a) => {
618
- a.stopPropagation(), I();
618
+ a.stopPropagation(), D();
619
619
  },
620
620
  children: "Select all"
621
621
  }
622
622
  )
623
623
  ] }),
624
- l.map((a, B) => {
625
- const C = !!(r != null && r.find((b) => b.value === a.value));
626
- return /* @__PURE__ */ p(
624
+ p.map((a, S) => {
625
+ const N = !!(r != null && r.find((g) => g.value === a.value));
626
+ return /* @__PURE__ */ t(
627
627
  "div",
628
628
  {
629
629
  className: [
630
630
  "sa-input-dropdwon-item",
631
- C ? "active" : "",
632
- B === h ? "highlight" : "",
631
+ N ? "active" : "",
632
+ S === x ? "highlight" : "",
633
633
  a.disable ? "sa-input-dropdwon-item-disable" : ""
634
634
  ].filter(Boolean).join(" "),
635
- ref: (b) => {
636
- z.current[B] = b;
635
+ ref: (g) => {
636
+ R.current[S] = g;
637
637
  },
638
- onClick: () => c(a.label, a.value),
638
+ onClick: () => y(a.label, a.value),
639
639
  children: [
640
- u && /* @__PURE__ */ n("div", { style: { flexShrink: 0 }, children: /* @__PURE__ */ n(rn, { isChecked: C }) }),
641
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0 }, children: J.cloneElement(a.icon, { width: 16 }) }),
642
- /* @__PURE__ */ p("div", { style: { minWidth: 0, flex: 1 }, children: [
640
+ h && /* @__PURE__ */ n("div", { style: { flexShrink: 0 }, children: /* @__PURE__ */ n(cn, { isChecked: N }) }),
641
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0 }, children: Y.cloneElement(a.icon, { width: 16 }) }),
642
+ /* @__PURE__ */ t("div", { style: { minWidth: 0, flex: 1 }, children: [
643
643
  /* @__PURE__ */ n(
644
644
  "p",
645
645
  {
646
646
  className: [
647
647
  "sa-input-dropdwon-item-text",
648
- C ? "active" : "",
648
+ N ? "active" : "",
649
649
  a.disable ? "sa-input-dropdwon-item-disable" : ""
650
650
  ].filter(Boolean).join(" "),
651
651
  children: a.label
@@ -656,7 +656,7 @@ const en = ({ ...e }) => /* @__PURE__ */ p(
656
656
  {
657
657
  className: [
658
658
  "sa-input-dropdwon-item-text-description",
659
- C ? "active" : "",
659
+ N ? "active" : "",
660
660
  a.disable ? "sa-input-dropdwon-item-disable" : ""
661
661
  ].filter(Boolean).join(" "),
662
662
  children: a.description
@@ -665,212 +665,249 @@ const en = ({ ...e }) => /* @__PURE__ */ p(
665
665
  ] })
666
666
  ]
667
667
  },
668
- B
668
+ S
669
669
  );
670
670
  })
671
671
  ]
672
672
  }
673
673
  ),
674
- e === "top" && A,
675
- g && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: g })
674
+ e === "top" && j,
675
+ A && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: A })
676
676
  ]
677
677
  }
678
678
  ) : null });
679
679
  }
680
- ), an = ({
680
+ ), un = ({
681
681
  children: e,
682
- handleChangePosition: l
682
+ handleChangePosition: p
683
683
  }) => {
684
- const i = L(null);
685
- x(() => {
686
- var c;
684
+ const d = I(null);
685
+ v(() => {
686
+ var y;
687
687
  const o = () => {
688
- if (i.current) {
689
- let u = i.current.parentElement;
690
- for (; u && !d(u); )
691
- u = u.parentElement;
692
- u && l();
688
+ if (d.current) {
689
+ let h = d.current.parentElement;
690
+ for (; h && !l(h); )
691
+ h = h.parentElement;
692
+ h && p();
693
693
  }
694
694
  };
695
- let r = (c = i.current) == null ? void 0 : c.parentElement;
696
- for (; r && !d(r); )
695
+ let r = (y = d.current) == null ? void 0 : y.parentElement;
696
+ for (; r && !l(r); )
697
697
  r = r.parentElement;
698
698
  return r && r.addEventListener("scroll", o), o(), () => {
699
699
  r && r.removeEventListener("scroll", o);
700
700
  };
701
701
  }, []);
702
- const d = (o) => o && (o.scrollHeight > o.clientHeight || o.scrollWidth > o.clientWidth);
703
- return /* @__PURE__ */ n("div", { ref: i, children: e });
704
- }, V = "sa-input-dropdown-styles", tn = (e) => {
705
- if (!document.getElementById(V)) {
706
- const l = document.createElement("style");
707
- l.id = V, l.textContent = e, document.head.appendChild(l);
702
+ const l = (o) => o && (o.scrollHeight > o.clientHeight || o.scrollWidth > o.clientWidth);
703
+ return /* @__PURE__ */ n("div", { ref: d, children: e });
704
+ }, Z = "sa-input-dropdown-styles", wn = (e) => {
705
+ if (!document.getElementById(Z)) {
706
+ const p = document.createElement("style");
707
+ p.id = Z, p.textContent = e, document.head.appendChild(p);
708
708
  }
709
709
  };
710
- tn(_);
711
- const K = ({
710
+ wn(dn);
711
+ const mn = ({
712
712
  dropdownLists: e,
713
- onChange: l,
714
- defaultValue: i,
715
- value: d,
713
+ onChange: p,
714
+ defaultValue: d,
715
+ value: l,
716
716
  size: o = "md",
717
717
  multiSelect: r,
718
- searchAble: c,
719
- iconLeft: u,
720
- placeholder: y,
721
- onSearch: h,
722
- error: g,
723
- onBlur: S,
724
- onFocus: I,
725
- disable: j,
726
- searchValue: z,
727
- variant: A = "standard",
718
+ searchAble: y,
719
+ iconLeft: h,
720
+ placeholder: F,
721
+ onSearch: x,
722
+ error: A,
723
+ onBlur: O,
724
+ onFocus: D,
725
+ disable: H,
726
+ searchValue: R,
727
+ variant: j = "outline",
728
728
  footer: a,
729
- groupLabel: B,
730
- onSelectAll: C
729
+ groupLabel: S,
730
+ onSelectAll: N,
731
+ /* field wrapper */
732
+ label: g,
733
+ labelPosition: _ = "outside-top",
734
+ required: J,
735
+ optional: U,
736
+ description: E,
737
+ helperText: C,
738
+ errorText: u
731
739
  }) => {
732
- const b = d !== void 0, W = L(), [w, R] = O(
733
- b ? d || [] : i || []
734
- ), [U, q] = O(""), [v, F] = O(-1), m = L(null), { isComponentVisible: k, ref: H, setIsComponentVisible: D } = nn(!1), M = () => {
735
- D((t) => !t);
736
- }, P = (t, s) => {
740
+ const z = l !== void 0, M = I(), T = A || !!u, [c, L] = P(
741
+ z ? l || [] : d || []
742
+ ), [nn, X] = P(""), [b, $] = P(-1), m = I(null), { isComponentVisible: k, ref: q, setIsComponentVisible: W } = ln(!1), en = () => {
743
+ W((i) => !i);
744
+ }, V = (i, s) => {
737
745
  if (r)
738
- if (w == null ? void 0 : w.find((f) => f.value === s)) {
739
- const f = w.filter((Q) => Q.value !== s);
740
- b || R(f), l(f);
746
+ if (c == null ? void 0 : c.find((w) => w.value === s)) {
747
+ const w = c.filter((an) => an.value !== s);
748
+ z || L(w), p(w);
741
749
  } else {
742
- const f = [...w, { label: t, value: s }];
743
- b || R(f), l(f);
750
+ const w = [...c, { label: i, value: s }];
751
+ z || L(w), p(w);
744
752
  }
745
753
  else {
746
- const N = [{ label: t, value: s }];
747
- b || R(N), l(N), D(!1);
754
+ const f = [{ label: i, value: s }];
755
+ z || L(f), p(f), W(!1);
748
756
  }
749
757
  };
750
- x(() => {
751
- b && R(d || []);
752
- }, [d]), x(() => {
753
- b || JSON.stringify(W.current) === JSON.stringify(i) || (W.current = i, R(W.current || []));
754
- }, [i]);
755
- const X = () => w.length ? r ? w == null ? void 0 : w.map((t, s) => /* @__PURE__ */ p("div", { className: "sa-input-dropdown-preview-item", children: [
756
- /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }),
758
+ v(() => {
759
+ z && L(l || []);
760
+ }, [l]), v(() => {
761
+ z || JSON.stringify(M.current) === JSON.stringify(d) || (M.current = d, L(M.current || []));
762
+ }, [d]);
763
+ const rn = () => c.length ? r ? c == null ? void 0 : c.map((i, s) => /* @__PURE__ */ t("div", { className: "sa-input-dropdown-preview-item", children: [
764
+ /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: i == null ? void 0 : i.label }),
757
765
  /* @__PURE__ */ n(
758
- sn,
766
+ bn,
759
767
  {
760
- onClick: () => P(t.label, t.value)
768
+ onClick: (f) => {
769
+ f.stopPropagation(), V(i.label, i.value);
770
+ }
761
771
  }
762
772
  )
763
- ] }, s)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: w == null ? void 0 : w[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: y }), E = () => {
764
- if (H.current && m.current) {
765
- const t = window.innerHeight, s = H.current.getBoundingClientRect(), N = m.current.getBoundingClientRect(), f = s.bottom + N.height;
766
- m.current.style.left = `${s.left}px`, m.current.style.width = `${s.width}px`, f >= t - 10 ? (m.current.style.top = `${s.top - N.height - 5}px`, q("top")) : (m.current.style.top = `${s.top + s.height + 4}px`, q("bottom"));
773
+ ] }, s)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: F }), B = () => {
774
+ if (q.current && m.current) {
775
+ const i = window.innerHeight, s = q.current.getBoundingClientRect(), f = m.current.getBoundingClientRect(), w = s.bottom + f.height;
776
+ m.current.style.left = `${s.left}px`, m.current.style.width = `${s.width}px`, w >= i - 10 ? (m.current.style.top = `${s.top - f.height - 5}px`, X("top")) : (m.current.style.top = `${s.top + s.height + 4}px`, X("bottom"));
767
777
  }
768
778
  };
769
- x(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
770
- window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
771
- }), []), x(() => {
772
- E();
773
- }, [k]), x(() => {
774
- k || F(-1);
779
+ v(() => (window.addEventListener("scroll", B), window.addEventListener("resize", B), () => {
780
+ window.removeEventListener("scroll", B), window.removeEventListener("resize", B);
781
+ }), []), v(() => {
782
+ B();
783
+ }, [k]), v(() => {
784
+ k || $(-1);
775
785
  }, [k]);
776
- const Z = (t) => {
786
+ const on = (i) => {
777
787
  if (!k) {
778
- (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), D(!0));
788
+ (i.key === "ArrowDown" || i.key === "Enter") && (i.preventDefault(), W(!0));
779
789
  return;
780
790
  }
781
- switch (t.key) {
791
+ switch (i.key) {
782
792
  case "ArrowDown": {
783
- t.preventDefault();
784
- const s = T(e, v, 1);
785
- s !== -1 && F(s);
793
+ i.preventDefault();
794
+ const s = Q(e, b, 1);
795
+ s !== -1 && $(s);
786
796
  break;
787
797
  }
788
798
  case "ArrowUp": {
789
- t.preventDefault();
790
- const s = T(e, v, -1);
791
- s !== -1 && F(s);
799
+ i.preventDefault();
800
+ const s = Q(e, b, -1);
801
+ s !== -1 && $(s);
792
802
  break;
793
803
  }
794
804
  case "Enter": {
795
- t.preventDefault(), v >= 0 && e[v] && !e[v].disable && P(
796
- e[v].label,
797
- e[v].value
805
+ i.preventDefault(), b >= 0 && e[b] && !e[b].disable && V(
806
+ e[b].label,
807
+ e[b].value
798
808
  );
799
809
  break;
800
810
  }
801
- case "Escape": {
802
- D(!1);
811
+ case "Escape":
812
+ W(!1);
803
813
  break;
804
- }
805
814
  }
806
- }, $ = dn(o);
807
- return /* @__PURE__ */ n(an, { handleChangePosition: E, children: /* @__PURE__ */ p(
815
+ }, K = o === "lg" || o === "xl" ? 20 : 16, G = /* @__PURE__ */ n(un, { handleChangePosition: B, children: /* @__PURE__ */ t(
808
816
  "div",
809
817
  {
810
818
  className: [
811
819
  "sa-input-dropdown-container",
812
- A,
820
+ j,
813
821
  `sa-input-dropdown-size-${o}`,
814
822
  k ? "active" : "",
815
- g ? "error" : "",
816
- j ? "disable" : ""
823
+ T ? "error" : "",
824
+ H ? "disable" : ""
817
825
  ].filter(Boolean).join(" "),
818
- ref: H,
819
- onClick: M,
820
- onKeyDown: Z,
826
+ ref: q,
827
+ onClick: en,
828
+ onKeyDown: on,
821
829
  tabIndex: 0,
822
- onBlur: S,
823
- onFocus: I,
830
+ onBlur: O,
831
+ onFocus: D,
824
832
  children: [
825
- /* @__PURE__ */ p("div", { className: "sa-input-dropdown-preview-container", children: [
826
- u ? /* @__PURE__ */ n(G, { children: J.cloneElement(u, {
827
- width: $,
828
- color: "var(--sa-dropdown-placeholder)",
829
- style: { color: "var(--sa-dropdown-placeholder)" }
830
- }) }) : null,
831
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: X() }),
832
- k ? /* @__PURE__ */ n(pn, { width: $ }) : /* @__PURE__ */ n(ln, { width: $ })
833
+ /* @__PURE__ */ t("div", { className: "sa-input-dropdown-preview-container", children: [
834
+ h ? Y.cloneElement(h, {
835
+ width: K,
836
+ style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
837
+ }) : null,
838
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: rn() }),
839
+ k ? /* @__PURE__ */ n(vn, { width: K }) : /* @__PURE__ */ n(fn, { width: K })
833
840
  ] }),
834
841
  /* @__PURE__ */ n(
835
- on,
842
+ hn,
836
843
  {
837
844
  dropdownLists: e,
838
- handleChangeValue: P,
845
+ handleChangeValue: V,
839
846
  isComponentVisible: k,
840
- positionDropdown: U,
841
- searchAble: !!c,
842
- value: w,
843
- onSearch: h,
847
+ positionDropdown: nn,
848
+ searchAble: !!y,
849
+ value: c,
850
+ onSearch: x,
844
851
  ref: m,
845
852
  multiSelect: r,
846
- searchValue: z,
847
- highlightedIndex: v,
853
+ searchValue: R,
854
+ highlightedIndex: b,
848
855
  footer: a,
849
- groupLabel: B,
850
- onSelectAll: C
856
+ groupLabel: S,
857
+ onSelectAll: N
851
858
  }
852
859
  )
853
860
  ]
854
861
  }
855
862
  ) });
856
- }, T = (e, l, i) => {
857
- const d = e.length;
858
- let o = l + i;
859
- for (; o >= 0 && o < d; ) {
863
+ return g ? _ === "outside-left" ? /* @__PURE__ */ t("div", { className: "sa-select-field sa-select-field-left", children: [
864
+ /* @__PURE__ */ t("div", { className: "sa-select-field-left-label", children: [
865
+ /* @__PURE__ */ t("div", { className: "sa-select-field-label-row", children: [
866
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: g }),
867
+ U && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
868
+ J && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
869
+ ] }),
870
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E })
871
+ ] }),
872
+ /* @__PURE__ */ t("div", { className: "sa-select-field-input-wrap", children: [
873
+ G,
874
+ C && !u && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
875
+ u && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: u })
876
+ ] })
877
+ ] }) : /* @__PURE__ */ t("div", { className: "sa-select-field", children: [
878
+ /* @__PURE__ */ t("div", { className: "sa-select-field-label-row", children: [
879
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: g }),
880
+ U && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
881
+ J && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
882
+ ] }),
883
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
884
+ G,
885
+ C && !u && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
886
+ u && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: u })
887
+ ] }) : /* @__PURE__ */ t("div", { className: "sa-select-field", children: [
888
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
889
+ G,
890
+ C && !u && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
891
+ u && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: u })
892
+ ] });
893
+ }, Q = (e, p, d) => {
894
+ const l = e.length;
895
+ let o = p + d;
896
+ for (; o >= 0 && o < l; ) {
860
897
  if (!e[o].disable)
861
898
  return o;
862
- o += i;
899
+ o += d;
863
900
  }
864
- if (i === 1) {
865
- for (let r = 0; r < d; r++)
901
+ if (d === 1) {
902
+ for (let r = 0; r < l; r++)
866
903
  if (!e[r].disable)
867
904
  return r;
868
905
  } else
869
- for (let r = d - 1; r >= 0; r--)
906
+ for (let r = l - 1; r >= 0; r--)
870
907
  if (!e[r].disable)
871
908
  return r;
872
909
  return -1;
873
- }, dn = (e) => e === "lg" || e === "xl" ? 20 : 16, sn = (e) => /* @__PURE__ */ n(
910
+ }, bn = (e) => /* @__PURE__ */ n(
874
911
  "svg",
875
912
  {
876
913
  xmlns: "http://www.w3.org/2000/svg",
@@ -878,6 +915,7 @@ const K = ({
878
915
  height: "14",
879
916
  viewBox: "0 0 18 18",
880
917
  fill: "none",
918
+ style: { flexShrink: 0, cursor: "pointer" },
881
919
  ...e,
882
920
  children: /* @__PURE__ */ n(
883
921
  "path",
@@ -890,7 +928,7 @@ const K = ({
890
928
  }
891
929
  )
892
930
  }
893
- ), ln = ({ width: e = 16 }) => /* @__PURE__ */ n(
931
+ ), fn = ({ width: e = 16 }) => /* @__PURE__ */ n(
894
932
  "svg",
895
933
  {
896
934
  xmlns: "http://www.w3.org/2000/svg",
@@ -910,7 +948,7 @@ const K = ({
910
948
  }
911
949
  )
912
950
  }
913
- ), pn = ({ width: e = 16 }) => /* @__PURE__ */ n(
951
+ ), vn = ({ width: e = 16 }) => /* @__PURE__ */ n(
914
952
  "svg",
915
953
  {
916
954
  xmlns: "http://www.w3.org/2000/svg",
@@ -930,41 +968,7 @@ const K = ({
930
968
  }
931
969
  )
932
970
  }
933
- ), wn = ({
934
- label: e,
935
- labelPosition: l = "top",
936
- required: i,
937
- optional: d,
938
- helperText: o,
939
- helperTextTop: r,
940
- errorMessage: c,
941
- error: u,
942
- ...y
943
- }) => {
944
- const h = u || !!c, g = e ? /* @__PURE__ */ p("div", { className: "sa-select-field-label-row", children: [
945
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: e }),
946
- d && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
947
- i && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
948
- ] }) : null;
949
- return l === "left" ? /* @__PURE__ */ p("div", { className: "sa-select-field sa-select-field-left", children: [
950
- /* @__PURE__ */ p("div", { className: "sa-select-field-left-label", children: [
951
- g,
952
- r && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: r })
953
- ] }),
954
- /* @__PURE__ */ p("div", { className: "sa-select-field-input-wrap", children: [
955
- /* @__PURE__ */ n(K, { ...y, error: h }),
956
- o && !c && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: o }),
957
- c && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: c })
958
- ] })
959
- ] }) : /* @__PURE__ */ p("div", { className: "sa-select-field", children: [
960
- g,
961
- r && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: r }),
962
- /* @__PURE__ */ n(K, { ...y, error: h }),
963
- o && !c && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: o }),
964
- c && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: c })
965
- ] });
966
- };
971
+ );
967
972
  export {
968
- K as Dropdown,
969
- wn as SelectField
973
+ mn as Dropdown
970
974
  };
@@ -1,4 +1,4 @@
1
- (function(u,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):(u=typeof globalThis<"u"?globalThis:u||self,n(u.Dropdown={},u.jsxRuntime,u.React))})(this,function(u,n,d){"use strict";const K=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(b,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):(b=typeof globalThis<"u"?globalThis:b||self,n(b.Dropdown={},b.jsxRuntime,b.React))})(this,function(b,n,d){"use strict";const Z=`@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;
@@ -497,4 +497,4 @@
497
497
  height: 100%;
498
498
  width: 100%;
499
499
  }
500
- `;function G(e){const[p,t]=d.useState(e),i=d.useRef(null),o=r=>{i.current&&!i.current.contains(r.target)&&t(!1)};return d.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:i,isComponentVisible:p,setIsComponentVisible:t}}const J=({...e})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...e,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"})]}),M=({isChecked:e})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:e}),n.jsx("svg",{children:n.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:n.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:n.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),U=d.forwardRef(({positionDropdown:e,dropdownLists:p,isComponentVisible:t,searchAble:i,onSearch:o,value:r,handleChangeValue:c,multiSelect:w,searchValue:m,highlightedIndex:f,footer:g,groupLabel:L,onSelectAll:I},O)=>{const z=d.useRef([]);d.useEffect(()=>{var a;f>=0&&z.current[f]&&((a=z.current[f])==null||a.scrollIntoView({block:"nearest"}))},[f]);const A=i?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(J,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{o&&o(a.target.value)},value:m,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:O,children:[e!=="top"&&A,n.jsxs("div",{className:`sa-input-dropdwon-item-container ${w?"multi":""}`,children:[L&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:L}),w&&I&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),I()},children:"Select all"})]}),p.map((a,S)=>{const E=!!(r!=null&&r.find(b=>b.value===a.value));return n.jsxs("div",{className:["sa-input-dropdwon-item",E?"active":"",S===f?"highlight":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),ref:b=>{z.current[S]=b},onClick:()=>c(a.label,a.value),children:[w&&n.jsx("div",{style:{flexShrink:0},children:n.jsx(M,{isChecked:E})}),a.icon&&n.jsx("div",{style:{flexShrink:0},children:d.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdwon-item-text",E?"active":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdwon-item-text-description",E?"active":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},S)})]}),e==="top"&&A,g&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:g})]}):null})}),X=({children:e,handleChangePosition:p})=>{const t=d.useRef(null);d.useEffect(()=>{var c;const o=()=>{if(t.current){let w=t.current.parentElement;for(;w&&!i(w);)w=w.parentElement;w&&p()}};let r=(c=t.current)==null?void 0:c.parentElement;for(;r&&!i(r);)r=r.parentElement;return r&&r.addEventListener("scroll",o),o(),()=>{r&&r.removeEventListener("scroll",o)}},[]);const i=o=>o&&(o.scrollHeight>o.clientHeight||o.scrollWidth>o.clientWidth);return n.jsx("div",{ref:t,children:e})},T="sa-input-dropdown-styles";(e=>{if(!document.getElementById(T)){const p=document.createElement("style");p.id=T,p.textContent=e,document.head.appendChild(p)}})(K);const D=({dropdownLists:e,onChange:p,defaultValue:t,value:i,size:o="md",multiSelect:r,searchAble:c,iconLeft:w,placeholder:m,onSearch:f,error:g,onBlur:L,onFocus:I,disable:O,searchValue:z,variant:A="standard",footer:a,groupLabel:S,onSelectAll:E})=>{const b=i!==void 0,W=d.useRef(),[h,B]=d.useState(b?i||[]:t||[]),[nn,V]=d.useState(""),[x,F]=d.useState(-1),k=d.useRef(null),{isComponentVisible:y,ref:P,setIsComponentVisible:j}=G(!1),en=()=>{j(s=>!s)},H=(s,l)=>{if(r)if(h==null?void 0:h.find(v=>v.value===l)){const v=h.filter(an=>an.value!==l);b||B(v),p(v)}else{const v=[...h,{label:s,value:l}];b||B(v),p(v)}else{const N=[{label:s,value:l}];b||B(N),p(N),j(!1)}};d.useEffect(()=>{b&&B(i||[])},[i]),d.useEffect(()=>{b||JSON.stringify(W.current)===JSON.stringify(t)||(W.current=t,B(W.current||[]))},[t]);const rn=()=>h.length?r?h==null?void 0:h.map((s,l)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:s==null?void 0:s.label}),n.jsx(Q,{onClick:()=>H(s.label,s.value)})]},l)):n.jsx("p",{style:{minWidth:"max-content"},children:h==null?void 0:h[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:m}),C=()=>{if(P.current&&k.current){const s=window.innerHeight,l=P.current.getBoundingClientRect(),N=k.current.getBoundingClientRect(),v=l.bottom+N.height;k.current.style.left=`${l.left}px`,k.current.style.width=`${l.width}px`,v>=s-10?(k.current.style.top=`${l.top-N.height-5}px`,V("top")):(k.current.style.top=`${l.top+l.height+4}px`,V("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",C),window.addEventListener("resize",C),()=>{window.removeEventListener("scroll",C),window.removeEventListener("resize",C)}),[]),d.useEffect(()=>{C()},[y]),d.useEffect(()=>{y||F(-1)},[y]);const on=s=>{if(!y){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),j(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const l=$(e,x,1);l!==-1&&F(l);break}case"ArrowUp":{s.preventDefault();const l=$(e,x,-1);l!==-1&&F(l);break}case"Enter":{s.preventDefault(),x>=0&&e[x]&&!e[x].disable&&H(e[x].label,e[x].value);break}case"Escape":{j(!1);break}}},q=Z(o);return n.jsx(X,{handleChangePosition:C,children:n.jsxs("div",{className:["sa-input-dropdown-container",A,`sa-input-dropdown-size-${o}`,y?"active":"",g?"error":"",O?"disable":""].filter(Boolean).join(" "),ref:P,onClick:en,onKeyDown:on,tabIndex:0,onBlur:L,onFocus:I,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[w?n.jsx(n.Fragment,{children:d.cloneElement(w,{width:q,color:"var(--sa-dropdown-placeholder)",style:{color:"var(--sa-dropdown-placeholder)"}})}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:rn()}),y?n.jsx(_,{width:q}):n.jsx(Y,{width:q})]}),n.jsx(U,{dropdownLists:e,handleChangeValue:H,isComponentVisible:y,positionDropdown:nn,searchAble:!!c,value:h,onSearch:f,ref:k,multiSelect:r,searchValue:z,highlightedIndex:x,footer:a,groupLabel:S,onSelectAll:E})]})})},$=(e,p,t)=>{const i=e.length;let o=p+t;for(;o>=0&&o<i;){if(!e[o].disable)return o;o+=t}if(t===1){for(let r=0;r<i;r++)if(!e[r].disable)return r}else for(let r=i-1;r>=0;r--)if(!e[r].disable)return r;return-1},Z=e=>e==="lg"||e==="xl"?20:16,Q=e=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",...e,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Y=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})}),_=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})}),R=({label:e,labelPosition:p="top",required:t,optional:i,helperText:o,helperTextTop:r,errorMessage:c,error:w,...m})=>{const f=w||!!c,g=e?n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:e}),i&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),t&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}):null;return p==="left"?n.jsxs("div",{className:"sa-select-field sa-select-field-left",children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[g,r&&n.jsx("p",{className:"sa-select-field-helper-top",children:r})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[n.jsx(D,{...m,error:f}),o&&!c&&n.jsx("p",{className:"sa-select-field-helper",children:o}),c&&n.jsx("p",{className:"sa-select-field-error-msg",children:c})]})]}):n.jsxs("div",{className:"sa-select-field",children:[g,r&&n.jsx("p",{className:"sa-select-field-helper-top",children:r}),n.jsx(D,{...m,error:f}),o&&!c&&n.jsx("p",{className:"sa-select-field-helper",children:o}),c&&n.jsx("p",{className:"sa-select-field-error-msg",children:c})]})};u.Dropdown=D,u.SelectField=R,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
500
+ `;function Q(e){const[p,t]=d.useState(e),l=d.useRef(null),o=r=>{l.current&&!l.current.contains(r.target)&&t(!1)};return d.useEffect(()=>(document.addEventListener("click",o,!0),()=>{document.removeEventListener("click",o,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:t}}const Y=({...e})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...e,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"})]}),_=({isChecked:e})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:e}),n.jsx("svg",{children:n.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:n.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:n.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),R=d.forwardRef(({positionDropdown:e,dropdownLists:p,isComponentVisible:t,searchAble:l,onSearch:o,value:r,handleChangeValue:m,multiSelect:h,searchValue:P,highlightedIndex:x,footer:j,groupLabel:A,onSelectAll:D},F)=>{const B=d.useRef([]);d.useEffect(()=>{var a;x>=0&&B.current[x]&&((a=B.current[x])==null||a.scrollIntoView({block:"nearest"}))},[x]);const O=l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(Y,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{o&&o(a.target.value)},value:P,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:F,children:[e!=="top"&&O,n.jsxs("div",{className:`sa-input-dropdwon-item-container ${h?"multi":""}`,children:[A&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:A}),h&&D&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),D()},children:"Select all"})]}),p.map((a,L)=>{const E=!!(r!=null&&r.find(g=>g.value===a.value));return n.jsxs("div",{className:["sa-input-dropdwon-item",E?"active":"",L===x?"highlight":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),ref:g=>{B.current[L]=g},onClick:()=>m(a.label,a.value),children:[h&&n.jsx("div",{style:{flexShrink:0},children:n.jsx(_,{isChecked:E})}),a.icon&&n.jsx("div",{style:{flexShrink:0},children:d.cloneElement(a.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdwon-item-text",E?"active":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.label}),a.description&&n.jsx("p",{className:["sa-input-dropdwon-item-text-description",E?"active":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},L)})]}),e==="top"&&O,j&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:j})]}):null})}),nn=({children:e,handleChangePosition:p})=>{const t=d.useRef(null);d.useEffect(()=>{var m;const o=()=>{if(t.current){let h=t.current.parentElement;for(;h&&!l(h);)h=h.parentElement;h&&p()}};let r=(m=t.current)==null?void 0:m.parentElement;for(;r&&!l(r);)r=r.parentElement;return r&&r.addEventListener("scroll",o),o(),()=>{r&&r.removeEventListener("scroll",o)}},[]);const l=o=>o&&(o.scrollHeight>o.clientHeight||o.scrollWidth>o.clientWidth);return n.jsx("div",{ref:t,children:e})},G="sa-input-dropdown-styles";(e=>{if(!document.getElementById(G)){const p=document.createElement("style");p.id=G,p.textContent=e,document.head.appendChild(p)}})(Z);const en=({dropdownLists:e,onChange:p,defaultValue:t,value:l,size:o="md",multiSelect:r,searchAble:m,iconLeft:h,placeholder:P,onSearch:x,error:j,onBlur:A,onFocus:D,disable:F,searchValue:B,variant:O="outline",footer:a,groupLabel:L,onSelectAll:E,label:g,labelPosition:sn="outside-top",required:U,optional:T,description:N,helperText:C,errorText:f})=>{const z=l!==void 0,H=d.useRef(),dn=j||!!f,[c,I]=d.useState(z?l||[]:t||[]),[tn,X]=d.useState(""),[u,M]=d.useState(-1),k=d.useRef(null),{isComponentVisible:y,ref:q,setIsComponentVisible:W}=Q(!1),ln=()=>{W(s=>!s)},$=(s,i)=>{if(r)if(c==null?void 0:c.find(w=>w.value===i)){const w=c.filter(hn=>hn.value!==i);z||I(w),p(w)}else{const w=[...c,{label:s,value:i}];z||I(w),p(w)}else{const v=[{label:s,value:i}];z||I(v),p(v),W(!1)}};d.useEffect(()=>{z&&I(l||[])},[l]),d.useEffect(()=>{z||JSON.stringify(H.current)===JSON.stringify(t)||(H.current=t,I(H.current||[]))},[t]);const pn=()=>c.length?r?c==null?void 0:c.map((s,i)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:s==null?void 0:s.label}),n.jsx(rn,{onClick:v=>{v.stopPropagation(),$(s.label,s.value)}})]},i)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:P}),S=()=>{if(q.current&&k.current){const s=window.innerHeight,i=q.current.getBoundingClientRect(),v=k.current.getBoundingClientRect(),w=i.bottom+v.height;k.current.style.left=`${i.left}px`,k.current.style.width=`${i.width}px`,w>=s-10?(k.current.style.top=`${i.top-v.height-5}px`,X("top")):(k.current.style.top=`${i.top+i.height+4}px`,X("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",S),window.addEventListener("resize",S),()=>{window.removeEventListener("scroll",S),window.removeEventListener("resize",S)}),[]),d.useEffect(()=>{S()},[y]),d.useEffect(()=>{y||M(-1)},[y]);const cn=s=>{if(!y){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),W(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const i=J(e,u,1);i!==-1&&M(i);break}case"ArrowUp":{s.preventDefault();const i=J(e,u,-1);i!==-1&&M(i);break}case"Enter":{s.preventDefault(),u>=0&&e[u]&&!e[u].disable&&$(e[u].label,e[u].value);break}case"Escape":W(!1);break}},V=o==="lg"||o==="xl"?20:16,K=n.jsx(nn,{handleChangePosition:S,children:n.jsxs("div",{className:["sa-input-dropdown-container",O,`sa-input-dropdown-size-${o}`,y?"active":"",dn?"error":"",F?"disable":""].filter(Boolean).join(" "),ref:q,onClick:ln,onKeyDown:cn,tabIndex:0,onBlur:A,onFocus:D,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[h?d.cloneElement(h,{width:V,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:pn()}),y?n.jsx(an,{width:V}):n.jsx(on,{width:V})]}),n.jsx(R,{dropdownLists:e,handleChangeValue:$,isComponentVisible:y,positionDropdown:tn,searchAble:!!m,value:c,onSearch:x,ref:k,multiSelect:r,searchValue:B,highlightedIndex:u,footer:a,groupLabel:L,onSelectAll:E})]})});return g?sn==="outside-left"?n.jsxs("div",{className:"sa-select-field 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:g}),T&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),U&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[K,C&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:C}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:"sa-select-field",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:g}),T&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),U&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:C}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:"sa-select-field",children:[N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:C}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},J=(e,p,t)=>{const l=e.length;let o=p+t;for(;o>=0&&o<l;){if(!e[o].disable)return o;o+=t}if(t===1){for(let r=0;r<l;r++)if(!e[r].disable)return r}else for(let r=l-1;r>=0;r--)if(!e[r].disable)return r;return-1},rn=e=>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"},...e,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),on=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})}),an=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})});b.Dropdown=en,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { Dropdown } from "./Dropdown";
2
- export { SelectField } from "./SelectField";
3
2
  export * from "./interface";
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
2
  export interface IconPropsDropdown extends React.SVGProps<SVGSVGElement> {
3
3
  }
4
+ export type DropdownSize = "sm" | "md" | "lg" | "xl";
5
+ export type DropdownVariant = "standard" | "outline" | "flushed";
6
+ export type DropdownLabelPosition = "outside-top" | "outside-left";
4
7
  export interface IDropdown {
5
8
  onChange: (props: {
6
9
  label: string;
@@ -21,7 +24,7 @@ export interface IDropdown {
21
24
  label: string;
22
25
  value: string;
23
26
  }[];
24
- size?: "sm" | "md" | "lg" | "xl";
27
+ size?: DropdownSize;
25
28
  error?: boolean;
26
29
  multiSelect?: boolean;
27
30
  searchAble?: boolean;
@@ -33,17 +36,15 @@ export interface IDropdown {
33
36
  onFocus?: (e: React.FocusEvent<HTMLDivElement, Element>) => void;
34
37
  disable?: boolean;
35
38
  searchValue?: string;
36
- variant?: "standard" | "outline" | "flushed";
39
+ variant?: DropdownVariant;
37
40
  footer?: React.ReactNode;
38
41
  groupLabel?: string;
39
42
  onSelectAll?: () => void;
40
- }
41
- export interface ISelectField extends IDropdown {
42
- label?: string;
43
- labelPosition?: "top" | "left";
43
+ label?: React.ReactNode;
44
+ labelPosition?: DropdownLabelPosition;
44
45
  required?: boolean;
45
46
  optional?: boolean;
47
+ description?: string;
46
48
  helperText?: string;
47
- helperTextTop?: string;
48
- errorMessage?: string;
49
+ errorText?: string;
49
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",
@@ -12,10 +12,6 @@
12
12
  "dist/*.map",
13
13
  "dist/*.css"
14
14
  ],
15
- "scripts": {
16
- "dev": "vite --config vite.config.ts --port 3000",
17
- "build": "vite build --config vite.config.ts"
18
- },
19
15
  "keywords": [],
20
16
  "license": "ISC",
21
17
  "type": "module",
@@ -37,5 +33,9 @@
37
33
  "react-dom": "^18.2.0",
38
34
  "@types/react": "^18.2.55",
39
35
  "@types/react-dom": "^18.2.19"
36
+ },
37
+ "scripts": {
38
+ "dev": "vite --config vite.config.ts --port 3000",
39
+ "build": "vite build --config vite.config.ts"
40
40
  }
41
- }
41
+ }
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import { ISelectField } from "./interface";
3
- export declare const SelectField: React.FC<ISelectField>;