@starasia/dropdown 5.5.1 → 5.5.3

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,5 +1,5 @@
1
1
  import { jsxs as l, jsx as n, Fragment as dn } from "react/jsx-runtime";
2
- import ln, { useState as W, useRef as M, useEffect as v, forwardRef as yn } from "react";
2
+ import ln, { useState as M, useRef as S, useEffect as v, forwardRef as yn } from "react";
3
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;
@@ -43,7 +43,6 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
43
43
  --borderRadius: var(--sa-dropdown-radius);
44
44
  --paddingInline: 8px;
45
45
  --paddingBlock: 2px;
46
- --iconSize: 14px;
47
46
  --iconMarginTop: 4px;
48
47
  }
49
48
  .sa-input-dropdown-size-sm {
@@ -52,7 +51,6 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
52
51
  --borderRadius: var(--sa-dropdown-radius);
53
52
  --paddingInline: 12px;
54
53
  --paddingBlock: 4px;
55
- --iconSize: 16px;
56
54
  --iconMarginTop: 4px;
57
55
  }
58
56
  .sa-input-dropdown-size-md {
@@ -61,7 +59,6 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
61
59
  --borderRadius: var(--sa-dropdown-radius);
62
60
  --paddingInline: 12px;
63
61
  --paddingBlock: 8px;
64
- --iconSize: 16px;
65
62
  --iconMarginTop: 4px;
66
63
  }
67
64
  .sa-input-dropdown-size-lg {
@@ -70,7 +67,6 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
70
67
  --borderRadius: var(--sa-dropdown-radius);
71
68
  --paddingInline: 12px;
72
69
  --paddingBlock: 12px;
73
- --iconSize: 20px;
74
70
  --iconMarginTop: 2px;
75
71
  }
76
72
  .sa-input-dropdown-size-xl {
@@ -79,7 +75,6 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
79
75
  --borderRadius: var(--sa-dropdown-radius);
80
76
  --paddingInline: 16px;
81
77
  --paddingBlock: 16px;
82
- --iconSize: 20px;
83
78
  --iconMarginTop: 2px;
84
79
  }
85
80
 
@@ -552,7 +547,7 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
552
547
 
