@starasia/dropdown 5.1.0 → 5.2.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.
@@ -5,6 +5,7 @@ interface IProps {
5
5
  dropdownLists: IDropdown["dropdownLists"];
6
6
  isComponentVisible: boolean;
7
7
  searchAble: boolean;
8
+ hideSearch?: boolean;
8
9
  onSearch?: (e: string) => void;
9
10
  value: {
10
11
  label: string;
@@ -1,6 +1,6 @@
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");
1
+ import { jsxs as l, jsx as n, Fragment as an } from "react/jsx-runtime";
2
+ import tn, { useState as P, useRef as W, useEffect as x, forwardRef as fn } from "react";
3
+ const bn = `@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;
@@ -199,6 +199,38 @@ const pn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
199
199
  color: var(--sa-dropdown-placeholder-subtle);
200
200
  }
201
201
 
202
+ /* === TRIGGER INPUT MODE === */
203
+ .sa-input-dropdown-container.trigger-input {
204
+ cursor: text;
205
+ }
206
+ .sa-input-dropdown-container.trigger-input .sa-input-dropdown-container-preview-item {
207
+ flex-wrap: wrap;
208
+ gap: 4px;
209
+ align-items: center;
210
+ }
211
+ .sa-input-dropdown-trigger-input {
212
+ flex: 1;
213
+ min-width: 80px;
214
+ border: none;
215
+ outline: none;
216
+ background: transparent;
217
+ font-size: var(--baseFont);
218
+ font-family: inherit;
219
+ color: var(--sa-dropdown-text-primary);
220
+ padding: 0;
221
+ line-height: normal;
222
+ }
223
+ .sa-input-dropdown-trigger-input::placeholder {
224
+ color: var(--sa-dropdown-placeholder);
225
+ }
226
+ .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
227
+ .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
228
+ color: var(--sa-dropdown-placeholder-subtle);
229
+ }
230
+ .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
231
+ cursor: not-allowed;
232
+ }
233
+
202
234
  /* === DROPDOWN PANEL === */
203
235
  .sa-input-dropdown-lists-container {
204
236
  position: fixed;
@@ -454,19 +486,19 @@ const pn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
454
486
  }
455
487
 
456
488
  `;
457
- function cn(e) {
458
- const [p, d] = P(e), s = B(null), r = (o) => {
459
- s.current && !s.current.contains(o.target) && d(!1);
489
+ function gn(o) {
490
+ const [p, t] = P(o), s = W(null), d = (r) => {
491
+ s.current && !s.current.contains(r.target) && t(!1);
460
492
  };
461
- return g(() => (document.addEventListener("click", r, !0), () => {
462
- document.removeEventListener("click", r, !0);
463
- }), []), { ref: s, isComponentVisible: p, setIsComponentVisible: d };
493
+ return x(() => (document.addEventListener("click", d, !0), () => {
494
+ document.removeEventListener("click", d, !0);
495
+ }), []), { ref: s, isComponentVisible: p, setIsComponentVisible: t };
464
496
  }
465
- const un = ({ ...e }) => /* @__PURE__ */ l(
497
+ const vn = ({ ...o }) => /* @__PURE__ */ l(
466
498
  "svg",
467
499
  {
468
500
  xmlns: "http://www.w3.org/2000/svg",
469
- ...e,
501
+ ...o,
470
502
  viewBox: "0 0 20 20",
471
503
  fill: "none",
472
504
  children: [
@@ -494,12 +526,12 @@ const un = ({ ...e }) => /* @__PURE__ */ l(
494
526
  )
495
527
  ]
496
528
  }
497
- ), wn = ({ width: e = 16 }) => /* @__PURE__ */ n(
529
+ ), xn = ({ width: o = 16 }) => /* @__PURE__ */ n(
498
530
  "svg",
499
531
  {
500
532
  xmlns: "http://www.w3.org/2000/svg",
501
- width: e,
502
- height: e,
533
+ width: o,
534
+ height: o,
503
535
  viewBox: "0 0 16 16",
504
536
  fill: "none",
505
537
  children: /* @__PURE__ */ n(
@@ -513,86 +545,87 @@ const un = ({ ...e }) => /* @__PURE__ */ l(
513
545
  }
514
546
  )
515
547
  }
516
- ), hn = ln(
548
+ ), mn = fn(
517
549
  ({
518
- positionDropdown: e,
550
+ positionDropdown: o,
519
551
  dropdownLists: p,
520
- isComponentVisible: d,
552
+ isComponentVisible: t,
521
553
  searchAble: s,
554
+ hideSearch: d,
522
555
  onSearch: r,
523
- value: o,
524
- handleChangeValue: N,
525
- multiSelect: u,
526
- searchValue: F,
527
- highlightedIndex: m,
556
+ value: m,
557
+ handleChangeValue: u,
558
+ multiSelect: C,
559
+ searchValue: z,
560
+ highlightedIndex: y,
528
561
  footer: I,
529
- groupLabel: A,
530
- onSelectAll: D
531
- }, H) => {
532
- const L = B([]);
533
- g(() => {
562
+ groupLabel: F,
563
+ onSelectAll: R
564
+ }, q) => {
565
+ const D = W([]);
566
+ x(() => {
534
567
  var a;
535
- m >= 0 && L.current[m] && ((a = L.current[m]) == null || a.scrollIntoView({ block: "nearest" }));
536
- }, [m]);
537
- const j = s ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
538
- /* @__PURE__ */ n(un, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
568
+ y >= 0 && D.current[y] && ((a = D.current[y]) == null || a.scrollIntoView({ block: "nearest" }));
569
+ }, [y]);
570
+ const H = s && !d ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
571
+ /* @__PURE__ */ n(vn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
539
572
  /* @__PURE__ */ n(
540
573
  "input",
541
574
  {
542
575
  onChange: (a) => {
543
576
  r && r(a.target.value);
544
577
  },
545
- value: F,
578
+ value: z,
546
579
  autoFocus: !0,
547
580
  placeholder: "Search..."
548
581
  }
549
582
  )
550
583
  ] }) : null;
551
- return /* @__PURE__ */ n(sn, { children: d ? /* @__PURE__ */ l(
584
+ return /* @__PURE__ */ n(an, { children: t ? /* @__PURE__ */ l(
552
585
  "div",
553
586
  {
554
587
  className: "sa-input-dropdown-lists-container",
555
588
  onClick: (a) => a.stopPropagation(),
556
- ref: H,
589
+ ref: q,
557
590
  children: [
558
- e !== "top" && j,
591
+ o !== "top" && H,
559
592
  /* @__PURE__ */ l(
560
593
  "div",
561
594
  {
562
- className: `sa-input-dropdown-item-container ${u ? "multi" : ""}`,
595
+ className: `sa-input-dropdown-item-container ${C ? "multi" : ""}`,
563
596
  children: [
564
- A && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
565
- /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: A }),
566
- u && D && /* @__PURE__ */ n(
597
+ F && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
598
+ /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: F }),
599
+ C && R && /* @__PURE__ */ n(
567
600
  "button",
568
601
  {
569
602
  className: "sa-input-dropdown-section-select-all",
570
603
  onClick: (a) => {
571
- a.stopPropagation(), D();
604
+ a.stopPropagation(), R();
572
605
  },
573
606
  children: "Select all"
574
607
  }
575
608
  )
576
609
  ] }),
577
- p.map((a, R) => {
578
- const O = !!(o != null && o.find((k) => k.value === a.value)), M = !!a.description;
610
+ p.map((a, A) => {
611
+ const M = !!(m != null && m.find((j) => j.value === a.value)), w = !!a.description;
579
612
  return /* @__PURE__ */ l(
580
613
  "div",
581
614
  {
582
615
  className: [
583
616
  "sa-input-dropdown-item",
584
- M ? "has-description" : "",
585
- O ? "active" : "",
586
- R === m ? "highlight" : "",
617
+ w ? "has-description" : "",
618
+ M ? "active" : "",
619
+ A === y ? "highlight" : "",
587
620
  a.disable ? "sa-input-dropdown-item-disable" : ""
588
621
  ].filter(Boolean).join(" "),
589
- ref: (k) => {
590
- L.current[R] = k;
622
+ ref: (j) => {
623
+ D.current[A] = j;
591
624
  },
592
- onClick: () => N(a.label, a.value),
625
+ onClick: () => u(a.label, a.value),
593
626
  children: [
594
- u && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: O && /* @__PURE__ */ n(wn, { width: 16 }) }),
595
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: T.cloneElement(a.icon, { width: 16 }) }),
627
+ C && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: M && /* @__PURE__ */ n(xn, { width: 16 }) }),
628
+ a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: tn.cloneElement(a.icon, { width: 16 }) }),
596
629
  /* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
597
630
  /* @__PURE__ */ n(
598
631
  "p",
@@ -617,260 +650,302 @@ const un = ({ ...e }) => /* @__PURE__ */ l(
617
650
  ] })
618
651
  ]
619
652
  },
620
- R
653
+ A
621
654
  );
622
655
  })
623
656
  ]
624
657
  }
625
658
  ),
626
- e === "top" && j,
659
+ o === "top" && H,
627
660
  I && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: I })
