@starasia/dropdown 3.5.1 → 4.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.
@@ -1,6 +1,6 @@
1
- import { jsxs as l, jsx as n, Fragment as tn } from "react/jsx-runtime";
2
- import _, { useState as F, useRef as I, useEffect as g, forwardRef as dn } from "react";
3
- const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ import { jsxs as l, jsx as n, Fragment as sn } from "react/jsx-runtime";
2
+ import T, { useState as P, useRef as B, useEffect as g, forwardRef as ln } from "react";
3
+ const pn = `@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;
@@ -116,6 +116,7 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
116
116
  background-color: transparent;
117
117
  border: 0.8px solid var(--sa-dropdown-border-subtle);
118
118
  border-radius: var(--borderRadius);
119
+ outline: none;
119
120
  }
120
121
  .sa-input-dropdown-container.outline.active {
121
122
  border: 1.2px solid var(--sa-dropdown-border-active);
@@ -365,9 +366,12 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
365
366
  display: flex;
366
367
  flex-direction: column;
367
368
  gap: 6px;
368
- width: 100%;
369
+ width: max-content;
369
370
  font-family: "Poppins", sans-serif;
370
371
  }
372
+ .sa-select-field-fullwidth {
373
+ width: 100%;
374
+ }
371
375
  .sa-select-field-left {
372
376
  flex-direction: row;
373
377
  align-items: flex-start;
@@ -447,15 +451,15 @@ const sn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
447
451
  }
448
452
 
449
453
  `;
450
- function ln(e) {
451
- const [p, d] = F(e), s = I(null), r = (o) => {
454
+ function cn(e) {
455
+ const [p, d] = P(e), s = B(null), r = (o) => {
452
456
  s.current && !s.current.contains(o.target) && d(!1);
453
457
  };
454
458
  return g(() => (document.addEventListener("click", r, !0), () => {
455
459
  document.removeEventListener("click", r, !0);
456
460
  }), []), { ref: s, isComponentVisible: p, setIsComponentVisible: d };
457
461
  }
458
- const pn = ({ ...e }) => /* @__PURE__ */ l(
462
+ const un = ({ ...e }) => /* @__PURE__ */ l(
459
463
  "svg",
460
464
  {
461
465
  xmlns: "http://www.w3.org/2000/svg",
@@ -487,7 +491,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
487
491
  )
488
492
  ]
489
493
  }
490
- ), cn = ({ width: e = 16 }) => /* @__PURE__ */ n(
494
+ ), wn = ({ width: e = 16 }) => /* @__PURE__ */ n(
491
495
  "svg",
492
496
  {
493
497
  xmlns: "http://www.w3.org/2000/svg",
@@ -506,7 +510,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
506
510
  }
507
511
  )
508
512
  }
509
- ), un = dn(
513
+ ), hn = ln(
510
514
  ({
511
515
  positionDropdown: e,
512
516
  dropdownLists: p,
@@ -514,78 +518,78 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
514
518
  searchAble: s,
515
519
  onSearch: r,
516
520
  value: o,
517
- handleChangeValue: y,
521
+ handleChangeValue: N,
518
522
  multiSelect: u,
519
- searchValue: H,
523
+ searchValue: F,
520
524
  highlightedIndex: m,
521
- footer: A,
522
- groupLabel: D,
523
- onSelectAll: j
524
- }, M) => {
525
- const L = I([]);
525
+ footer: I,
526
+ groupLabel: j,
527
+ onSelectAll: A
528
+ }, H) => {
529
+ const R = B([]);
526
530
  g(() => {
527
531
  var a;
528
- m >= 0 && L.current[m] && ((a = L.current[m]) == null || a.scrollIntoView({ block: "nearest" }));
532
+ m >= 0 && R.current[m] && ((a = R.current[m]) == null || a.scrollIntoView({ block: "nearest" }));
529
533
  }, [m]);
530
- const O = s ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
531
- /* @__PURE__ */ n(pn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
534
+ const D = s ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
535
+ /* @__PURE__ */ n(un, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
532
536
  /* @__PURE__ */ n(
533
537
  "input",
534
538
  {
535
539
  onChange: (a) => {
536
540
  r && r(a.target.value);
537
541
  },
538
- value: H,
542
+ value: F,
539
543
  autoFocus: !0,
540
544
  placeholder: "Search..."
541
545
  }
542
546
  )
543
547
  ] }) : null;