553
548
  `;
554
549
  function En(o) {
555
- const [p, s] = W(o), d = M(null), i = (r) => {
550
+ const [p, s] = M(o), d = S(null), i = (r) => {
556
551
  d.current && !d.current.contains(r.target) && s(!1);
557
552
  };
558
553
  return v(() => (document.addEventListener("click", i, !0), () => {
@@ -627,10 +622,10 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
627
622
  groupLabel: T,
628
623
  onSelectAll: N
629
624
  }, U) => {
630
- const j = M([]);
625
+ const A = S([]);
631
626
  v(() => {
632
627
  var t;
633
- y >= 0 && j.current[y] && ((t = j.current[y]) == null || t.scrollIntoView({ block: "nearest" }));
628
+ y >= 0 && A.current[y] && ((t = A.current[y]) == null || t.scrollIntoView({ block: "nearest" }));
634
629
  }, [y]);
635
630
  const $ = d && !i ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
636
631
  /* @__PURE__ */ n(Cn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
@@ -672,8 +667,8 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
672
667
  }
673
668
  )
674
669
  ] }),
675
- p.map((t, A) => {
676
- const H = !!(m != null && m.find((P) => P.value === t.value)), w = !!t.description;
670
+ p.map((t, P) => {
671
+ const H = !!(m != null && m.find((I) => I.value === t.value)), w = !!t.description;
677
672
  return /* @__PURE__ */ l(
678
673
  "div",
679
674
  {
@@ -681,11 +676,11 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
681
676
  "sa-input-dropdown-item",
682
677
  w ? "has-description" : "",
683
678
  H ? "active" : "",
684
- A === y ? "highlight" : "",
679
+ P === y ? "highlight" : "",
685
680
  t.disable ? "sa-input-dropdown-item-disable" : ""
686
681
  ].filter(Boolean).join(" "),
687
- ref: (P) => {
688
- j.current[A] = P;
682
+ ref: (I) => {
683
+ A.current[P] = I;
689
684
  },
690
685
  onClick: () => u(t.label, t.value),
691
686
  children: [
@@ -715,7 +710,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
715
710
  ] })
716
711
  ]
717
712
  },
718
- A
713
+ P
719
714
  );
720
715
  })
721
716
  ]
@@ -731,7 +726,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
731
726
  children: o,
732
727
  handleChangePosition: p
733
728
  }) => {
734
- const s = M(null);
729
+ const s = S(null);
735
730
  v(() => {
736
731
  var m;
737
732
  const i = () => {
@@ -752,13 +747,13 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
752
747
  const d = (i) => i && (i.scrollHeight > i.clientHeight || i.scrollWidth > i.clientWidth);
753
748
  return /* @__PURE__ */ n("div", { ref: s, children: o });
754
749
  }, an = "sa-input-dropdown-styles", Bn = (o) => {
755
- if (!document.getElementById(an)) {
750
+ if (!(typeof document > "u") && !document.getElementById(an)) {
756
751
  const p = document.createElement("style");
757
752
  p.id = an, p.textContent = o, document.head.appendChild(p);
758
753
  }
759
754
  };
760
755
  Bn(Nn);
761
- const In = ({
756
+ const On = ({
762
757
  dropdownLists: o,
763
758
  onChange: p,
764
759
  defaultValue: s,
@@ -774,13 +769,13 @@ const In = ({
774
769
  onFocus: T,
775
770
  disable: N,
776
771
  searchValue: U,
777
- variant: j = "outline",
772
+ variant: A = "outline",
778
773
  footer: $,
779
774
  groupLabel: t,
780
- onSelectAll: A,
775
+ onSelectAll: P,
781
776
  fullWidth: H = !0,
782
777
  triggerInput: w = !1,
783
- clearOnSelect: P = !1,
778
+ clearOnSelect: I = !1,
784
779
  hideChevronIcon: pn = !1,
785
780
  clearable: cn = !1,
786
781
  onClear: K,
@@ -797,38 +792,38 @@ const In = ({
797
792
  "sa-select-field",
798
793
  `sa-select-field-size-${i}`,
799
794
  H ? "sa-select-field-fullwidth" : ""
800
- ].filter(Boolean).join(" "), E = d !== void 0, Q = M(), un = y || !!h, [c, S] = W(
795
+ ].filter(Boolean).join(" "), E = d !== void 0, Q = S(), un = y || !!h, [c, j] = M(
801
796
  E ? d || [] : s || []
802
- ), [hn, en] = W(""), [k, X] = W(-1), [fn, q] = W(
797
+ ), [hn, en] = M(""), [k, X] = M(-1), [fn, q] = M(
803
798
  () => {
804
799
  var e, a;
805
800
  return !r && (d != null && d.length || s != null && s.length) ? ((e = d == null ? void 0 : d[0]) == null ? void 0 : e.label) ?? ((a = s == null ? void 0 : s[0]) == null ? void 0 : a.label) ?? "" : "";
806
801
  }
807
- ), g = M(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), I = o !== void 0, on = c.length > 0, bn = (e) => {
802
+ ), g = S(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), O = o !== void 0, on = c.length > 0, bn = (e) => {
808
803
  e.stopPropagation();
809
804
  const a = [];
810
- E || S(a), p(a), w && q(""), K == null || K();
805
+ E || j(a), p(a), w && q(""), K == null || K();
811
806
  }, gn = () => {
812
- I && C((e) => !e);
807
+ O && C((e) => !e);
813
808
  }, G = (e, a) => {
814
809
  if (r) {
815
810
  if (c == null ? void 0 : c.find((x) => x.value === a)) {
816
811
  const x = c.filter((kn) => kn.value !== a);
817
- E || S(x), p(x);
812
+ E || j(x), p(x);
818
813
  } else {
819
814
  const x = [...c, { label: e, value: a }];
820
- E || S(x), p(x);
815
+ E || j(x), p(x);
821
816
  }
822
817
  w && q("");
823
818
  } else {
824
819
  const b = [{ label: e, value: a }];
825
- E || S(b), p(b), w && q(P ? "" : e), C(!1);
820
+ E || j(b), p(b), w && q(I ? "" : e), C(!1);
826
821
  }
827
822
  };
828
823
  v(() => {
829
- E && S(d || []);
824
+ E && j(d || []);
830
825
  }, [d]), v(() => {
831
- E || JSON.stringify(Q.current) === JSON.stringify(s) || (Q.current = s, S(Q.current || []));
826
+ E || JSON.stringify(Q.current) === JSON.stringify(s) || (Q.current = s, j(Q.current || []));
832
827
  }, [s]);
833
828
  const xn = () => c.length ? r ? c == null ? void 0 : c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
834
829
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
@@ -861,7 +856,7 @@ const In = ({
861
856
  f || X(-1);
862
857
  }, [f]);
863
858
  const rn = (e) => {
864
- if (I) {
859
+ if (O) {
865
860
  if (!f) {
866
861
  (e.key === "ArrowDown" || e.key === "Enter") && (e.preventDefault(), C(!0));
867
862
  return;
@@ -891,7 +886,7 @@ const In = ({
891
886
  break;
892
887
  }
893
888
  }
894
- }, O = i === "lg" || i === "xl" ? 20 : i === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
889
+ }, W = i === "lg" || i === "xl" ? 20 : i === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
895
890
  "button",
896
891
  {
897
892
  type: "button",
@@ -901,7 +896,7 @@ const In = ({
901
896
  tabIndex: -1,
902
897
  onClick: bn,
903
898
  onMouseDown: (e) => e.preventDefault(),
904
- children: /* @__PURE__ */ n(Dn, { width: O, height: O })
899
+ children: /* @__PURE__ */ n(Dn, { width: W, height: W })
905
900
  }
906
901
  ) : null, mn = w ? /* @__PURE__ */ l(dn, { children: [
907
902
  r && c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
@@ -922,10 +917,10 @@ const In = ({
922
917
  value: fn,
923
918
  onChange: (e) => {
924
919
  const a = e.target.value;
925
- q(a), L == null || L(a), !f && I && C(!0);
920
+ q(a), L == null || L(a), !f && O && C(!0);
926
921
  },
927
922
  onFocus: () => {
928
- !N && I && C(!0);
923
+ !N && O && C(!0);
929
924
  },
930
925
  onBlur: () => {
931
926
  r || setTimeout(() => C(!1), 150);
@@ -940,7 +935,7 @@ const In = ({
940
935
  {
941
936
  className: [
942
937
  "sa-input-dropdown-container",
943
- j,
938
+ A,
944
939
  `sa-input-dropdown-size-${i}`,
945
940
  w ? "trigger-input" : "",
946
941
  f ? "active" : "",
@@ -956,14 +951,14 @@ const In = ({
956
951
  children: [
957
952
  /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-container", children: [
958
953
  u ? ln.cloneElement(u, {
959
- width: O,
954
+ width: W,
960
955
  style: { color: "var(--sa-dropdown-placeholder)", flexShrink: 0 }
961
956
  }) : null,
962
957
  /* @__PURE__ */ n("div", { className: "sa-input-dropdown-container-preview-item", children: w ? mn : xn() }),
963
958
  vn,
964
- !pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(jn, { width: O }) : /* @__PURE__ */ n(Sn, { width: O }) })
959
+ !pn && /* @__PURE__ */ n("div", { className: "sa-input-dropdown-chevron", children: f ? /* @__PURE__ */ n(An, { width: W }) : /* @__PURE__ */ n(jn, { width: W }) })
965
960
  ] }),
966
- I && /* @__PURE__ */ n(
961
+ O && /* @__PURE__ */ n(
967
962
  Rn,
968
963
  {
969
964
  dropdownLists: o,
@@ -980,7 +975,7 @@ const In = ({
980
975
  highlightedIndex: k,
981
976
  footer: $,
982
977
  groupLabel: t,
983
- onSelectAll: A
978
+ onSelectAll: P
984
979
  }
985
980
  )
986
981
  ]
@@ -1057,7 +1052,7 @@ const In = ({
1057
1052
  }
1058
1053
  )
1059
1054
  }
1060
- ), Sn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1055
+ ), jn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1061
1056
  "svg",
1062
1057
  {
1063
1058
  xmlns: "http://www.w3.org/2000/svg",
@@ -1077,7 +1072,7 @@ const In = ({
1077
1072
  }
1078
1073
  )
1079
1074
  }
1080
- ), jn = ({ width: o = 16 }) => /* @__PURE__ */ n(
1075
+ ), An = ({ width: o = 16 }) => /* @__PURE__ */ n(
1081
1076
  "svg",
1082
1077
  {
1083
1078
  xmlns: "http://www.w3.org/2000/svg",
@@ -1099,5 +1094,5 @@ const In = ({
1099
1094
  }
1100
1095
  );
1101
1096
  export {
1102
- In as Dropdown
1097
+ On as Dropdown
1103
1098
  };
@@ -41,7 +41,6 @@
41
41
  --borderRadius: var(--sa-dropdown-radius);
42
42
  --paddingInline: 8px;
43
43
  --paddingBlock: 2px;
44
- --iconSize: 14px;
45
44
  --iconMarginTop: 4px;
46
45
  }
47
46
  .sa-input-dropdown-size-sm {
@@ -50,7 +49,6 @@
50
49
  --borderRadius: var(--sa-dropdown-radius);
51
50
  --paddingInline: 12px;
52
51
  --paddingBlock: 4px;
53
- --iconSize: 16px;
54
52
  --iconMarginTop: 4px;
55
53
  }
56
54
  .sa-input-dropdown-size-md {
@@ -59,7 +57,6 @@
59
57
  --borderRadius: var(--sa-dropdown-radius);
60
58
  --paddingInline: 12px;
61
59
  --paddingBlock: 8px;
62
- --iconSize: 16px;
63
60
  --iconMarginTop: 4px;
64
61
  }
65
62
  .sa-input-dropdown-size-lg {
@@ -68,7 +65,6 @@
68
65
  --borderRadius: var(--sa-dropdown-radius);
69
66
  --paddingInline: 12px;
70
67
  --paddingBlock: 12px;
71
- --iconSize: 20px;
72
68
  --iconMarginTop: 2px;
73
69
  }
74
70
  .sa-input-dropdown-size-xl {
@@ -77,7 +73,6 @@
77
73
  --borderRadius: var(--sa-dropdown-radius);
78
74
  --paddingInline: 16px;
79
75
  --paddingBlock: 16px;
80
- --iconSize: 20px;
81
76
  --iconMarginTop: 2px;
82
77
  }
83
78
 
@@ -548,4 +543,4 @@
548
543
  display: none;
549
544
  }
550
545
 
551
- `;function dn(o){const[p,d]=l.useState(o),t=l.useRef(null),s=r=>{t.current&&!t.current.contains(r.target)&&d(!1)};return l.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:t,isComponentVisible:p,setIsComponentVisible:d}}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:d,searchAble:t,hideSearch:s,onSearch:r,value:k,handleChangeValue:h,multiSelect:L,searchValue:B,highlightedIndex:y,footer:W,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var i;y>=0&&P.current[y]&&((i=P.current[y])==null||i.scrollIntoView({block:"nearest"}))},[y]);const T=t&&!s?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:i=>{r&&r(i.target.value)},value:B,autoFocus:!0,placeholder:"Search..."})]}):null;return n.jsx(n.Fragment,{children:d?n.jsxs("div",{className:"sa-input-dropdown-lists-container",onClick:i=>i.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:i=>{i.stopPropagation(),N()},children:"Select all"})]}),p.map((i,A)=>{const $=!!(k!=null&&k.find(O=>O.value===i.value)),w=!!i.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",$?"active":"",A===y?"highlight":"",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>h(i.label,i.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:$&&n.jsx(ln,{width:16})}),i.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(i.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.label}),i.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",i.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:i.description})]})]},A)})]}),o==="top"&&T,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:i=>i.stopPropagation(),children:W})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const d=l.useRef(null);l.useEffect(()=>{var k;const s=()=>{if(d.current){let h=d.current.parentElement;for(;h&&!t(h);)h=h.parentElement;h&&p()}};let r=(k=d.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",s),s(),()=>{r&&r.removeEventListener("scroll",s)}},[]);const t=s=>s&&(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);return n.jsx("div",{ref:d,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:d,value:t,size:s="sm",multiSelect:r,searchAble:k,iconLeft:h,placeholder:L,onSearch:B,error:y,onBlur:W,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:i,onSelectAll:A,fullWidth:$=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:S,helperText:D,errorText:f})=>{const J=["sa-select-field",`sa-select-field-size-${s}`,$?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),vn=y||!!f,[c,j]=l.useState(E?t||[]:d||[]),[kn,on]=l.useState(""),[m,Q]=l.useState(-1),[mn,q]=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:X,setIsComponentVisible:C}=dn(!1),I=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&q(""),U==null||U()},Nn=()=>{I&&C(e=>!e)},H=(e,a)=>{if(r){if(c==null?void 0:c.find(x=>x.value===a)){const x=c.filter(Ln=>Ln.value!==a);E||j(x),p(x)}else{const x=[...c,{label:e,value:a}];E||j(x),p(x)}w&&q("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&q(O?"":e),C(!1)}};l.useEffect(()=>{E&&j(t||[])},[t]),l.useEffect(()=>{E||JSON.stringify(Z.current)===JSON.stringify(d)||(Z.current=d,j(Z.current||[]))},[d]);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(),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:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),x=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,x>=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(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,m,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,m,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&H(o[m].label,o[m].value);break}case"Escape":C(!1);break}}},M=s==="lg"||s==="xl"?20:s==="xs"?14: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:yn,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(),H(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const a=e.target.value;q(a),B==null||B(a),!u&&I&&C(!0)},onFocus:()=>{!N&&I&&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-${s}`,w?"trigger-input":"",u?"active":"",vn?"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:W,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})})]}),I&&n.jsx(pn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:m,footer:T,groupLabel:i,onSelectAll:A})]})});return K?xn==="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,d)=>{const t=o.length;let s=p+d;for(;s>=0&&s<t;){if(!o[s].disable)return s;s+=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},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"})});v.Dropdown=wn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
546
+ `;function dn(o){const[p,i]=l.useState(o),t=l.useRef(null),s=r=>{t.current&&!t.current.contains(r.target)&&i(!1)};return l.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!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:s,onSearch:r,value:k,handleChangeValue:f,multiSelect:L,searchValue:B,highlightedIndex:y,footer:W,groupLabel:F,onSelectAll:N},G)=>{const P=l.useRef([]);l.useEffect(()=>{var d;y>=0&&P.current[y]&&((d=P.current[y])==null||d.scrollIntoView({block:"nearest"}))},[y]);const T=t&&!s?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:d=>{r&&r(d.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:d=>d.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:d=>{d.stopPropagation(),N()},children:"Select all"})]}),p.map((d,A)=>{const $=!!(k!=null&&k.find(O=>O.value===d.value)),w=!!d.description;return n.jsxs("div",{className:["sa-input-dropdown-item",w?"has-description":"",$?"active":"",A===y?"highlight":"",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),ref:O=>{P.current[A]=O},onClick:()=>f(d.label,d.value),children:[L&&n.jsx("div",{className:"sa-input-dropdown-item-check",children:$&&n.jsx(ln,{width:16})}),d.icon&&n.jsx("div",{style:{flexShrink:0,display:"flex"},children:l.cloneElement(d.icon,{width:16})}),n.jsxs("div",{style:{minWidth:0,flex:1},children:[n.jsx("p",{className:["sa-input-dropdown-item-text",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:d.label}),d.description&&n.jsx("p",{className:["sa-input-dropdown-item-text-description",d.disable?"sa-input-dropdown-item-disable":""].filter(Boolean).join(" "),children:d.description})]})]},A)})]}),o==="top"&&T,W&&n.jsx("div",{className:"sa-input-dropdown-footer",onClick:d=>d.stopPropagation(),children:W})]}):null})}),cn=({children:o,handleChangePosition:p})=>{const i=l.useRef(null);l.useEffect(()=>{var k;const s=()=>{if(i.current){let f=i.current.parentElement;for(;f&&!t(f);)f=f.parentElement;f&&p()}};let r=(k=i.current)==null?void 0:k.parentElement;for(;r&&!t(r);)r=r.parentElement;return r&&r.addEventListener("scroll",s),s(),()=>{r&&r.removeEventListener("scroll",s)}},[]);const t=s=>s&&(s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth);return n.jsx("div",{ref:i,children:o})},_="sa-input-dropdown-styles";(o=>{if(!(typeof document>"u")&&!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:s="sm",multiSelect:r,searchAble:k,iconLeft:f,placeholder:L,onSearch:B,error:y,onBlur:W,onFocus:F,disable:N,searchValue:G,variant:P="outline",footer:T,groupLabel:d,onSelectAll:A,fullWidth:$=!0,triggerInput:w=!1,clearOnSelect:O=!1,hideChevronIcon:bn=!1,clearable:gn=!1,onClear:U,label:K,labelPosition:xn="outside-top",required:nn,optional:en,description:D,helperText:S,errorText:h})=>{const J=["sa-select-field",`sa-select-field-size-${s}`,$?"sa-select-field-fullwidth":""].filter(Boolean).join(" "),E=t!==void 0,Z=l.useRef(),vn=y||!!h,[c,j]=l.useState(E?t||[]:i||[]),[kn,on]=l.useState(""),[m,Q]=l.useState(-1),[mn,q]=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),I=o!==void 0,rn=c.length>0,yn=e=>{e.stopPropagation();const a=[];E||j(a),p(a),w&&q(""),U==null||U()},Nn=()=>{I&&C(e=>!e)},H=(e,a)=>{if(r){if(c==null?void 0:c.find(x=>x.value===a)){const x=c.filter(Ln=>Ln.value!==a);E||j(x),p(x)}else{const x=[...c,{label:e,value:a}];E||j(x),p(x)}w&&q("")}else{const b=[{label:e,value:a}];E||j(b),p(b),w&&q(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(),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:L}),z=()=>{if(X.current&&g.current){const e=window.innerHeight,a=X.current.getBoundingClientRect(),b=g.current.getBoundingClientRect(),x=a.bottom+b.height;g.current.style.left=`${a.left}px`,g.current.style.width=`${a.width}px`,x>=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(I){if(!u){(e.key==="ArrowDown"||e.key==="Enter")&&(e.preventDefault(),C(!0));return}switch(e.key){case"ArrowDown":{e.preventDefault();const a=V(o,m,1);a!==-1&&Q(a);break}case"ArrowUp":{e.preventDefault();const a=V(o,m,-1);a!==-1&&Q(a);break}case"Enter":{e.preventDefault(),m>=0&&o[m]&&!o[m].disable&&H(o[m].label,o[m].value);break}case"Escape":C(!1);break}}},M=s==="lg"||s==="xl"?20:s==="xs"?14: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:yn,onMouseDown:e=>e.preventDefault(),children:n.jsx(fn,{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(),H(e.label,e.value)}})]},a)),n.jsx("input",{className:"sa-input-dropdown-trigger-input",value:mn,onChange:e=>{const a=e.target.value;q(a),B==null||B(a),!u&&I&&C(!0)},onFocus:()=>{!N&&I&&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-${s}`,w?"trigger-input":"",u?"active":"",vn?"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:W,onFocus:w?void 0:F,children:[n.jsxs("div",{className:"sa-input-dropdown-preview-container",children:[f?l.cloneElement(f,{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(hn,{width:M})})]}),I&&n.jsx(pn,{dropdownLists:o,handleChangeValue:H,isComponentVisible:u,positionDropdown:kn,searchAble:!!k,hideSearch:w,value:c,onSearch:B,ref:g,multiSelect:r,searchValue:G,highlightedIndex:m,footer:T,groupLabel:d,onSelectAll:A})]})});return K?xn==="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:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D})]}),n.jsxs("div",{className:"sa-select-field-input-wrap",children:[Y,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: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:"*"})]}),D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),Y,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:J,children:[D&&n.jsx("p",{className:"sa-select-field-helper-top",children:D}),Y,S&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:S}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},V=(o,p,i)=>{const t=o.length;let s=p+i;for(;s>=0&&s<t;){if(!o[s].disable)return s;s+=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},fn=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"})}),hn=({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"})});v.Dropdown=wn,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
@@ -31,6 +31,11 @@ export interface IDropdown {
31
31
  iconLeft?: React.ReactElement<IconPropsDropdown>;
32
32
  placeholder?: string;
33
33
  onSearch?: (e: string) => void;
34
+ /**
35
+ * @deprecated Panel placement is now computed automatically (it flips
36
+ * between top/bottom based on available viewport space). This prop is
37
+ * ignored and has no effect. It will be removed in a future major version.
38
+ */
34
39
  position?: "top" | "bottom";
35
40
  onBlur?: (e: React.FocusEvent<HTMLDivElement, Element>) => void;
36
41
  onFocus?: (e: React.FocusEvent<HTMLDivElement, Element>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.5.1",
3
+ "version": "5.5.3",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",