628
661
  ]
629
662
  }
630
663
  ) : null });
631
664
  }
632
- ), fn = ({
633
- children: e,
665
+ ), kn = ({
666
+ children: o,
634
667
  handleChangePosition: p
635
668
  }) => {
636
- const d = B(null);
637
- g(() => {
638
- var N;
639
- const r = () => {
640
- if (d.current) {
641
- let u = d.current.parentElement;
669
+ const t = W(null);
670
+ x(() => {
671
+ var m;
672
+ const d = () => {
673
+ if (t.current) {
674
+ let u = t.current.parentElement;
642
675
  for (; u && !s(u); )
643
676
  u = u.parentElement;
644
677
  u && p();
645
678
  }
646
679
  };
647
- let o = (N = d.current) == null ? void 0 : N.parentElement;
648
- for (; o && !s(o); )
649
- o = o.parentElement;
650
- return o && o.addEventListener("scroll", r), r(), () => {
651
- o && o.removeEventListener("scroll", r);
680
+ let r = (m = t.current) == null ? void 0 : m.parentElement;
681
+ for (; r && !s(r); )
682
+ r = r.parentElement;
683
+ return r && r.addEventListener("scroll", d), d(), () => {
684
+ r && r.removeEventListener("scroll", d);
652
685
  };
653
686
  }, []);
654
- const s = (r) => r && (r.scrollHeight > r.clientHeight || r.scrollWidth > r.clientWidth);
655
- return /* @__PURE__ */ n("div", { ref: d, children: e });
656
- }, Y = "sa-input-dropdown-styles", bn = (e) => {
657
- if (!document.getElementById(Y)) {
687
+ const s = (d) => d && (d.scrollHeight > d.clientHeight || d.scrollWidth > d.clientWidth);
688
+ return /* @__PURE__ */ n("div", { ref: t, children: o });
689
+ }, en = "sa-input-dropdown-styles", yn = (o) => {
690
+ if (!document.getElementById(en)) {
658
691
  const p = document.createElement("style");
659
- p.id = Y, p.textContent = e, document.head.appendChild(p);
692
+ p.id = en, p.textContent = o, document.head.appendChild(p);
660
693
  }
661
694
  };
662
- bn(pn);
663
- const yn = ({
664
- dropdownLists: e,
695
+ yn(bn);
696
+ const Rn = ({
697
+ dropdownLists: o,
665
698
  onChange: p,
666
- defaultValue: d,
699
+ defaultValue: t,
667
700
  value: s,
668
- size: r = "md",
669
- multiSelect: o,
670
- searchAble: N,
701
+ size: d = "md",
702
+ multiSelect: r,
703
+ searchAble: m,
671
704
  iconLeft: u,
672
- placeholder: F,
673
- onSearch: m,
674
- error: I,
675
- onBlur: A,
676
- onFocus: D,
677
- disable: H,
678
- searchValue: L,
679
- variant: j = "outline",
680
- footer: a,
681
- groupLabel: R,
682
- onSelectAll: O,
705
+ placeholder: C,
706
+ onSearch: z,
707
+ error: y,
708
+ onBlur: I,
709
+ onFocus: F,
710
+ disable: R,
711
+ searchValue: q,
712
+ variant: D = "outline",
713
+ footer: H,
714
+ groupLabel: a,
715
+ onSelectAll: A,
683
716
  fullWidth: M = !0,
717
+ triggerInput: w = !1,
718
+ clearOnSelect: j = !1,
684
719
  /* field wrapper */
685
- label: k,
686
- labelPosition: nn = "outside-top",
687
- required: Z,
688
- optional: Q,
689
- description: E,
690
- helperText: C,
691
- errorText: w
720
+ label: G,
721
+ labelPosition: dn = "outside-top",
722
+ required: Y,
723
+ optional: _,
724
+ description: L,
725
+ helperText: B,
726
+ errorText: h
692
727
  }) => {
693
- const $ = [
728
+ const K = [
694
729
  "sa-select-field",
695
730
  M ? "sa-select-field-fullwidth" : ""
696
- ].filter(Boolean).join(" "), z = s !== void 0, V = B(), en = I || !!w, [c, S] = P(
697
- z ? s || [] : d || []
698
- ), [on, X] = P(""), [x, q] = P(-1), h = B(null), { isComponentVisible: f, ref: G, setIsComponentVisible: W } = cn(!1), rn = () => {
699
- W((t) => !t);
700
- }, J = (t, i) => {
701
- if (o)
702
- if (c == null ? void 0 : c.find((b) => b.value === i)) {
703
- const b = c.filter((dn) => dn.value !== i);
704
- z || S(b), p(b);
731
+ ].filter(Boolean).join(" "), S = s !== void 0, U = W(), sn = y || !!h, [c, O] = P(
732
+ S ? s || [] : t || []
733
+ ), [ln, V] = P(""), [k, J] = P(-1), [pn, T] = P(
734
+ () => {
735
+ var e, i;
736
+ return !r && (s != null && s.length || t != null && t.length) ? ((e = s == null ? void 0 : s[0]) == null ? void 0 : e.label) ?? ((i = t == null ? void 0 : t[0]) == null ? void 0 : i.label) ?? "" : "";
737
+ }
738
+ ), g = W(null), { isComponentVisible: f, ref: Z, setIsComponentVisible: N } = gn(!1), cn = () => {
739
+ N((e) => !e);
740
+ }, $ = (e, i) => {
741
+ if (r) {
742
+ if (c == null ? void 0 : c.find((v) => v.value === i)) {
743
+ const v = c.filter((hn) => hn.value !== i);
744
+ S || O(v), p(v);
705
745
  } else {
706
- const b = [...c, { label: t, value: i }];
707
- z || S(b), p(b);
746
+ const v = [...c, { label: e, value: i }];
747
+ S || O(v), p(v);
708
748
  }
709
- else {
710
- const v = [{ label: t, value: i }];
711
- z || S(v), p(v), W(!1);
749
+ w && T("");
750
+ } else {
751
+ const b = [{ label: e, value: i }];
752
+ S || O(b), p(b), w && T(j ? "" : e), N(!1);
712
753
  }
713
754
  };
714
- g(() => {
715
- z && S(s || []);
716
- }, [s]), g(() => {
717
- z || JSON.stringify(V.current) === JSON.stringify(d) || (V.current = d, S(V.current || []));
718
- }, [d]);
719
- const an = () => c.length ? o ? c == null ? void 0 : c.map((t, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
720
- /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: t == null ? void 0 : t.label }),
755
+ x(() => {
756
+ S && O(s || []);
757
+ }, [s]), x(() => {
758
+ S || JSON.stringify(U.current) === JSON.stringify(t) || (U.current = t, O(U.current || []));
759
+ }, [t]);
760
+ const wn = () => c.length ? r ? c == null ? void 0 : c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
761
+ /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
721
762
  /* @__PURE__ */ n(
722
- gn,
763
+ rn,
723
764
  {
724
- onClick: (v) => {
725
- v.stopPropagation(), J(t.label, t.value);
765
+ onClick: (b) => {
766
+ b.stopPropagation(), $(e.label, e.value);
726
767
  }
727
768
  }
728
769
  )
729
- ] }, 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 = () => {
730
- if (G.current && h.current) {
731
- const t = window.innerHeight, i = G.current.getBoundingClientRect(), v = h.current.getBoundingClientRect(), b = i.bottom + v.height;
732
- 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"));
770
+ ] }, 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: C }), E = () => {
771
+ if (Z.current && g.current) {
772
+ const e = window.innerHeight, i = Z.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), v = i.bottom + b.height;
773
+ g.current.style.left = `${i.left}px`, g.current.style.width = `${i.width}px`, v >= e - 10 ? (g.current.style.top = `${i.top - b.height - 5}px`, V("top")) : (g.current.style.top = `${i.top + i.height + 4}px`, V("bottom"));
733
774
  }
734
775
  };
735
- g(() => (window.addEventListener("scroll", y), window.addEventListener("resize", y), () => {
736
- window.removeEventListener("scroll", y), window.removeEventListener("resize", y);
737
- }), []), g(() => {
738
- y();
739
- }, [f]), g(() => {
740
- if (!f || !h.current)
776
+ x(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
777
+ window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
778
+ }), []), x(() => {
779
+ E();
780
+ }, [f]), x(() => {
781
+ if (!f || !g.current)
741
782
  return;
742
- const t = new ResizeObserver(() => {
743
- y();
783
+ const e = new ResizeObserver(() => {
784
+ E();
744
785
  });
745
- return t.observe(h.current), () => t.disconnect();
746
- }, [f]), g(() => {
747
- f || q(-1);
786
+ return e.observe(g.current), () => e.disconnect();
787
+ }, [f]), x(() => {
788
+ f || J(-1);
748
789
  }, [f]);
749
- const tn = (t) => {
790
+ const nn = (e) => {
750
791
  if (!f) {
751
- (t.key === "ArrowDown" || t.key === "Enter") && (t.preventDefault(), W(!0));
792
+ (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), N(!0));
752
793
  return;
753
794
  }
754
- switch (t.key) {
795
+ switch (e.key) {
755
796
  case "ArrowDown": {
756
- t.preventDefault();
757
- const i = _(e, x, 1);
758
- i !== -1 && q(i);
797
+ e.preventDefault();
798
+ const i = on(o, k, 1);
799
+ i !== -1 && J(i);
759
800
  break;
760
801
  }
761
802
  case "ArrowUp": {
762
- t.preventDefault();
763
- const i = _(e, x, -1);
764
- i !== -1 && q(i);
803
+ e.preventDefault();
804
+ const i = on(o, k, -1);
805
+ i !== -1 && J(i);
765
806
  break;
766
807
  }
767
808
  case "Enter": {
768
- t.preventDefault(), x >= 0 && e[x] && !e[x].disable && J(
769
- e[x].label,
770
- e[x].value
809
+ e.preventDefault(), k >= 0 && o[k] && !o[k].disable && $(
810
+ o[k].label,
811
+ o[k].value
771
812
  );
772
813
  break;
773
814
  }
774
815
  case "Escape":
775
- W(!1);
816
+ N(!1);
776
817
  break;
777
818
  }
778
- }, K = r === "lg" || r === "xl" ? 20 : 16, U = /* @__PURE__ */ n(fn, { handleChangePosition: y, children: /* @__PURE__ */ l(
819
+ }, Q = d === "lg" || d === "xl" ? 20 : 16, un = w ? /* @__PURE__ */ l(an, { children: [
820
+ r && c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
821
+ /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
822
+ /* @__PURE__ */ n(
823
+ rn,
824
+ {
825
+ onClick: (b) => {
826
+ b.stopPropagation(), $(e.label, e.value);
827
+ }
828
+ }
829
+ )
830
+ ] }, i)),
831
+ /* @__PURE__ */ n(
832
+ "input",
833
+ {
834
+ className: "sa-input-dropdown-trigger-input",
835
+ value: pn,
836
+ onChange: (e) => {
837
+ const i = e.target.value;
838
+ T(i), z == null || z(i), f || N(!0);
839
+ },
840
+ onFocus: () => {
841
+ R || N(!0);
842
+ },
843
+ onBlur: () => {
844
+ setTimeout(() => N(!1), 150);
845
+ },
846
+ onKeyDown: nn,
847
+ placeholder: c.length === 0 || r ? C : void 0,
848
+ disabled: R
849
+ }
850
+ )
851
+ ] }) : null, X = /* @__PURE__ */ n(kn, { handleChangePosition: E, children: /* @__PURE__ */ l(
779
852
  "div",
780
853
  {
781
854
  className: [
782
855
  "sa-input-dropdown-container",
783
- j,
784
- `sa-input-dropdown-size-${r}`,
856
+ D,
857
+ `sa-input-dropdown-size-${d}`,
858
+ w ? "trigger-input" : "",
785
859
  f ? "active" : "",
786
- en ? "error" : "",
787
- H ? "disable" : ""
860
+ sn ? "error" : "",
861
+ R ? "disable" : ""
788
862
  ].filter(Boolean).join(" "),
789
- ref: G,
790
- onClick: rn,
791
- onKeyDown: tn,
792
- tabIndex: 0,
793
- onBlur: A,
794
- onFocus: D,
863
+ ref: Z,
864
+ onClick: w ? void 0 : cn,
865
+ onKeyDown: w ? void 0 : nn,
866
+ tabIndex: w ? void 0 : 0,
867
+ onBlur: w ? void 0 : I,
868
+ onFocus: w ? void 0 : F,
795
869
  children: [
796
870
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
797
- u ? T.cloneElement(u, {
798
- width: K,
871
+ u ? tn.cloneElement(u, {
872
+ width: Q,
799
873
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
800
874
  }) : null,
801
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: an() }),
802
- f ? /* @__PURE__ */ n(vn, { width: K }) : /* @__PURE__ */ n(xn, { width: K })
875
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? un : wn() }),
876
+ f ? /* @__PURE__ */ n(En, { width: Q }) : /* @__PURE__ */ n(Nn, { width: Q })
803
877
  ] }),
804
878
  /* @__PURE__ */ n(
805
- hn,
879
+ mn,
806
880
  {
807
- dropdownLists: e,
808
- handleChangeValue: J,
881
+ dropdownLists: o,
882
+ handleChangeValue: $,
809
883
  isComponentVisible: f,
810
- positionDropdown: on,
811
- searchAble: !!N,
884
+ positionDropdown: ln,
885
+ searchAble: !!m,
886
+ hideSearch: w,
812
887
  value: c,
813
- onSearch: m,
814
- ref: h,
815
- multiSelect: o,
816
- searchValue: L,
817
- highlightedIndex: x,
818
- footer: a,
819
- groupLabel: R,
820
- onSelectAll: O
888
+ onSearch: z,
889
+ ref: g,
890
+ multiSelect: r,
891
+ searchValue: q,
892
+ highlightedIndex: k,
893
+ footer: H,
894
+ groupLabel: a,
895
+ onSelectAll: A
821
896
  }
822
897
  )
823
898
  ]
824
899
  }
825
900
  ) });
826
- return k ? nn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${$} sa-select-field-left`, children: [
901
+ return G ? dn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${K} sa-select-field-left`, children: [
827
902
  /* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
828
903
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
829
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
830
- Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
831
- Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
904
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: G }),
905
+ _ && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
906
+ Y && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
832
907
  ] }),
833
- E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E })
908
+ L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L })
834
909
  ] }),
835
910
  /* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
836
- U,
837
- C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
838
- w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
911
+ X,
912
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
913
+ h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
839
914
  ] })
840
- ] }) : /* @__PURE__ */ l("div", { className: $, children: [
915
+ ] }) : /* @__PURE__ */ l("div", { className: K, children: [
841
916
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
842
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: k }),
843
- Q && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
844
- Z && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
917
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: G }),
918
+ _ && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
919
+ Y && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
845
920
  ] }),
846
- E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
847
- U,
848
- C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
849
- w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
850
- ] }) : /* @__PURE__ */ l("div", { className: $, children: [
851
- E && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: E }),
852
- U,
853
- C && !w && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: C }),
854
- w && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: w })
921
+ L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L }),
922
+ X,
923
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
924
+ h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
925
+ ] }) : /* @__PURE__ */ l("div", { className: K, children: [
926
+ L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L }),
927
+ X,
928
+ B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
929
+ h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
855
930
  ] });