544
- return /* @__PURE__ */ n(tn, { children: d ? /* @__PURE__ */ l(
548
+ return /* @__PURE__ */ n(sn, { children: d ? /* @__PURE__ */ l(
545
549
  "div",
546
550
  {
547
551
  className: "sa-input-dropdown-lists-container",
548
552
  onClick: (a) => a.stopPropagation(),
549
- ref: M,
553
+ ref: H,
550
554
  children: [
551
- e !== "top" && O,
555
+ e !== "top" && D,
552
556
  /* @__PURE__ */ l(
553
557
  "div",
554
558
  {
555
559
  className: `sa-input-dropdwon-item-container ${u ? "multi" : ""}`,
556
560
  children: [
557
- D && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
558
- /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: D }),
559
- u && j && /* @__PURE__ */ n(
561
+ j && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
562
+ /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: j }),
563
+ u && A && /* @__PURE__ */ n(
560
564
  "button",
561
565
  {
562
566
  className: "sa-input-dropdown-section-select-all",
563
567
  onClick: (a) => {
564
- a.stopPropagation(), j();
568
+ a.stopPropagation(), A();
565
569
  },
566
570
  children: "Select all"
567
571
  }
568
572
  )
569
573
  ] }),
570
- p.map((a, R) => {
571
- const W = !!(o != null && o.find((S) => S.value === a.value)), z = !!a.description;
574
+ p.map((a, z) => {
575
+ const O = !!(o != null && o.find((k) => k.value === a.value)), M = !!a.description;
572
576
  return /* @__PURE__ */ l(
573
577
  "div",
574
578
  {
575
579
  className: [
576
580
  "sa-input-dropdwon-item",
577
- z ? "has-description" : "",
578
- W ? "active" : "",
579
- R === m ? "highlight" : "",
581
+ M ? "has-description" : "",
582
+ O ? "active" : "",
583
+ z === m ? "highlight" : "",
580
584
  a.disable ? "sa-input-dropdwon-item-disable" : ""
581
585
  ].filter(Boolean).join(" "),
582
- ref: (S) => {
583
- L.current[R] = S;
586
+ ref: (k) => {
587
+ R.current[z] = k;
584
588
  },
585
- onClick: () => y(a.label, a.value),
589
+ onClick: () => N(a.label, a.value),
586
590
  children: [
587
- u && /* @__PURE__ */ n("div", { className: "sa-input-dropdwon-item-check", children: W && /* @__PURE__ */ n(cn, { width: 16 }) }),
588
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: _.cloneElement(a.icon, { width: 16 }) }),
591
+ u && /* @__PURE__ */ n("div", { className: "sa-input-dropdwon-item-check", children: O && /* @__PURE__ */ n(wn, { width: 16 }) }),
592
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: T.cloneElement(a.icon, { width: 16 }) }),
589
593
  /* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
590
594
  /* @__PURE__ */ n(
591
595
  "p",
@@ -610,25 +614,25 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
610
614
  ] })
611
615
  ]
612
616
  },
613
- R
617
+ z
614
618
  );
615
619
  })
616
620
  ]
617
621
  }
618
622
  ),
619
- e === "top" && O,
620
- A && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: A })
623
+ e === "top" && D,
624
+ I && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: I })
621
625
  ]
622
626
  }
623
627
  ) : null });
624
628
  }
