@starasia/dropdown 5.3.0 → 5.4.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 dn, { useState as W, useRef as I, useEffect as x, forwardRef as gn } from "react";
3
- const vn = `@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 ln, { useState as I, useRef as M, useEffect as x, forwardRef as yn } from "react";
3
+ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
4
4
  * {
5
5
  margin: 0;
6
6
  padding: 0;
@@ -44,6 +44,7 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
44
44
  --paddingInline: 12px;
45
45
  --paddingBlock: 4px;
46
46
  --iconSize: 16px;
47
+ --iconMarginTop: 4px;
47
48
  }
48
49
  .sa-input-dropdown-size-md {
49
50
  --baseFont: 14px;
@@ -52,6 +53,7 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
52
53
  --paddingInline: 12px;
53
54
  --paddingBlock: 8px;
54
55
  --iconSize: 16px;
56
+ --iconMarginTop: 4px;
55
57
  }
56
58
  .sa-input-dropdown-size-lg {
57
59
  --baseFont: 14px;
@@ -60,6 +62,7 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
60
62
  --paddingInline: 12px;
61
63
  --paddingBlock: 12px;
62
64
  --iconSize: 20px;
65
+ --iconMarginTop: 2px;
63
66
  }
64
67
  .sa-input-dropdown-size-xl {
65
68
  --baseFont: 16px;
@@ -68,6 +71,7 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
68
71
  --paddingInline: 16px;
69
72
  --paddingBlock: 16px;
70
73
  --iconSize: 20px;
74
+ --iconMarginTop: 2px;
71
75
  }
72
76
 
73
77
  /* === BASE CONTAINER === */
@@ -159,12 +163,26 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
159
163
  display: flex;
160
164
  flex-direction: row;
161
165
  gap: 8px;
162
- align-items: center;
166
+ align-items: flex-start;
163
167
  justify-content: space-between;
164
168
  width: 100%;
165
169
  min-width: 0;
166
170
  }
167
171
 
172
+ /* Chevron + clear button — top-aligned with margin so they appear visually
173
+ centered when single-line, and snap to top-right when content wraps */
174
+ .sa-input-dropdown-chevron,
175
+ .sa-input-dropdown-clear {
176
+ align-self: flex-start;
177
+ margin-top: var(--iconMarginTop, 4px);
178
+ }
179
+ .sa-input-dropdown-chevron {
180
+ display: inline-flex;
181
+ align-items: center;
182
+ justify-content: center;
183
+ flex-shrink: 0;
184
+ }
185
+
168
186
  .sa-input-dropdown-container-preview-item {
169
187
  flex: 1;
170
188
  display: flex;
@@ -485,16 +503,47 @@ const vn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
485
503
  margin: 0;
486
504
  }
487
505
 
506
+ /* === CLEAR BUTTON === */
507
+ .sa-input-dropdown-clear {
508
+ appearance: none;
509
+ border: 0;
510
+ background: transparent;
511
+ padding: 0;
512
+ cursor: pointer;
513
+ color: var(--sa-dropdown-placeholder);
514
+ border-radius: 50%;
515
+ flex-shrink: 0;
516
+ display: inline-flex;
517
+ align-items: center;
518
+ justify-content: center;
519
+ opacity: 1;
520
+ transition: opacity 120ms ease, color 120ms ease, transform 80ms ease;
521
+ }
522
+ .sa-input-dropdown-clear:hover {
523
+ color: var(--sa-dropdown-text-secondary);
524
+ }
525
+ .sa-input-dropdown-clear:active {
526
+ transform: scale(0.92);
527
+ }
528
+ .sa-input-dropdown-clear-hidden {
529
+ opacity: 0;
530
+ pointer-events: none;
531
+ cursor: default;
532
+ }
533
+ .sa-input-dropdown-container.disable .sa-input-dropdown-clear {
534
+ display: none;
535
+ }
536
+
488
537
  `;
489
- function xn(o) {
490
- const [p, t] = W(o), s = I(null), d = (r) => {
538
+ function En(o) {
539
+ const [p, t] = I(o), s = M(null), d = (r) => {
491
540
  s.current && !s.current.contains(r.target) && t(!1);
492
541
  };
493
542
  return x(() => (document.addEventListener("click", d, !0), () => {
494
543
  document.removeEventListener("click", d, !0);
495
544
  }), []), { ref: s, isComponentVisible: p, setIsComponentVisible: t };
496
545
  }
497
- const mn = ({ ...o }) => /* @__PURE__ */ l(
546
+ const Cn = ({ ...o }) => /* @__PURE__ */ l(
498
547
  "svg",
499
548
  {
500
549
  xmlns: "http://www.w3.org/2000/svg",
@@ -526,7 +575,7 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
526
575
  )
527
576
  ]
528
577
  }
529
- ), kn = ({ width: o = 16 }) => /* @__PURE__ */ n(
578
+ ), zn = ({ width: o = 16 }) => /* @__PURE__ */ n(
530
579
  "svg",
531
580
  {
532
581
  xmlns: "http://www.w3.org/2000/svg",
@@ -545,7 +594,7 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
545
594
  }
546
595
  )
547
596
  }