856
- }, _ = (e, p, d) => {
857
- const s = e.length;
858
- let r = p + d;
859
- for (; r >= 0 && r < s; ) {
860
- if (!e[r].disable)
861
- return r;
862
- r += d;
931
+ }, on = (o, p, t) => {
932
+ const s = o.length;
933
+ let d = p + t;
934
+ for (; d >= 0 && d < s; ) {
935
+ if (!o[d].disable)
936
+ return d;
937
+ d += t;
863
938
  }
864
- if (d === 1) {
865
- for (let o = 0; o < s; o++)
866
- if (!e[o].disable)
867
- return o;
939
+ if (t === 1) {
940
+ for (let r = 0; r < s; r++)
941
+ if (!o[r].disable)
942
+ return r;
868
943
  } else
869
- for (let o = s - 1; o >= 0; o--)
870
- if (!e[o].disable)
871
- return o;
944
+ for (let r = s - 1; r >= 0; r--)
945
+ if (!o[r].disable)
946
+ return r;
872
947
  return -1;
873
- }, gn = (e) => /* @__PURE__ */ n(
948
+ }, rn = (o) => /* @__PURE__ */ n(
874
949
  "svg",
875
950
  {
876
951
  xmlns: "http://www.w3.org/2000/svg",
@@ -879,7 +954,7 @@ const yn = ({
879
954
  viewBox: "0 0 18 18",
880
955
  fill: "none",
881
956
  style: { flexShrink: 0, cursor: "pointer" },
882
- ...e,
957
+ ...o,
883
958
  children: /* @__PURE__ */ n(
884
959
  "path",
885
960
  {
@@ -891,12 +966,12 @@ const yn = ({
891
966
  }
892
967
  )
893
968
  }
894
- ), xn = ({ width: e = 16 }) => /* @__PURE__ */ n(
969
+ ), Nn = ({ width: o = 16 }) => /* @__PURE__ */ n(
895
970
  "svg",
896
971
  {
897
972
  xmlns: "http://www.w3.org/2000/svg",
898
- width: e,
899
- height: e,
973
+ width: o,
974
+ height: o,
900
975
  viewBox: "0 0 16 16",
901
976
  fill: "none",
902
977
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 },
@@ -911,12 +986,12 @@ const yn = ({
911
986
  }
912
987
  )
913
988
  }
914
- ), vn = ({ width: e = 16 }) => /* @__PURE__ */ n(
989
+ ), En = ({ width: o = 16 }) => /* @__PURE__ */ n(
915
990
  "svg",
916
991
  {
917
992
  xmlns: "http://www.w3.org/2000/svg",
918
- width: e,
919
- height: e,
993
+ width: o,
994
+ height: o,
920
995
  viewBox: "0 0 16 16",
921
996
  fill: "none",
922
997
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 },
@@ -933,5 +1008,5 @@ const yn = ({
933
1008
  }
934
1009
  );
935
1010
  export {
936
- yn as Dropdown
1011
+ Rn as Dropdown
937
1012
  };
@@ -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 Y=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Dropdown={},x.jsxRuntime,x.React))})(this,function(x,n,l){"use strict";const on=`@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;
@@ -197,6 +197,38 @@
197
197
  color: var(--sa-dropdown-placeholder-subtle);
198
198
  }
199
199
 
200
+ /* === TRIGGER INPUT MODE === */
201
+ .sa-input-dropdown-container.trigger-input {
202
+ cursor: text;
203
+ }
204
+ .sa-input-dropdown-container.trigger-input .sa-input-dropdown-container-preview-item {
205
+ flex-wrap: wrap;
206
+ gap: 4px;
207
+ align-items: center;
208
+ }
209
+ .sa-input-dropdown-trigger-input {
210
+ flex: 1;
211
+ min-width: 80px;
212
+ border: none;
213
+ outline: none;
214
+ background: transparent;
215
+ font-size: var(--baseFont);
216
+ font-family: inherit;
217
+ color: var(--sa-dropdown-text-primary);
218
+ padding: 0;
219
+ line-height: normal;
220
+ }
221
+ .sa-input-dropdown-trigger-input::placeholder {
222
+ color: var(--sa-dropdown-placeholder);
223
+ }
224
+ .sa-input-dropdown-container.outline .sa-input-dropdown-trigger-input::placeholder,
225
+ .sa-input-dropdown-container.flushed .sa-input-dropdown-trigger-input::placeholder {
226
+ color: var(--sa-dropdown-placeholder-subtle);
227
+ }
228
+ .sa-input-dropdown-container.disable .sa-input-dropdown-trigger-input {
229
+ cursor: not-allowed;
230
+ }
231
+
200
232
  /* === DROPDOWN PANEL === */
201
233
  .sa-input-dropdown-lists-container {
202
234
  position: fixed;
@@ -451,4 +483,4 @@
451
483
  margin: 0;
452
484
  }
453
485
 
454
- `;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 z=d.useRef([]);d.useEffect(()=>{var a;k>=0&&z.current[k]&&((a=z.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-dropdown-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,L)=>{const O=!!(o!=null&&o.find(m=>m.value===a.value)),H=!!a.description;return n.jsxs("div",{className:["sa-input-dropdown-item",H?"has-description":"",O?"active":"",L===k?"highlight":"",a.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:m=>{z.current[L]=m},onClick:()=>E(a.label,a.value),children:[f&&n.jsx("div",{className:"sa-input-dropdown-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-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})]})]},L)})]}),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:z,variant:A="outline",footer:a,groupLabel:L,onSelectAll:O,fullWidth:H=!0,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:z,highlightedIndex:x,footer:a,groupLabel:L,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"})});
486
+ `;function rn(o){const[p,d]=l.useState(o),t=l.useRef(null),i=r=>{t.current&&!t.current.contains(r.target)&&d(!1)};return l.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:d}}const an=({...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"})]}),sn=({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"})}),dn=l.forwardRef(({positionDropdown:o,dropdownLists:p,isComponentVisible:d,searchAble:t,hideSearch:i,onSearch:r,value:k,handleChangeValue:f,multiSelect:C,searchValue:z,highlightedIndex:y,footer:W,groupLabel:I,onSelectAll:L},$)=>{const j=l.useRef([]);l.useEffect(()=>{var s;y>=0&&j.current[y]&&((s=j.current[y])==null||s.scrollIntoView({block:"nearest"}))},[y]);const F=t&&!i?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(an,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:s=>{r&&r(s.target.value)},value:z,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:s=>s.stopPropagation(),ref:$,children:[o!=="top"&&F,n.jsxs("div",{className:`sa-input-dropdown-item-container ${C?"multi":""}`,children:[I&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:I}),C&&L&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:s=>{s.stopPropagation(),L()},children:"Select all"})]}),p.map((s,A)=>{const M=!!(k!=null&&k.find(O=>O.value===s.value)),w=!!s.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",M?"active":"",A===y?"highlight":"",s.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{j.current[A]=O},onClick:()=>f(s.label,s.value),children:[C&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:M&&n.jsx(sn,{width:16})}),s.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(s.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",s.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:s.label}),s.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",s.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:s.description})]})]},A)})]}),o==="top"&&F,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:s=>s.stopPropagation(),children:W})]}):null})}),tn=({children:o,handleChangePosition:p})=>{const d=l.useRef(null);l.useEffect(()=>{var k;const i=()=>{if(d.current){let f=d.current.parentElement;for(;f&&!t(f);)f=f.parentElement;f&&p()}};let r=(k=d.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",i),i(),()=>{r&&r.removeEventListener("scroll",i)}},[]);const t=i=>i&&(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth);return n.jsx("div",{ref:d,children:o})},X="sa-input-dropdown-styles";(o=>{if(!document.getElementById(X)){const p=document.createElement("style");p.id=X,p.textContent=o,document.head.appendChild(p)}})(on);const ln=({dropdownLists:o,onChange:p,defaultValue:d,value:t,size:i="md",multiSelect:r,searchAble:k,iconLeft:f,placeholder:C,onSearch:z,error:y,onBlur:W,onFocus:I,disable:L,searchValue:$,variant:j="outline",footer:F,groupLabel:s,onSelectAll:A,fullWidth:M=!0,triggerInput:w=!1,clearOnSelect:O=!1,label:q,labelPosition:wn="outside-top",required:V,optional:R,description:S,helperText:B,errorText:h})=>{const G=["sa-select-field",M?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),D=t!==void 0,T=l.useRef(),fn=y||!!h,[c,P]=l.useState(D?t||[]:d||[]),[hn,nn]=l.useState(""),[m,K]=l.useState(-1),[un,U]=l.useState(()=>{var e,a;return!r&&(t!=null&&t.length||d!=null&&d.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((a=d==null?void 0:d[0])==null?void 0:a.label)??"":""}),g=l.useRef(null),{isComponentVisible:u,ref:J,setIsComponentVisible:E}=rn(!1),bn=()=>{E(e=>!e)},H=(e,a)=>{if(r){if(c==null?void 0:c.find(v=>v.value===a)){const v=c.filter(xn=>xn.value!==a);D||P(v),p(v)}else{const v=[...c,{label:e,value:a}];D||P(v),p(v)}w&&U("")}else{const b=[{label:e,value:a}];D||P(b),p(b),w&&U(O?"":e),E(!1)}};l.useEffect(()=>{D&&P(t||[])},[t]),l.useEffect(()=>{D||JSON.stringify(T.current)===JSON.stringify(d)||(T.current=d,P(T.current||[]))},[d]);const gn=()=>c.length?r?c==null?void 0:c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(_,{onClick:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)):n.jsx("p",{style:{minWidth:"max-content"},children:c==null?void 0:c[0].label}):n.jsx("p",{className:"sa-input-dropdown-placeholder",children:C}),N=()=>{if(J.current&&g.current){const e=window.innerHeight,a=J.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),v=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,v>=e-10?(g.current.style.top=`${a.top-b.height-5}px`,nn("top")):(g.current.style.top=`${a.top+a.height+4}px`,nn("bottom"))}};l.useEffect(()=>(window.addEventListener("scroll",N),window.addEventListener("resize",N),()=>{window.removeEventListener("scroll",N),window.removeEventListener("resize",N)}),[]),l.useEffect(()=>{N()},[u]),l.useEffect(()=>{if(!u||!g.current)return;const e=new ResizeObserver(()=>{N()});return e.observe(g.current),()=>e.disconnect()},[u]),l.useEffect(()=>{u||K(-1)},[u]);const en=e=>{if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=Y(o,m,1);a!==-1&&K(a);break}case"ArrowUp":{e.preventDefault();const a=Y(o,m,-1);a!==-1&&K(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&H(o[m].label,o[m].value);break}case"Escape":E(!1);break}},Z=i==="lg"||i==="xl"?20:16,vn=w?n.jsxs(n.Fragment,{children:[r&&c.map((e,a)=>n.jsxs("div",{className:"sa-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:e==null?void 0:e.label}),n.jsx(_,{onClick:b=>{b.stopPropagation(),H(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:un,onChange:e=>{const a=e.target.value;U(a),z==null||z(a),u||E(!0)},onFocus:()=>{L||E(!0)},onBlur:()=>{setTimeout(()=>E(!1),150)},onKeyDown:en,placeholder:c.length===0||r?C:void 0,disabled:L})]}):null,Q=n.jsx(tn,{handleChangePosition:N,children:n.jsxs("div",{className:["sa-input-dropdown-container",j,`sa-input-dropdown-size-${i}`,w?"trigger-input":"",u?"active":"",fn?"error":"",L?"disable":""].filter(Boolean).join(" "),ref:J,onClick:w?void 0:bn,onKeyDown:w?void 0:en,tabIndex:w?void 0:0,onBlur:w?void 0:W,onFocus:w?void 0:I,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?l.cloneElement(f,{width:Z,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?vn:gn()}),u?n.jsx(cn,{width:Z}):n.jsx(pn,{width:Z})]}),n.jsx(dn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:u,positionDropdown:hn,searchAble:!!k,hideSearch:w,value:c,onSearch:z,ref:g,multiSelect:r,searchValue:$,highlightedIndex:m,footer:F,groupLabel:s,onSelectAll:A})]})});return q?wn==="outside-left"?n.jsxs("div",{className:`${G} 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:q}),R&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),V&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Q,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):n.jsxs("div",{className:G,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:q}),R&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),V&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Q,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:G,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Q,B&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:B}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},Y=(o,p,d)=>{const t=o.length;let i=p+d;for(;i>=0&&i<t;){if(!o[i].disable)return i;i+=d}if(d===1){for(let r=0;r<t;r++)if(!o[r].disable)return r}else for(let r=t-1;r>=0;r--)if(!o[r].disable)return r;return-1},_=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"})}),pn=({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"})}),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",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=ln,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
@@ -41,6 +41,8 @@ export interface IDropdown {
41
41
  groupLabel?: string;
42
42
  onSelectAll?: () => void;
43
43
  fullWidth?: boolean;
44
+ triggerInput?: boolean;
45
+ clearOnSelect?: boolean;
44
46
  label?: React.ReactNode;
45
47
  labelPosition?: DropdownLabelPosition;
46
48
  required?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",