625
- ), wn = ({
629
+ ), fn = ({
626
630
  children: e,
627
631
  handleChangePosition: p
628
632
  }) => {
629
- const d = I(null);
633
+ const d = B(null);
630
634
  g(() => {
631
- var y;
635
+ var N;
632
636
  const r = () => {
633
637
  if (d.current) {
634
638
  let u = d.current.parentElement;
@@ -637,7 +641,7 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
637
641
  u && p();
638
642
  }
639
643
  };
640
- let o = (y = d.current) == null ? void 0 : y.parentElement;
644
+ let o = (N = d.current) == null ? void 0 : N.parentElement;
641
645
  for (; o && !s(o); )
642
646
  o = o.parentElement;
643
647
  return o && o.addEventListener("scroll", r), r(), () => {
@@ -646,203 +650,207 @@ const pn = ({ ...e }) => /* @__PURE__ */ l(
646
650
  }, []);
647
651
  const s = (r) => r && (r.scrollHeight > r.clientHeight || r.scrollWidth > r.clientWidth);
648
652
  return /* @__PURE__ */ n("div", { ref: d, children: e });
649
- }, X = "sa-input-dropdown-styles", hn = (e) => {
650
- if (!document.getElementById(X)) {
653
+ }, Y = "sa-input-dropdown-styles", bn = (e) => {
654
+ if (!document.getElementById(Y)) {
651
655
  const p = document.createElement("style");
652
- p.id = X, p.textContent = e, document.head.appendChild(p);
656
+ p.id = Y, p.textContent = e, document.head.appendChild(p);
653
657
  }
654
658
  };
655
- hn(sn);
656
- const mn = ({
659
+ bn(pn);
660
+ const yn = ({
657
661
  dropdownLists: e,
658
662
  onChange: p,
659
663
  defaultValue: d,
660
664
  value: s,
661
665
  size: r = "md",
662
666
  multiSelect: o,
663
- searchAble: y,
667
+ searchAble: N,
664
668
  iconLeft: u,
665
- placeholder: H,
669
+ placeholder: F,
666
670
  onSearch: m,
667
- error: A,
668
- onBlur: D,
669
- onFocus: j,
670
- disable: M,
671
- searchValue: L,
672
- variant: O = "outline",
671
+ error: I,
672
+ onBlur: j,
673
+ onFocus: A,
674
+ disable: H,
675
+ searchValue: R,
676
+ variant: D = "outline",
673
677
  footer: a,
674
- groupLabel: R,
675
- onSelectAll: W,
678
+ groupLabel: z,
679
+ onSelectAll: O,
680
+ fullWidth: M = !1,
676
681
  /* field wrapper */
677
- label: z,
678
- labelPosition: S = "outside-top",
679
- required: U,
680
- optional: Z,
681
- description: N,
682
- helperText: E,
682
+ label: k,
683
+ labelPosition: nn = "outside-top",
684
+ required: Z,
685
+ optional: Q,
686
+ description: E,
687
+ helperText: C,
683
688
  errorText: w
684
689
  }) => {
685
- const C = s !== void 0, $ = I(), T = A || !!w, [c, B] = F(
686
- C ? s || [] : d || []
687
- ), [nn, Q] = F(""), [x, V] = F(-1), h = I(null), { isComponentVisible: f, ref: q, setIsComponentVisible: P } = ln(!1), en = () => {
688
- P((t) => !t);
689
- }, G = (t, i) => {
690
+ const $ = [
691
+ "sa-select-field",
692
+ M ? "sa-select-field-fullwidth" : ""
693
+ ].filter(Boolean).join(" "), L = s !== void 0, V = B(), en = I || !!w, [c, S] = P(
694
+ L ? s || [] : d || []
695
+ ), [on, X] = P(""), [x, q] = P(-1), h = B(null), { isComponentVisible: f, ref: G, setIsComponentVisible: W } = cn(!1), rn = () => {
696
+ W((t) => !t);
697
+ }, J = (t, i) => {
690
698
  if (o)
691
699
  if (c == null ? void 0 : c.find((b) => b.value === i)) {
692
- const b = c.filter((an) => an.value !== i);
693
- C || B(b), p(b);
700
+ const b = c.filter((dn) => dn.value !== i);
701
+ L || S(b), p(b);
694
702
  } else {
695
703
  const b = [...c, { label: t, value: i }];
696
- C || B(b), p(b);
704
+ L || S(b), p(b);
697
705
  }
698
706
  else {
699
707
  const v = [{ label: t, value: i }];
700
- C || B(v), p(v), P(!1);
708
+ L || S(v), p(v), W(!1);
701
709
  }
702
710
  };
703
711
  g(() => {
704
- C && B(s || []);
712
+ L && S(s || []);
705
713
  }, [s]), g(() => {
706
- C || JSON.stringify($.current) === JSON.stringify(d) || ($.current = d, B($.current || []));
714
+ L || JSON.stringify(V.current) === JSON.stringify(d) || (V.current = d, S(V.current || []));
707
715
  }, [d]);
708
- const on = () => c.length ? o ? c == null ? void 0 : c.map((t, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
716
+ const an = () => c.length ? o ? c == null ? void 0 : c.map((t, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
709
717
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }),
710
718
  /* @__PURE__ */ n(
711
- fn,
719
+ gn,
712
720
  {
713
721
  onClick: (v) => {
714
- v.stopPropagation(), G(t.label, t.value);
722
+ v.stopPropagation(), J(t.label, t.value);
715
723
  }
716
724
  }
717
725
  )
718
- ] }, i)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: H }), k = () => {
719
- if (q.current && h.current) {
720
- const t = window.innerHeight, i = q.current.getBoundingClientRect(), v = h.current.getBoundingClientRect(), b = i.bottom + v.height;
721
- h.current.style.left = `${i.left}px`, h.current.style.width = `${i.width}px`, b >= t - 10 ? (h.current.style.top = `${i.top - v.height - 5}px`, Q("top")) : (h.current.style.top = `${i.top + i.height + 4}px`, Q("bottom"));
726
+ ] }, i)) : /* @__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 }), y = () => {
727
+ if (G.current && h.current) {
728
+ const t = window.innerHeight, i = G.current.getBoundingClientRect(), v = h.current.getBoundingClientRect(), b = i.bottom + v.height;
729
+ h.current.style.left = `${i.left}px`, h.current.style.width = `${i.width}px`, b >= t - 10 ? (h.current.style.top = `${i.top - v.height - 5}px`, X("top")) : (h.current.style.top = `${i.top + i.height + 4}px`, X("bottom"));
722
730
  }
723
731
  };
724
- g(() => (window.addEventListener("scroll", k), window.addEventListener("resize", k), () => {
725
- window.removeEventListener("scroll", k), window.removeEventListener("resize", k);
732
+ g(() => (window.addEventListener("scroll", y), window.addEventListener("resize", y), () => {
733
+ window.removeEventListener("scroll", y), window.removeEventListener("resize", y);
726
734
  }), []), g(() => {
727
- k();
735
+ y();
728
736
  }, [f]), g(() => {
729
737
  if (!f || !h.current)
730
738
  return;
731
739
  const t = new ResizeObserver(() => {
732
- k();
740
+ y();
733
741
  });
734
742
  return t.observe(h.current), () => t.disconnect();
735
743
  }, [f]), g(() => {
736
- f || V(-1);
744
+ f || q(-1);
737
745
  }, [f]);
738
- const rn = (t) => {
746
+ const tn = (t) => {
739
747
  if (!f) {
740
- (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), P(!0));
748
+ (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), W(!0));
741
749
  return;
742
750
  }
743
751
  switch (t.key) {
744
752
  case "ArrowDown": {
745
753
  t.preventDefault();
746
- const i = Y(e, x, 1);
747
- i !== -1 && V(i);
754
+ const i = _(e, x, 1);
755
+ i !== -1 && q(i);
748
756
  break;
749
757
  }
750
758
  case "ArrowUp": {
751
759
  t.preventDefault();
752
- const i = Y(e, x, -1);
753
- i !== -1 && V(i);
760
+ const i = _(e, x, -1);
761
+ i !== -1 && q(i);
754
762
  break;
755
763
  }
756
764
  case "Enter": {
757
- t.preventDefault(), x >= 0 && e[x] && !e[x].disable && G(
765
+ t.preventDefault(), x >= 0 && e[x] && !e[x].disable && J(
758
766
  e[x].label,
759
767
  e[x].value
760
768
  );
761
769
  break;
762
770
  }
763
771
  case "Escape":
764
- P(!1);
772
+ W(!1);
765
773
  break;
766
774
  }
767
- }, J = r === "lg" || r === "xl" ? 20 : 16, K = /* @__PURE__ */ n(wn, { handleChangePosition: k, children: /* @__PURE__ */ l(
775
+ }, K = r === "lg" || r === "xl" ? 20 : 16, U = /* @__PURE__ */ n(fn, { handleChangePosition: y, children: /* @__PURE__ */ l(
768
776
  "div",
769
777
  {
770
778
  className: [
771
779
  "sa-input-dropdown-container",
772
- O,
780
+ D,
773
781
  `sa-input-dropdown-size-${r}`,
774
782
  f ? "active" : "",
775
- T ? "error" : "",
776
- M ? "disable" : ""
783
+ en ? "error" : "",
784
+ H ? "disable" : ""
777
785
  ].filter(Boolean).join(" "),
778
- ref: q,
779
- onClick: en,
780
- onKeyDown: rn,
786
+ ref: G,
787
+ onClick: rn,
788
+ onKeyDown: tn,
781
789
  tabIndex: 0,
782
- onBlur: D,
783
- onFocus: j,
790
+ onBlur: j,
791
+ onFocus: A,
784
792
  children: [
785
793
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
786
- u ? _.cloneElement(u, {
787
- width: J,
794
+ u ? T.cloneElement(u, {
795
+ width: K,
788
796
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
789
797
  }) : null,
790
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: on() }),
791
- f ? /* @__PURE__ */ n(gn, { width: J }) : /* @__PURE__ */ n(bn, { width: J })
798
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: an() }),
799
+ f ? /* @__PURE__ */ n(vn, { width: K }) : /* @__PURE__ */ n(xn, { width: K })
792
800
  ] }),
793
801
  /* @__PURE__ */ n(
794
- un,
802
+ hn,
795
803
  {
796
804
  dropdownLists: e,
797
- handleChangeValue: G,
805
+ handleChangeValue: J,
798
806
  isComponentVisible: f,
799
- positionDropdown: nn,
800
- searchAble: !!y,
807
+ positionDropdown: on,
808
+ searchAble: !!N,
801
809
  value: c,
802
810
  onSearch: m,
803
811
  ref: h,
804
812
  multiSelect: o,
805
- searchValue: L,
813
+ searchValue: R,
806
814
  highlightedIndex: x,
807
815
  footer: a,
808
- groupLabel: R,
809
- onSelectAll: W
816
+ groupLabel: z,
817
+ onSelectAll: O
810
818
  }
811
819
  )
812
820
  ]
813
821
  }
814
822
  ) });