548
- ), yn = gn(
597
+ ), Rn = yn(
549
598
  ({
550
599
  positionDropdown: o,
551
600
  dropdownLists: p,
@@ -555,60 +604,60 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
555
604
  onSearch: r,
556
605
  value: m,
557
606
  handleChangeValue: u,
558
- multiSelect: C,
559
- searchValue: z,
607
+ multiSelect: R,
608
+ searchValue: L,
560
609
  highlightedIndex: y,
561
610
  footer: F,
562
611
  groupLabel: H,
563
- onSelectAll: R
564
- }, G) => {
565
- const S = I([]);
612
+ onSelectAll: N
613
+ }, U) => {
614
+ const j = M([]);
566
615
  x(() => {
567
- var a;
568
- y >= 0 && S.current[y] && ((a = S.current[y]) == null || a.scrollIntoView({ block: "nearest" }));
616
+ var i;
617
+ y >= 0 && j.current[y] && ((i = j.current[y]) == null || i.scrollIntoView({ block: "nearest" }));
569
618
  }, [y]);
570
- const M = s && !d ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
571
- /* @__PURE__ */ n(mn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
619
+ const T = s && !d ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
620
+ /* @__PURE__ */ n(Cn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
572
621
  /* @__PURE__ */ n(
573
622
  "input",
574
623
  {
575
- onChange: (a) => {
576
- r && r(a.target.value);
624
+ onChange: (i) => {
625
+ r && r(i.target.value);
577
626
  },
578
- value: z,
627
+ value: L,
579
628
  autoFocus: !0,
580
629
  placeholder: "Search..."
581
630
  }
582
631
  )
583
632
  ] }) : null;
584
- return /* @__PURE__ */ n(tn, { children: t ? /* @__PURE__ */ l(
633
+ return /* @__PURE__ */ n(sn, { children: t ? /* @__PURE__ */ l(
585
634
  "div",
586
635
  {
587
636
  className: "sa-input-dropdown-lists-container",
588
- onClick: (a) => a.stopPropagation(),
589
- ref: G,
637
+ onClick: (i) => i.stopPropagation(),
638
+ ref: U,
590
639
  children: [
591
- o !== "top" && M,
640
+ o !== "top" && T,
592
641
  /* @__PURE__ */ l(
593
642
  "div",
594
643
  {
595
- className: `sa-input-dropdown-item-container ${C ? "multi" : ""}`,
644
+ className: `sa-input-dropdown-item-container ${R ? "multi" : ""}`,
596
645
  children: [
597
646
  H && /* @__PURE__ */ l("div", { className: "sa-input-dropdown-section-header", children: [
598
647
  /* @__PURE__ */ n("span", { className: "sa-input-dropdown-section-label", children: H }),
599
- C && R && /* @__PURE__ */ n(
648
+ R && N && /* @__PURE__ */ n(
600
649
  "button",
601
650
  {
602
651
  className: "sa-input-dropdown-section-select-all",
603
- onClick: (a) => {
604
- a.stopPropagation(), R();
652
+ onClick: (i) => {
653
+ i.stopPropagation(), N();
605
654
  },
606
655
  children: "Select all"
607
656
  }
608
657
  )
609
658
  ] }),
610
- p.map((a, A) => {
611
- const $ = !!(m != null && m.find((P) => P.value === a.value)), w = !!a.description;
659
+ p.map((i, A) => {
660
+ const $ = !!(m != null && m.find((P) => P.value === i.value)), w = !!i.description;
612
661
  return /* @__PURE__ */ l(
613
662
  "div",
614
663
  {
@@ -617,34 +666,34 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
617
666
  w ? "has-description" : "",
618
667
  $ ? "active" : "",
619
668
  A === y ? "highlight" : "",
620
- a.disable ? "sa-input-dropdown-item-disable" : ""
669
+ i.disable ? "sa-input-dropdown-item-disable" : ""
621
670
  ].filter(Boolean).join(" "),
622
671
  ref: (P) => {
623
- S.current[A] = P;
672
+ j.current[A] = P;
624
673
  },
625
- onClick: () => u(a.label, a.value),
674
+ onClick: () => u(i.label, i.value),
626
675
  children: [
627
- C && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: $ && /* @__PURE__ */ n(kn, { width: 16 }) }),
628
- a.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: dn.cloneElement(a.icon, { width: 16 }) }),
676
+ R && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-item-check", children: $ && /* @__PURE__ */ n(zn, { width: 16 }) }),
677
+ i.icon && /* @__PURE__ */ n("div", { style: { flexShrink: 0, display: "flex" }, children: ln.cloneElement(i.icon, { width: 16 }) }),
629
678
  /* @__PURE__ */ l("div", { style: { minWidth: 0, flex: 1 }, children: [
630
679
  /* @__PURE__ */ n(
631
680
  "p",
632
681
  {
633
682
  className: [
634
683
  "sa-input-dropdown-item-text",
635
- a.disable ? "sa-input-dropdown-item-disable" : ""
684
+ i.disable ? "sa-input-dropdown-item-disable" : ""
636
685
  ].filter(Boolean).join(" "),
637
- children: a.label
686
+ children: i.label
638
687
  }
639
688
  ),
640
- a.description && /* @__PURE__ */ n(
689
+ i.description && /* @__PURE__ */ n(
641
690
  "p",
642
691
  {
643
692
  className: [
644
693
  "sa-input-dropdown-item-text-description",
645
- a.disable ? "sa-input-dropdown-item-disable" : ""
694
+ i.disable ? "sa-input-dropdown-item-disable" : ""
646
695
  ].filter(Boolean).join(" "),
647
- children: a.description
696
+ children: i.description
648
697
  }
649
698
  )
650
699
  ] })
@@ -656,17 +705,17 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
656
705
  ]
657
706
  }
658
707
  ),
659
- o === "top" && M,
660
- F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (a) => a.stopPropagation(), children: F })
708
+ o === "top" && T,
709
+ F && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-footer", onClick: (i) => i.stopPropagation(), children: F })
661
710
  ]
662
711
  }
663
712
  ) : null });
664
713
  }
665
- ), Nn = ({
714
+ ), Ln = ({
666
715
  children: o,
667
716
  handleChangePosition: p
668
717
  }) => {
669
- const t = I(null);
718
+ const t = M(null);
670
719
  x(() => {
671
720
  var m;
672
721
  const d = () => {
@@ -686,14 +735,14 @@ const mn = ({ ...o }) => /* @__PURE__ */ l(
686
735
  }, []);
687
736
  const s = (d) => d && (d.scrollHeight > d.clientHeight || d.scrollWidth > d.clientWidth);
688
737
  return /* @__PURE__ */ n("div", { ref: t, children: o });
689
- }, on = "sa-input-dropdown-styles", En = (o) => {
690
- if (!document.getElementById(on)) {
738
+ }, an = "sa-input-dropdown-styles", Bn = (o) => {
739
+ if (!document.getElementById(an)) {
691
740
  const p = document.createElement("style");
692
- p.id = on, p.textContent = o, document.head.appendChild(p);
741
+ p.id = an, p.textContent = o, document.head.appendChild(p);
693
742
  }
694
743
  };
695
- En(vn);
696
- const Bn = ({
744
+ Bn(Nn);
745
+ const On = ({
697
746
  dropdownLists: o,
698
747
  onChange: p,
699
748
  defaultValue: t,
@@ -702,236 +751,255 @@ const Bn = ({
702
751
  multiSelect: r,
703
752
  searchAble: m,
704
753
  iconLeft: u,
705
- placeholder: C,
706
- onSearch: z,
754
+ placeholder: R,
755
+ onSearch: L,
707
756
  error: y,
708
757
  onBlur: F,
709
758
  onFocus: H,
710
- disable: R,
711
- searchValue: G,
712
- variant: S = "outline",
713
- footer: M,
714
- groupLabel: a,
759
+ disable: N,
760
+ searchValue: U,
761
+ variant: j = "outline",
762
+ footer: T,
763
+ groupLabel: i,
715
764
  onSelectAll: A,
716
765
  fullWidth: $ = !0,
717
766
  triggerInput: w = !1,
718
767
  clearOnSelect: P = !1,
719
- hideChevronIcon: sn = !1,
768
+ hideChevronIcon: pn = !1,
769
+ clearable: cn = !1,
770
+ onClear: K,
720
771
  /* field wrapper */
721
- label: K,
722
- labelPosition: ln = "outside-top",
723
- required: _,
724
- optional: V,
725
- description: L,
726
- helperText: B,
772
+ label: J,
773
+ labelPosition: wn = "outside-top",
774
+ required: V,
775
+ optional: nn,
776
+ description: B,
777
+ helperText: D,
727
778
  errorText: h
728
779
  }) => {
729
- const U = [
780
+ const Z = [
730
781
  "sa-select-field",
731
782
  $ ? "sa-select-field-fullwidth" : ""
732
- ].filter(Boolean).join(" "), D = s !== void 0, J = I(), pn = y || !!h, [c, j] = W(
733
- D ? s || [] : t || []
734
- ), [cn, nn] = W(""), [k, T] = W(-1), [wn, Z] = W(
783
+ ].filter(Boolean).join(" "), E = s !== void 0, Q = M(), un = y || !!h, [c, S] = I(
784
+ E ? s || [] : t || []
785
+ ), [hn, en] = I(""), [k, X] = I(-1), [fn, q] = I(
735
786
  () => {
736
- var e, i;
737
- 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) ?? "" : "";
787
+ var e, a;
788
+ return !r && (s != null && s.length || t != null && t.length) ? ((e = s == null ? void 0 : s[0]) == null ? void 0 : e.label) ?? ((a = t == null ? void 0 : t[0]) == null ? void 0 : a.label) ?? "" : "";
738
789
  }
739
- ), g = I(null), { isComponentVisible: f, ref: Q, setIsComponentVisible: N } = xn(!1), O = o !== void 0, un = () => {
740
- O && N((e) => !e);
741
- }, q = (e, i) => {
790
+ ), g = M(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), O = o !== void 0, on = c.length > 0, bn = (e) => {
791
+ e.stopPropagation();
792
+ const a = [];
793
+ E || S(a), p(a), w && q(""), K == null || K();
794
+ }, gn = () => {
795
+ O && C((e) => !e);
796
+ }, G = (e, a) => {
742
797
  if (r) {
743
- if (c == null ? void 0 : c.find((v) => v.value === i)) {
744
- const v = c.filter((bn) => bn.value !== i);
745
- D || j(v), p(v);
798
+ if (c == null ? void 0 : c.find((v) => v.value === a)) {
799
+ const v = c.filter((kn) => kn.value !== a);
800
+ E || S(v), p(v);
746
801
  } else {
747
- const v = [...c, { label: e, value: i }];
748
- D || j(v), p(v);
802
+ const v = [...c, { label: e, value: a }];
803
+ E || S(v), p(v);
749
804
  }
750
- w && Z("");
805
+ w && q("");
751
806
  } else {
752
- const b = [{ label: e, value: i }];
753
- D || j(b), p(b), w && Z(P ? "" : e), N(!1);
807
+ const b = [{ label: e, value: a }];
808
+ E || S(b), p(b), w && q(P ? "" : e), C(!1);
754
809
  }
755
810
  };
756
811
  x(() => {
757
- D && j(s || []);
812
+ E && S(s || []);
758
813
  }, [s]), x(() => {
759
- D || JSON.stringify(J.current) === JSON.stringify(t) || (J.current = t, j(J.current || []));
814
+ E || JSON.stringify(Q.current) === JSON.stringify(t) || (Q.current = t, S(Q.current || []));
760
815
  }, [t]);
761
- const hn = () => c.length ? r ? c == null ? void 0 : c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
816
+ const vn = () => c.length ? r ? c == null ? void 0 : c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
762
817
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
763
818
  /* @__PURE__ */ n(
764
- an,
819
+ dn,
765
820
  {
766
821
  onClick: (b) => {
767
- b.stopPropagation(), q(e.label, e.value);
822
+ b.stopPropagation(), G(e.label, e.value);
768
823
  }
769
824
  }
770
825
  )
771
- ] }, 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 = () => {
772
- if (Q.current && g.current) {
773
- const e = window.innerHeight, i = Q.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), v = i.bottom + b.height;
774
- 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`, nn("top")) : (g.current.style.top = `${i.top + i.height + 4}px`, nn("bottom"));
826
+ ] }, a)) : /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: c == null ? void 0 : c[0].label }) : /* @__PURE__ */ n("p", { className: "sa-input-dropdown-placeholder", children: R }), z = () => {
827
+ if (Y.current && g.current) {
828
+ const e = window.innerHeight, a = Y.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), v = a.bottom + b.height;
829
+ 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`, en("top")) : (g.current.style.top = `${a.top + a.height + 4}px`, en("bottom"));
775
830
  }
776
831
  };
777
- x(() => (window.addEventListener("scroll", E), window.addEventListener("resize", E), () => {
778
- window.removeEventListener("scroll", E), window.removeEventListener("resize", E);
832
+ x(() => (window.addEventListener("scroll", z), window.addEventListener("resize", z), () => {
833
+ window.removeEventListener("scroll", z), window.removeEventListener("resize", z);
779
834
  }), []), x(() => {
780
- E();
835
+ z();
781
836
  }, [f]), x(() => {
782
837
  if (!f || !g.current)
783
838
  return;
784
839
  const e = new ResizeObserver(() => {
785
- E();
840
+ z();
786
841
  });
787
842
  return e.observe(g.current), () => e.disconnect();
788
843
  }, [f]), x(() => {
789
- f || T(-1);
844
+ f || X(-1);
790
845
  }, [f]);
791
- const en = (e) => {
846
+ const rn = (e) => {
792
847
  if (O) {
793
848
  if (!f) {
794
- (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), N(!0));
849
+ (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
795
850
  return;
796
851
  }
797
852
  switch (e.key) {
798
853
  case "ArrowDown": {
799
854
  e.preventDefault();
800
- const i = rn(o, k, 1);
801
- i !== -1 && T(i);
855
+ const a = tn(o, k, 1);
856
+ a !== -1 && X(a);
802
857
  break;
803
858
  }
804
859
  case "ArrowUp": {
805
860
  e.preventDefault();
806
- const i = rn(o, k, -1);
807
- i !== -1 && T(i);
861
+ const a = tn(o, k, -1);
862
+ a !== -1 && X(a);
808
863
  break;
809
864
  }
810
865
  case "Enter": {
811
- e.preventDefault(), k >= 0 && o[k] && !o[k].disable && q(
866
+ e.preventDefault(), k >= 0 && o[k] && !o[k].disable && G(
812
867
  o[k].label,
813
868
  o[k].value
814
869
  );
815
870
  break;
816
871
  }
817
872
  case "Escape":
818
- N(!1);
873
+ C(!1);
819
874
  break;
820
875
  }
821
876
  }
822
- }, X = d === "lg" || d === "xl" ? 20 : 16, fn = w ? /* @__PURE__ */ l(tn, { children: [
823
- r && c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
877
+ }, W = d === "lg" || d === "xl" ? 20 : 16, xn = cn && !N ? /* @__PURE__ */ n(
878
+ "button",
879
+ {
880
+ type: "button",
881
+ className: `sa-input-dropdown-clear${on ? "" : " sa-input-dropdown-clear-hidden"}`,
882
+ "aria-label": "Clear selection",
883
+ "aria-hidden": !on,
884
+ tabIndex: -1,
885
+ onClick: bn,
886
+ onMouseDown: (e) => e.preventDefault(),
887
+ children: /* @__PURE__ */ n(Dn, { width: W, height: W })
888
+ }
889
+ ) : null, mn = w ? /* @__PURE__ */ l(sn, { children: [
890
+ r && c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
824
891
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
825
892
  /* @__PURE__ */ n(
826
- an,
893
+ dn,
827
894
  {
828
895
  onClick: (b) => {
829
- b.stopPropagation(), q(e.label, e.value);
896
+ b.stopPropagation(), G(e.label, e.value);
830
897
  }
831
898
  }
832
899
  )
833
- ] }, i)),
900
+ ] }, a)),
834
901
  /* @__PURE__ */ n(
835
902
  "input",
836
903
  {
837
904
  className: "sa-input-dropdown-trigger-input",
838
- value: wn,
905
+ value: fn,
839
906
  onChange: (e) => {
840
- const i = e.target.value;
841
- Z(i), z == null || z(i), !f && O && N(!0);
907
+ const a = e.target.value;
908
+ q(a), L == null || L(a), !f && O && C(!0);
842
909
  },
843
910
  onFocus: () => {
844
- !R && O && N(!0);
911
+ !N && O && C(!0);
845
912
  },
846
913
  onBlur: () => {
847
- r || setTimeout(() => N(!1), 150);
914
+ r || setTimeout(() => C(!1), 150);
848
915
  },
849
- onKeyDown: en,
850
- placeholder: c.length === 0 || r ? C : void 0,
851
- disabled: R
916
+ onKeyDown: rn,
917
+ placeholder: c.length === 0 || r ? R : void 0,
918
+ disabled: N
852
919
  }
853
920
  )
854
- ] }) : null, Y = /* @__PURE__ */ n(Nn, { handleChangePosition: E, children: /* @__PURE__ */ l(
921
+ ] }) : null, _ = /* @__PURE__ */ n(Ln, { handleChangePosition: z, children: /* @__PURE__ */ l(
855
922
  "div",
856
923
  {
857
924
  className: [
858
925
  "sa-input-dropdown-container",
859
- S,
926
+ j,
860
927
  `sa-input-dropdown-size-${d}`,
861
928
  w ? "trigger-input" : "",
862
929
  f ? "active" : "",
863
- pn ? "error" : "",
864
- R ? "disable" : ""
930
+ un ? "error" : "",
931
+ N ? "disable" : ""
865
932
  ].filter(Boolean).join(" "),
866
- ref: Q,
867
- onClick: w ? void 0 : un,
868
- onKeyDown: w ? void 0 : en,
933
+ ref: Y,
934
+ onClick: w ? void 0 : gn,
935
+ onKeyDown: w ? void 0 : rn,
869
936
  tabIndex: w ? void 0 : 0,
870
937
  onBlur: w ? void 0 : F,
871
938
  onFocus: w ? void 0 : H,
872
939
  children: [
873
940
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
874
- u ? dn.cloneElement(u, {
875
- width: X,
941
+ u ? ln.cloneElement(u, {
942
+ width: W,
876
943
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
877
944
  }) : null,
878
- /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? fn : hn() }),
879
- !sn && (f ? /* @__PURE__ */ n(zn, { width: X }) : /* @__PURE__ */ n(Cn, { width: X }))
945
+ /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : vn() }),
946
+ xn,
947
+ !pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(jn, { width: W }) : /* @__PURE__ */ n(Sn, { width: W }) })
880
948
  ] }),
881
949
  O && /* @__PURE__ */ n(
882
- yn,
950
+ Rn,
883
951
  {
884
952
  dropdownLists: o,
885
- handleChangeValue: q,
953
+ handleChangeValue: G,
886
954
  isComponentVisible: f,
887
- positionDropdown: cn,
955
+ positionDropdown: hn,
888
956
  searchAble: !!m,
889
957
  hideSearch: w,
890
958
  value: c,
891
- onSearch: z,
959
+ onSearch: L,
892
960
  ref: g,
893
961
  multiSelect: r,
894
- searchValue: G,
962
+ searchValue: U,
895
963
  highlightedIndex: k,
896
- footer: M,
897
- groupLabel: a,
964
+ footer: T,
965
+ groupLabel: i,
898
966
  onSelectAll: A
899
967
  }
900
968
  )
901
969
  ]
902
970
  }
903
971
  ) });
904
- return K ? ln === "outside-left" ? /* @__PURE__ */ l("div", { className: `${U} sa-select-field-left`, children: [
972
+ return J ? wn === "outside-left" ? /* @__PURE__ */ l("div", { className: `${Z} sa-select-field-left`, children: [
905
973
  /* @__PURE__ */ l("div", { className: "sa-select-field-left-label", children: [
906
974
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
907
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: K }),
908
- V && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
909
- _ && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
975
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: J }),
976
+ nn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
977
+ V && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
910
978
  ] }),
911
- L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L })
979
+ B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B })
912
980
  ] }),