815
- return z ? S === "outside-left" ? /* @__PURE__ */ l("div", { className: "sa-select-field sa-select-field-left", children: [
823
+ return k ? nn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${$} sa-select-field-left`, children: [
816
824
  /* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
817
825
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
818
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: z }),
819
- Z && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
820
- U && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
826
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
827
+ Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
828
+ Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
821
829
  ] }),
822
- N && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: N })
830
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E })
823
831
  ] }),
824
832
  /* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
825
- K,
826
- E && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: E }),
833
+ U,
834
+ C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
827
835
  w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
828
836
  ] })
829
- ] }) : /* @__PURE__ */ l("div", { className: "sa-select-field", children: [
837
+ ] }) : /* @__PURE__ */ l("div", { className: $, children: [
830
838
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
831
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: z }),
832
- Z && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
833
- U && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
839
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
840
+ Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
841
+ Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
834
842
  ] }),
835
- N && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: N }),
836
- K,
837
- E && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: E }),
843
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
844
+ U,
845
+ C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
838
846
  w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
839
- ] }) : /* @__PURE__ */ l("div", { className: "sa-select-field", children: [
840
- N && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: N }),
841
- K,
842
- E && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: E }),
847
+ ] }) : /* @__PURE__ */ l("div", { className: $, children: [
848
+ E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
849
+ U,
850
+ C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
843
851
  w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
844
852
  ] });
845
- }, Y = (e, p, d) => {
853
+ }, _ = (e, p, d) => {
846
854
  const s = e.length;
847
855
  let r = p + d;
848
856
  for (; r >= 0 && r < s; ) {
@@ -859,7 +867,7 @@ const mn = ({
859
867
  if (!e[o].disable)
860
868
  return o;
861
869
  return -1;
862
- }, fn = (e) => /* @__PURE__ */ n(
870
+ }, gn = (e) => /* @__PURE__ */ n(
863
871
  "svg",
864
872
  {
865
873
  xmlns: "http://www.w3.org/2000/svg",
@@ -880,7 +888,7 @@ const mn = ({
880
888
  }
881
889
  )
882
890
  }
883
- ), bn = ({ width: e = 16 }) => /* @__PURE__ */ n(
891
+ ), xn = ({ width: e = 16 }) => /* @__PURE__ */ n(
884
892
  "svg",
885
893
  {
886
894
  xmlns: "http://www.w3.org/2000/svg",
@@ -900,7 +908,7 @@ const mn = ({
900
908
  }
901
909
  )
902
910
  }
903
- ), gn = ({ width: e = 16 }) => /* @__PURE__ */ n(
911
+ ), vn = ({ width: e = 16 }) => /* @__PURE__ */ n(
904
912
  "svg",
905
913
  {
906
914
  xmlns: "http://www.w3.org/2000/svg",
@@ -922,5 +930,5 @@ const mn = ({
922
930
  }
923
931
  );
924
932
  export {
925
- mn as Dropdown
933
+ yn as Dropdown
926
934
  };
@@ -1,4 +1,4 @@
1
- (function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,d){"use strict";const X=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(g,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):(g=typeof globalThis<"u"?globalThis:g||self,n(g.Dropdown={},g.jsxRuntime,g.React))})(this,function(g,n,d){"use strict";const Y=`@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;
@@ -114,6 +114,7 @@
114
114
  background-color: transparent;
115
115
  border: 0.8px solid var(--sa-dropdown-border-subtle);
116
116
  border-radius: var(--borderRadius);
117
+ outline: none;
117
118
  }
118
119
  .sa-input-dropdown-container.outline.active {
119
120
  border: 1.2px solid var(--sa-dropdown-border-active);
@@ -363,9 +364,12 @@
363
364
  display: flex;
364
365
  flex-direction: column;
365
366
  gap: 6px;
366
- width: 100%;
367
+ width: max-content;
367
368
  font-family: "Poppins", sans-serif;
368
369
  }
370
+ .sa-select-field-fullwidth {
371
+ width: 100%;
372
+ }
369
373
  .sa-select-field-left {
370
374
  flex-direction: row;
371
375
  align-items: flex-start;
@@ -444,4 +448,4 @@
444
448
  margin: 0;
445
449
  }
446
450
 
447
- `;function Y(e){const[p,i]=d.useState(e),l=d.useRef(null),r=o=>{l.current&&!l.current.contains(o.target)&&i(!1)};return d.useEffect(()=>(document.addEventListener("click",r,!0),()=>{document.removeEventListener("click",r,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:i}}const _=({...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"})]}),R=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})}),nn=d.forwardRef(({positionDropdown:e,dropdownLists:p,isComponentVisible:i,searchAble:l,onSearch:r,value:o,handleChangeValue:y,multiSelect:f,searchValue:F,highlightedIndex:k,footer:I,groupLabel:D,onSelectAll:A},H)=>{const S=d.useRef([]);d.useEffect(()=>{var a;k>=0&&S.current[k]&&((a=S.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]);const O=l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(_,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{r&&r(a.target.value)},value:F,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:i?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:H,children:[e!=="top"&&O,n.jsxs("div",{className:`sa-input-dropdwon-item-container ${f?"multi":""}`,children:[D&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:D}),f&&A&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),A()},children:"Select all"})]}),p.map((a,L)=>{const P=!!(o!=null&&o.find(B=>B.value===a.value)),z=!!a.description;return n.jsxs("div",{className:["sa-input-dropdwon-item",z?"has-description":"",P?"active":"",L===k?"highlight":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),ref:B=>{S.current[L]=B},onClick:()=>y(a.label,a.value),children:[f&&n.jsx("div",{className:"sa-input-dropdwon-item-check",children:P&&n.jsx(R,{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-dropdwon-item-text",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",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},L)})]}),e==="top"&&O,I&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:I})]}):null})}),en=({children:e,handleChangePosition:p})=>{const i=d.useRef(null);d.useEffect(()=>{var y;const r=()=>{if(i.current){let f=i.current.parentElement;for(;f&&!l(f);)f=f.parentElement;f&&p()}};let o=(y=i.current)==null?void 0:y.parentElement;for(;o&&!l(o);)o=o.parentElement;return o&&o.addEventListener("scroll",r),r(),()=>{o&&o.removeEventListener("scroll",r)}},[]);const l=r=>r&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth);return n.jsx("div",{ref:i,children:e})},K="sa-input-dropdown-styles";(e=>{if(!document.getElementById(K)){const p=document.createElement("style");p.id=K,p.textContent=e,document.head.appendChild(p)}})(X);const on=({dropdownLists:e,onChange:p,defaultValue:i,value:l,size:r="md",multiSelect:o,searchAble:y,iconLeft:f,placeholder:F,onSearch:k,error:I,onBlur:D,onFocus:A,disable:H,searchValue:S,variant:O="outline",footer:a,groupLabel:L,onSelectAll:P,label:z,labelPosition:B="outside-top",required:T,optional:Z,description:E,helperText:N,errorText:w})=>{const C=l!==void 0,M=d.useRef(),dn=I||!!w,[c,j]=d.useState(C?l||[]:i||[]),[tn,Q]=d.useState(""),[x,q]=d.useState(-1),h=d.useRef(null),{isComponentVisible:u,ref:$,setIsComponentVisible:W}=Y(!1),ln=()=>{W(s=>!s)},V=(s,t)=>{if(o)if(c==null?void 0:c.find(b=>b.value===t)){const b=c.filter(fn=>fn.value!==t);C||j(b),p(b)}else{const b=[...c,{label:s,value:t}];C||j(b),p(b)}else{const v=[{label:s,value:t}];C||j(v),p(v),W(!1)}};d.useEffect(()=>{C&&j(l||[])},[l]),d.useEffect(()=>{C||JSON.stringify(M.current)===JSON.stringify(i)||(M.current=i,j(M.current||[]))},[i]);const pn=()=>c.length?o?c==null?void 0:c.map((s,t)=>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(),V(s.label,s.value)}})]},t)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:F}),m=()=>{if($.current&&h.current){const s=window.innerHeight,t=$.current.getBoundingClientRect(),v=h.current.getBoundingClientRect(),b=t.bottom+v.height;h.current.style.left=`${t.left}px`,h.current.style.width=`${t.width}px`,b>=s-10?(h.current.style.top=`${t.top-v.height-5}px`,Q("top")):(h.current.style.top=`${t.top+t.height+4}px`,Q("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",m),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m),window.removeEventListener("resize",m)}),[]),d.useEffect(()=>{m()},[u]),d.useEffect(()=>{if(!u||!h.current)return;const s=new ResizeObserver(()=>{m()});return s.observe(h.current),()=>s.disconnect()},[u]),d.useEffect(()=>{u||q(-1)},[u]);const cn=s=>{if(!u){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),W(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const t=U(e,x,1);t!==-1&&q(t);break}case"ArrowUp":{s.preventDefault();const t=U(e,x,-1);t!==-1&&q(t);break}case"Enter":{s.preventDefault(),x>=0&&e[x]&&!e[x].disable&&V(e[x].label,e[x].value);break}case"Escape":W(!1);break}},G=r==="lg"||r==="xl"?20:16,J=n.jsx(en,{handleChangePosition:m,children:n.jsxs("div",{className:["sa-input-dropdown-container",O,`sa-input-dropdown-size-${r}`,u?"active":"",dn?"error":"",H?"disable":""].filter(Boolean).join(" "),ref:$,onClick:ln,onKeyDown:cn,tabIndex:0,onBlur:D,onFocus:A,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?d.cloneElement(f,{width:G,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:pn()}),u?n.jsx(sn,{width:G}):n.jsx(an,{width:G})]}),n.jsx(nn,{dropdownLists:e,handleChangeValue:V,isComponentVisible:u,positionDropdown:tn,searchAble:!!y,value:c,onSearch:k,ref:h,multiSelect:o,searchValue:S,highlightedIndex:x,footer:a,groupLabel:L,onSelectAll:P})]})});return z?B==="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:z}),Z&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),T&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),E&&n.jsx("p",{className:"sa-select-field-helper-top",children:E})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[J,N&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:N}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})]}):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:z}),Z&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),T&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),E&&n.jsx("p",{className:"sa-select-field-helper-top",children:E}),J,N&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:N}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]}):n.jsxs("div",{className:"sa-select-field",children:[E&&n.jsx("p",{className:"sa-select-field-helper-top",children:E}),J,N&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:N}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})},U=(e,p,i)=>{const l=e.length;let r=p+i;for(;r>=0&&r<l;){if(!e[r].disable)return r;r+=i}if(i===1){for(let o=0;o<l;o++)if(!e[o].disable)return o}else for(let o=l-1;o>=0;o--)if(!e[o].disable)return o;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"})}),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 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),sn=({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"})});g.Dropdown=on,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
451
+ `;function _(e){const[p,i]=d.useState(e),l=d.useRef(null),r=o=>{l.current&&!l.current.contains(o.target)&&i(!1)};return d.useEffect(()=>(document.addEventListener("click",r,!0),()=>{document.removeEventListener("click",r,!0)}),[]),{ref:l,isComponentVisible:p,setIsComponentVisible:i}}const R=({...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"})]}),nn=({width:e=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:e,height:e,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"})}),en=d.forwardRef(({positionDropdown:e,dropdownLists:p,isComponentVisible:i,searchAble:l,onSearch:r,value:o,handleChangeValue:E,multiSelect:f,searchValue:W,highlightedIndex:k,footer:j,groupLabel:I,onSelectAll:D},F)=>{const L=d.useRef([]);d.useEffect(()=>{var a;k>=0&&L.current[k]&&((a=L.current[k])==null||a.scrollIntoView({block:"nearest"}))},[k]);const A=l?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(R,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:a=>{r&&r(a.target.value)},value:W,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:i?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:a=>a.stopPropagation(),ref:F,children:[e!=="top"&&A,n.jsxs("div",{className:`sa-input-dropdwon-item-container ${f?"multi":""}`,children:[I&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:I}),f&&D&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:a=>{a.stopPropagation(),D()},children:"Select all"})]}),p.map((a,z)=>{const O=!!(o!=null&&o.find(m=>m.value===a.value)),H=!!a.description;return n.jsxs("div",{className:["sa-input-dropdwon-item",H?"has-description":"",O?"active":"",z===k?"highlight":"",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),ref:m=>{L.current[z]=m},onClick:()=>E(a.label,a.value),children:[f&&n.jsx("div",{className:"sa-input-dropdwon-item-check",children:O&&n.jsx(nn,{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-dropdwon-item-text",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",a.disable?"sa-input-dropdwon-item-disable":""].filter(Boolean).join(" "),children:a.description})]})]},z)})]}),e==="top"&&A,j&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:a=>a.stopPropagation(),children:j})]}):null})}),on=({children:e,handleChangePosition:p})=>{const i=d.useRef(null);d.useEffect(()=>{var E;const r=()=>{if(i.current){let f=i.current.parentElement;for(;f&&!l(f);)f=f.parentElement;f&&p()}};let o=(E=i.current)==null?void 0:E.parentElement;for(;o&&!l(o);)o=o.parentElement;return o&&o.addEventListener("scroll",r),r(),()=>{o&&o.removeEventListener("scroll",r)}},[]);const l=r=>r&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth);return n.jsx("div",{ref:i,children:e})},U="sa-input-dropdown-styles";(e=>{if(!document.getElementById(U)){const p=document.createElement("style");p.id=U,p.textContent=e,document.head.appendChild(p)}})(Y);const rn=({dropdownLists:e,onChange:p,defaultValue:i,value:l,size:r="md",multiSelect:o,searchAble:E,iconLeft:f,placeholder:W,onSearch:k,error:j,onBlur:I,onFocus:D,disable:F,searchValue:L,variant:A="outline",footer:a,groupLabel:z,onSelectAll:O,fullWidth:H=!1,label:m,labelPosition:tn="outside-top",required:Z,optional:Q,description:N,helperText:C,errorText:w})=>{const M=["sa-select-field",H?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),S=l!==void 0,$=d.useRef(),ln=j||!!w,[c,B]=d.useState(S?l||[]:i||[]),[pn,X]=d.useState(""),[x,q]=d.useState(-1),h=d.useRef(null),{isComponentVisible:u,ref:V,setIsComponentVisible:P}=_(!1),cn=()=>{P(s=>!s)},G=(s,t)=>{if(o)if(c==null?void 0:c.find(b=>b.value===t)){const b=c.filter(hn=>hn.value!==t);S||B(b),p(b)}else{const b=[...c,{label:s,value:t}];S||B(b),p(b)}else{const v=[{label:s,value:t}];S||B(v),p(v),P(!1)}};d.useEffect(()=>{S&&B(l||[])},[l]),d.useEffect(()=>{S||JSON.stringify($.current)===JSON.stringify(i)||($.current=i,B($.current||[]))},[i]);const fn=()=>c.length?o?c==null?void 0:c.map((s,t)=>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(an,{onClick:v=>{v.stopPropagation(),G(s.label,s.value)}})]},t)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:W}),y=()=>{if(V.current&&h.current){const s=window.innerHeight,t=V.current.getBoundingClientRect(),v=h.current.getBoundingClientRect(),b=t.bottom+v.height;h.current.style.left=`${t.left}px`,h.current.style.width=`${t.width}px`,b>=s-10?(h.current.style.top=`${t.top-v.height-5}px`,X("top")):(h.current.style.top=`${t.top+t.height+4}px`,X("bottom"))}};d.useEffect(()=>(window.addEventListener("scroll",y),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y),window.removeEventListener("resize",y)}),[]),d.useEffect(()=>{y()},[u]),d.useEffect(()=>{if(!u||!h.current)return;const s=new ResizeObserver(()=>{y()});return s.observe(h.current),()=>s.disconnect()},[u]),d.useEffect(()=>{u||q(-1)},[u]);const wn=s=>{if(!u){(s.key==="ArrowDown"||s.key==="Enter")&&(s.preventDefault(),P(!0));return}switch(s.key){case"ArrowDown":{s.preventDefault();const t=T(e,x,1);t!==-1&&q(t);break}case"ArrowUp":{s.preventDefault();const t=T(e,x,-1);t!==-1&&q(t);break}case"Enter":{s.preventDefault(),x>=0&&e[x]&&!e[x].disable&&G(e[x].label,e[x].value);break}case"Escape":P(!1);break}},J=r==="lg"||r==="xl"?20:16,K=n.jsx(on,{handleChangePosition:y,children:n.jsxs("div",{className:["sa-input-dropdown-container",A,`sa-input-dropdown-size-${r}`,u?"active":"",ln?"error":"",F?"disable":""].filter(Boolean).join(" "),ref:V,onClick:cn,onKeyDown:wn,tabIndex:0,onBlur:I,onFocus:D,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?d.cloneElement(f,{width:J,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:fn()}),u?n.jsx(dn,{width:J}):n.jsx(sn,{width:J})]}),n.jsx(en,{dropdownLists:e,handleChangeValue:G,isComponentVisible:u,positionDropdown:pn,searchAble:!!E,value:c,onSearch:k,ref:h,multiSelect:o,searchValue:L,highlightedIndex:x,footer:a,groupLabel:z,onSelectAll:O})]})});return m?tn==="outside-left"?n.jsxs("div",{className:`${M} 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}),Q&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),Z&&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&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})]}):n.jsxs("div",{className:M,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:m}),Q&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),Z&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]}):n.jsxs("div",{className:M,children:[N&&n.jsx("p",{className:"sa-select-field-helper-top",children:N}),K,C&&!w&&n.jsx("p",{className:"sa-select-field-helper",children:C}),w&&n.jsx("p",{className:"sa-select-field-error-msg",children:w})]})},T=(e,p,i)=>{const l=e.length;let r=p+i;for(;r>=0&&r<l;){if(!e[r].disable)return r;r+=i}if(i===1){for(let o=0;o<l;o++)if(!e[o].disable)return o}else for(let o=l-1;o>=0;o--)if(!e[o].disable)return o;return-1},an=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"})}),sn=({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"})}),dn=({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"})});g.Dropdown=rn,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
@@ -40,6 +40,7 @@ export interface IDropdown {
40
40
  footer?: React.ReactNode;
41
41
  groupLabel?: string;
42
42
  onSelectAll?: () => void;
43
+ fullWidth?: boolean;
43
44
  label?: React.ReactNode;
44
45
  labelPosition?: DropdownLabelPosition;
45
46
  required?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "3.5.1",
3
+ "version": "4.0.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",