913
981
  /* @__PURE__ */ l("div", { className: "sa-select-field-input-wrap", children: [
914
- Y,
915
- B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
982
+ _,
983
+ D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
916
984
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
917
985
  ] })
918
- ] }) : /* @__PURE__ */ l("div", { className: U, children: [
986
+ ] }) : /* @__PURE__ */ l("div", { className: Z, children: [
919
987
  /* @__PURE__ */ l("div", { className: "sa-select-field-label-row", children: [
920
- /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: K }),
921
- V && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
922
- _ && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
988
+ /* @__PURE__ */ n("span", { className: "sa-select-field-label-text", children: J }),
989
+ nn && /* @__PURE__ */ n("span", { className: "sa-select-field-optional-badge", children: "Optional" }),
990
+ V && /* @__PURE__ */ n("span", { className: "sa-select-field-required", children: "*" })
923
991
  ] }),
924
- L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L }),
925
- Y,
926
- B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
992
+ B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
993
+ _,
994
+ D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
927
995
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
928
- ] }) : /* @__PURE__ */ l("div", { className: U, children: [
929
- L && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: L }),
930
- Y,
931
- B && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: B }),
996
+ ] }) : /* @__PURE__ */ l("div", { className: Z, children: [
997
+ B && /* @__PURE__ */ n("p", { className: "sa-select-field-helper-top", children: B }),
998
+ _,
999
+ D && !h && /* @__PURE__ */ n("p", { className: "sa-select-field-helper", children: D }),
932
1000
  h && /* @__PURE__ */ n("p", { className: "sa-select-field-error-msg", children: h })
933
1001
  ] });
934
- }, rn = (o, p, t) => {
1002
+ }, tn = (o, p, t) => {
935
1003
  const s = o.length;
936
1004
  let d = p + t;
937
1005
  for (; d >= 0 && d < s; ) {
@@ -948,7 +1016,10 @@ const Bn = ({
948
1016
  if (!o[r].disable)
949
1017
  return r;
950
1018
  return -1;
951
- }, an = (o) => /* @__PURE__ */ n(
1019
+ }, Dn = (o) => /* @__PURE__ */ l("svg", { viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...o, children: [
1020
+ /* @__PURE__ */ n("circle", { cx: "8", cy: "8", r: "7", fill: "currentColor", opacity: "0.2" }),
1021
+ /* @__PURE__ */ n("path", { d: "M5.5 5.5l5 5M10.5 5.5l-5 5", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
1022
+ ] }), dn = (o) => /* @__PURE__ */ n(
952
1023
  "svg",
953
1024
  {
954
1025
  xmlns: "http://www.w3.org/2000/svg",
@@ -969,7 +1040,7 @@ const Bn = ({
969
1040
  }
970
1041
  )
971
1042
  }
972
- ), Cn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1043
+ ), Sn = ({ width: o = 16 }) => /* @__PURE__ */ n(
973
1044
  "svg",
974
1045
  {
975
1046
  xmlns: "http://www.w3.org/2000/svg",
@@ -989,7 +1060,7 @@ const Bn = ({
989
1060
  }
990
1061
  )
991
1062
  }
992
- ), zn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1063
+ ), jn = ({ width: o = 16 }) => /* @__PURE__ */ n(
993
1064
  "svg",
994
1065
  {
995
1066
  xmlns: "http://www.w3.org/2000/svg",
@@ -1011,5 +1082,5 @@ const Bn = ({
1011
1082
  }
1012
1083
  );
1013
1084
  export {
1014
- Bn as Dropdown
1085
+ On as Dropdown
1015
1086
  };
@@ -1,4 +1,4 @@
1
- (function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.Dropdown={},x.jsxRuntime,x.React))})(this,function(x,n,l){"use strict";const rn=`@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 sn=`@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;
@@ -42,6 +42,7 @@
42
42
  --paddingInline: 12px;
43
43
  --paddingBlock: 4px;
44
44
  --iconSize: 16px;
45
+ --iconMarginTop: 4px;
45
46
  }
46
47
  .sa-input-dropdown-size-md {
47
48
  --baseFont: 14px;
@@ -50,6 +51,7 @@
50
51
  --paddingInline: 12px;
51
52
  --paddingBlock: 8px;
52
53
  --iconSize: 16px;
54
+ --iconMarginTop: 4px;
53
55
  }
54
56
  .sa-input-dropdown-size-lg {
55
57
  --baseFont: 14px;
@@ -58,6 +60,7 @@
58
60
  --paddingInline: 12px;
59
61
  --paddingBlock: 12px;
60
62
  --iconSize: 20px;
63
+ --iconMarginTop: 2px;
61
64
  }
62
65
  .sa-input-dropdown-size-xl {
63
66
  --baseFont: 16px;
@@ -66,6 +69,7 @@
66
69
  --paddingInline: 16px;
67
70
  --paddingBlock: 16px;
68
71
  --iconSize: 20px;
72
+ --iconMarginTop: 2px;
69
73
  }
70
74
 
71
75
  /* === BASE CONTAINER === */
@@ -157,12 +161,26 @@
157
161
  display: flex;
158
162
  flex-direction: row;
159
163
  gap: 8px;
160
- align-items: center;
164
+ align-items: flex-start;
161
165
  justify-content: space-between;
162
166
  width: 100%;
163
167
  min-width: 0;
164
168
  }
165
169
 
170
+ /* Chevron + clear button — top-aligned with margin so they appear visually
171
+ centered when single-line, and snap to top-right when content wraps */
172
+ .sa-input-dropdown-chevron,
173
+ .sa-input-dropdown-clear {
174
+ align-self: flex-start;
175
+ margin-top: var(--iconMarginTop, 4px);
176
+ }
177
+ .sa-input-dropdown-chevron {
178
+ display: inline-flex;
179
+ align-items: center;
180
+ justify-content: center;
181
+ flex-shrink: 0;
182
+ }
183
+
166
184
  .sa-input-dropdown-container-preview-item {
167
185
  flex: 1;
168
186
  display: flex;
@@ -483,4 +501,35 @@
483
501
  margin: 0;
484
502
  }
485
503
 
486
- `;function an(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 sn=({...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"})]}),dn=({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"})}),tn=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:I,groupLabel:F,onSelectAll:L},q)=>{const j=l.useRef([]);l.useEffect(()=>{var s;y>=0&&j.current[y]&&((s=j.current[y])==null||s.scrollIntoView({block:"nearest"}))},[y]);const M=t&&!i?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(sn,{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:q,children:[o!=="top"&&M,n.jsxs("div",{className:`sa-input-dropdown-item-container ${C?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),C&&L&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:s=>{s.stopPropagation(),L()},children:"Select all"})]}),p.map((s,P)=>{const H=!!(k!=null&&k.find(A=>A.value===s.value)),w=!!s.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",H?"active":"",P===y?"highlight":"",s.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:A=>{j.current[P]=A},onClick:()=>f(s.label,s.value),children:[C&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:H&&n.jsx(dn,{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})]})]},P)})]}),o==="top"&&M,I&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:s=>s.stopPropagation(),children:I})]}):null})}),ln=({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})},Y="sa-input-dropdown-styles";(o=>{if(!document.getElementById(Y)){const p=document.createElement("style");p.id=Y,p.textContent=o,document.head.appendChild(p)}})(rn);const pn=({dropdownLists:o,onChange:p,defaultValue:d,value:t,size:i="md",multiSelect:r,searchAble:k,iconLeft:f,placeholder:C,onSearch:z,error:y,onBlur:I,onFocus:F,disable:L,searchValue:q,variant:j="outline",footer:M,groupLabel:s,onSelectAll:P,fullWidth:H=!0,triggerInput:w=!1,clearOnSelect:A=!1,hideChevronIcon:fn=!1,label:G,labelPosition:hn="outside-top",required:R,optional:nn,description:B,helperText:S,errorText:h})=>{const T=["sa-select-field",H?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),D=t!==void 0,K=l.useRef(),un=y||!!h,[c,O]=l.useState(D?t||[]:d||[]),[bn,en]=l.useState(""),[m,U]=l.useState(-1),[gn,J]=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:Z,setIsComponentVisible:E}=an(!1),W=o!==void 0,vn=()=>{W&&E(e=>!e)},$=(e,a)=>{if(r){if(c==null?void 0:c.find(v=>v.value===a)){const v=c.filter(mn=>mn.value!==a);D||O(v),p(v)}else{const v=[...c,{label:e,value:a}];D||O(v),p(v)}w&&J("")}else{const b=[{label:e,value:a}];D||O(b),p(b),w&&J(A?"":e),E(!1)}};l.useEffect(()=>{D&&O(t||[])},[t]),l.useEffect(()=>{D||JSON.stringify(K.current)===JSON.stringify(d)||(K.current=d,O(K.current||[]))},[d]);const xn=()=>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(V,{onClick:b=>{b.stopPropagation(),$(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(Z.current&&g.current){const e=window.innerHeight,a=Z.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`,en("top")):(g.current.style.top=`${a.top+a.height+4}px`,en("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||U(-1)},[u]);const on=e=>{if(W){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),E(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=_(o,m,1);a!==-1&&U(a);break}case"ArrowUp":{e.preventDefault();const a=_(o,m,-1);a!==-1&&U(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&$(o[m].label,o[m].value);break}case"Escape":E(!1);break}}},Q=i==="lg"||i==="xl"?20:16,kn=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(V,{onClick:b=>{b.stopPropagation(),$(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:gn,onChange:e=>{const a=e.target.value;J(a),z==null||z(a),!u&&W&&E(!0)},onFocus:()=>{!L&&W&&E(!0)},onBlur:()=>{r||setTimeout(()=>E(!1),150)},onKeyDown:on,placeholder:c.length===0||r?C:void 0,disabled:L})]}):null,X=n.jsx(ln,{handleChangePosition:N,children:n.jsxs("div",{className:["sa-input-dropdown-container",j,`sa-input-dropdown-size-${i}`,w?"trigger-input":"",u?"active":"",un?"error":"",L?"disable":""].filter(Boolean).join(" "),ref:Z,onClick:w?void 0:vn,onKeyDown:w?void 0:on,tabIndex:w?void 0:0,onBlur:w?void 0:I,onFocus:w?void 0:F,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?l.cloneElement(f,{width:Q,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?kn:xn()}),!fn&&(u?n.jsx(wn,{width:Q}):n.jsx(cn,{width:Q}))]}),W&&n.jsx(tn,{dropdownLists:o,handleChangeValue:$,isComponentVisible:u,positionDropdown:bn,searchAble:!!k,hideSearch:w,value:c,onSearch:z,ref:g,multiSelect:r,searchValue:q,highlightedIndex:m,footer:M,groupLabel:s,onSelectAll:P})]})});return G?hn==="outside-left"?n.jsxs("div",{className:`${T} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:G}),nn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),R&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[X,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})]}):n.jsxs("div",{className:T,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:G}),nn&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),R&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),X,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:T,children:[B&&n.jsx("p",{className:"sa-select-field-helper-top",children:B}),X,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},_=(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},V=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"})}),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 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),wn=({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=pn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
504
+ /* === CLEAR BUTTON === */
505
+ .sa-input-dropdown-clear {
506
+ appearance: none;
507
+ border: 0;
508
+ background: transparent;
509
+ padding: 0;
510
+ cursor: pointer;
511
+ color: var(--sa-dropdown-placeholder);
512
+ border-radius: 50%;
513
+ flex-shrink: 0;
514
+ display: inline-flex;
515
+ align-items: center;
516
+ justify-content: center;
517
+ opacity: 1;
518
+ transition: opacity 120ms ease, color 120ms ease, transform 80ms ease;
519
+ }
520
+ .sa-input-dropdown-clear:hover {
521
+ color: var(--sa-dropdown-text-secondary);
522
+ }
523
+ .sa-input-dropdown-clear:active {
524
+ transform: scale(0.92);
525
+ }
526
+ .sa-input-dropdown-clear-hidden {
527
+ opacity: 0;
528
+ pointer-events: none;
529
+ cursor: default;
530
+ }
531
+ .sa-input-dropdown-container.disable .sa-input-dropdown-clear {
532
+ display: none;
533
+ }
534
+
535
+ `;function dn(o){const[p,i]=l.useState(o),t=l.useRef(null),d=r=>{t.current&&!t.current.contains(r.target)&&i(!1)};return l.useEffect(()=>(document.addEventListener("click",d,!0),()=>{document.removeEventListener("click",d,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:i}}const tn=({...o})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...o,viewBox:"0 0 20 20",fill:"none",children:[n.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),ln=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",children:n.jsx("path",{d:"M3.5 8L6.5 11L12.5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),pn=l.forwardRef(({positionDropdown:o,dropdownLists:p,isComponentVisible:i,searchAble:t,hideSearch:d,onSearch:r,value:k,handleChangeValue:h,multiSelect:L,searchValue:B,highlightedIndex:m,footer:I,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var s;m>=0&&P.current[m]&&((s=P.current[m])==null||s.scrollIntoView({block:"nearest"}))},[m]);const T=t&&!d?n.jsxs("div",{className:"sa-input-dropdown-container-dropdown-search",children:[n.jsx(tn,{strokeWidth:2,width:16,style:{flexShrink:0,color:"var(--sa-dropdown-placeholder-subtle)"}}),n.jsx("input",{onChange:s=>{r&&r(s.target.value)},value:B,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:i?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:s=>s.stopPropagation(),ref:G,children:[o!=="top"&&T,n.jsxs("div",{className:`sa-input-dropdown-item-container ${L?"multi":""}`,children:[F&&n.jsxs("div",{className:"sa-input-dropdown-section-header",children:[n.jsx("span",{className:"sa-input-dropdown-section-label",children:F}),L&&N&&n.jsx("button",{className:"sa-input-dropdown-section-select-all",onClick:s=>{s.stopPropagation(),N()},children:"Select all"})]}),p.map((s,A)=>{const H=!!(k!=null&&k.find(O=>O.value===s.value)),w=!!s.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",H?"active":"",A===m?"highlight":"",s.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>h(s.label,s.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:H&&n.jsx(ln,{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"&&T,I&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:s=>s.stopPropagation(),children:I})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const i=l.useRef(null);l.useEffect(()=>{var k;const d=()=>{if(i.current){let h=i.current.parentElement;for(;h&&!t(h);)h=h.parentElement;h&&p()}};let r=(k=i.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",d),d(),()=>{r&&r.removeEventListener("scroll",d)}},[]);const t=d=>d&&(d.scrollHeight>d.clientHeight||d.scrollWidth>d.clientWidth);return n.jsx("div",{ref:i,children:o})},_="sa-input-dropdown-styles";(o=>{if(!document.getElementById(_)){const p=document.createElement("style");p.id=_,p.textContent=o,document.head.appendChild(p)}})(sn);const wn=({dropdownLists:o,onChange:p,defaultValue:i,value:t,size:d="md",multiSelect:r,searchAble:k,iconLeft:h,placeholder:L,onSearch:B,error:m,onBlur:I,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:s,onSelectAll:A,fullWidth:H=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:vn="outside-top",required:nn,optional:en,description:S,helperText:D,errorText:f})=>{const J=["sa-select-field",H?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),xn=m||!!f,[c,j]=l.useState(E?t||[]:i||[]),[kn,on]=l.useState(""),[y,Q]=l.useState(-1),[yn,$]=l.useState(()=>{var e,a;return!r&&(t!=null&&t.length||i!=null&&i.length)?((e=t==null?void 0:t[0])==null?void 0:e.label)??((a=i==null?void 0:i[0])==null?void 0:a.label)??"":""}),g=l.useRef(null),{isComponentVisible:u,ref:X,setIsComponentVisible:C}=dn(!1),W=o!==void 0,rn=c.length>0,mn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&$(""),U==null||U()},Nn=()=>{W&&C(e=>!e)},q=(e,a)=>{if(r){if(c==null?void 0:c.find(v=>v.value===a)){const v=c.filter(Ln=>Ln.value!==a);E||j(v),p(v)}else{const v=[...c,{label:e,value:a}];E||j(v),p(v)}w&&$("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&$(O?"":e),C(!1)}};l.useEffect(()=>{E&&j(t||[])},[t]),l.useEffect(()=>{E||JSON.stringify(Z.current)===JSON.stringify(i)||(Z.current=i,j(Z.current||[]))},[i]);const En=()=>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(R,{onClick:b=>{b.stopPropagation(),q(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:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.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`,on("top")):(g.current.style.top=`${a.top+a.height+4}px`,on("bottom"))}};l.useEffect(()=>(window.addEventListener("scroll",z),window.addEventListener("resize",z),()=>{window.removeEventListener("scroll",z),window.removeEventListener("resize",z)}),[]),l.useEffect(()=>{z()},[u]),l.useEffect(()=>{if(!u||!g.current)return;const e=new ResizeObserver(()=>{z()});return e.observe(g.current),()=>e.disconnect()},[u]),l.useEffect(()=>{u||Q(-1)},[u]);const an=e=>{if(W){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,y,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,y,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),y>=0&&o[y]&&!o[y].disable&&q(o[y].label,o[y].value);break}case"Escape":C(!1);break}}},M=d==="lg"||d==="xl"?20:16,Cn=gn&&!N?n.jsx("button",{type:"button",className:`sa-input-dropdown-clear${rn?"":" sa-input-dropdown-clear-hidden"}`,"aria-label":"Clear selection","aria-hidden":!rn,tabIndex:-1,onClick:mn,onMouseDown:e=>e.preventDefault(),children:n.jsx(hn,{width:M,height:M})}):null,zn=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(R,{onClick:b=>{b.stopPropagation(),q(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:yn,onChange:e=>{const a=e.target.value;$(a),B==null||B(a),!u&&W&&C(!0)},onFocus:()=>{!N&&W&&C(!0)},onBlur:()=>{r||setTimeout(()=>C(!1),150)},onKeyDown:an,placeholder:c.length===0||r?L:void 0,disabled:N})]}):null,Y=n.jsx(cn,{handleChangePosition:z,children:n.jsxs("div",{className:["sa-input-dropdown-container",P,`sa-input-dropdown-size-${d}`,w?"trigger-input":"",u?"active":"",xn?"error":"",N?"disable":""].filter(Boolean).join(" "),ref:X,onClick:w?void 0:Nn,onKeyDown:w?void 0:an,tabIndex:w?void 0:0,onBlur:w?void 0:I,onFocus:w?void 0:F,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[h?l.cloneElement(h,{width:M,style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0}}):null,n.jsx("div",{className:"sa-input-dropdown-container-preview-item",children:w?zn:En()}),Cn,!bn&&n.jsx("div",{className:"sa-input-dropdown-chevron",children:u?n.jsx(un,{width:M}):n.jsx(fn,{width:M})})]}),W&&n.jsx(pn,{dropdownLists:o,handleChangeValue:q,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:y,footer:T,groupLabel:s,onSelectAll:A})]})});return K?vn==="outside-left"?n.jsxs("div",{className:`${J} sa-select-field-left`,children:[n.jsxs("div",{className:"sa-select-field-left-label",children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})]}):n.jsxs("div",{className:J,children:[n.jsxs("div",{className:"sa-select-field-label-row",children:[n.jsx("span",{className:"sa-select-field-label-text",children:K}),en&&n.jsx("span",{className:"sa-select-field-optional-badge",children:"Optional"}),nn&&n.jsx("span",{className:"sa-select-field-required",children:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]}):n.jsxs("div",{className:J,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!f&&n.jsx("p",{className:"sa-select-field-helper",children:D}),f&&n.jsx("p",{className:"sa-select-field-error-msg",children:f})]})},V=(o,p,i)=>{const t=o.length;let d=p+i;for(;d>=0&&d<t;){if(!o[d].disable)return d;d+=i}if(i===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},hn=o=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o,children:[n.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"currentColor",opacity:"0.2"}),n.jsx("path",{d:"M5.5 5.5l5 5M10.5 5.5l-5 5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})]}),R=o=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",style:{flexShrink:0,cursor:"pointer"},...o,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),fn=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),un=({width:o=16})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:o,height:o,viewBox:"0 0 16 16",fill:"none",style:{color:"var(--sa-dropdown-placeholder)",flexShrink:0},children:n.jsx("path",{d:"M4 10L8 6L12 10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})});x.Dropdown=wn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
@@ -44,6 +44,8 @@ export interface IDropdown {
44
44
  triggerInput?: boolean;
45
45
  clearOnSelect?: boolean;
46
46
  hideChevronIcon?: boolean;
47
+ clearable?: boolean;
48
+ onClear?: () => void;
47
49
  label?: React.ReactNode;
48
50
  labelPosition?: DropdownLabelPosition;
49
51
  required?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",