@starasia/dropdown 5.5.1 → 5.5.2

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.
@@ -552,11 +552,11 @@ const Nn = `@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@3
552
552
 
553
553
  `;
554
554
  function En(o) {
555
- const [p, s] = W(o), d = M(null), i = (r) => {
555
+ const [p, s] = W(o), d = M(null), a = (r) => {
556
556
  d.current && !d.current.contains(r.target) && s(!1);
557
557
  };
558
- return v(() => (document.addEventListener("click", i, !0), () => {
559
- document.removeEventListener("click", i, !0);
558
+ return v(() => (document.addEventListener("click", a, !0), () => {
559
+ document.removeEventListener("click", a, !0);
560
560
  }), []), { ref: d, isComponentVisible: p, setIsComponentVisible: s };
561
561
  }
562
562
  const Cn = ({ ...o }) => /* @__PURE__ */ l(
@@ -616,7 +616,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
616
616
  dropdownLists: p,
617
617
  isComponentVisible: s,
618
618
  searchAble: d,
619
- hideSearch: i,
619
+ hideSearch: a,
620
620
  onSearch: r,
621
621
  value: m,
622
622
  handleChangeValue: u,
@@ -632,7 +632,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
632
632
  var t;
633
633
  y >= 0 && j.current[y] && ((t = j.current[y]) == null || t.scrollIntoView({ block: "nearest" }));
634
634
  }, [y]);
635
- const $ = d && !i ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
635
+ const $ = d && !a ? /* @__PURE__ */ l("div", { className: "sa-input-dropdown-container-dropdown-search", children: [
636
636
  /* @__PURE__ */ n(Cn, { strokeWidth: 2, width: 16, style: { flexShrink: 0, color: "var(--sa-dropdown-placeholder-subtle)" } }),
637
637
  /* @__PURE__ */ n(
638
638
  "input",
@@ -734,7 +734,7 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
734
734
  const s = M(null);
735
735
  v(() => {
736
736
  var m;
737
- const i = () => {
737
+ const a = () => {
738
738
  if (s.current) {
739
739
  let u = s.current.parentElement;
740
740
  for (; u && !d(u); )
@@ -745,14 +745,14 @@ const Cn = ({ ...o }) => /* @__PURE__ */ l(
745
745
  let r = (m = s.current) == null ? void 0 : m.parentElement;
746
746
  for (; r && !d(r); )
747
747
  r = r.parentElement;
748
- return r && r.addEventListener("scroll", i), i(), () => {
749
- r && r.removeEventListener("scroll", i);
748
+ return r && r.addEventListener("scroll", a), a(), () => {
749
+ r && r.removeEventListener("scroll", a);
750
750
  };
751
751
  }, []);
752
- const d = (i) => i && (i.scrollHeight > i.clientHeight || i.scrollWidth > i.clientWidth);
752
+ const d = (a) => a && (a.scrollHeight > a.clientHeight || a.scrollWidth > a.clientWidth);
753
753
  return /* @__PURE__ */ n("div", { ref: s, children: o });
754
754
  }, an = "sa-input-dropdown-styles", Bn = (o) => {
755
- if (!document.getElementById(an)) {
755
+ if (!(typeof document > "u") && !document.getElementById(an)) {
756
756
  const p = document.createElement("style");
757
757
  p.id = an, p.textContent = o, document.head.appendChild(p);
758
758
  }
@@ -763,7 +763,7 @@ const In = ({
763
763
  onChange: p,
764
764
  defaultValue: s,
765
765
  value: d,
766
- size: i = "sm",
766
+ size: a = "sm",
767
767
  multiSelect: r,
768
768
  searchAble: m,
769
769
  iconLeft: u,
@@ -795,33 +795,33 @@ const In = ({
795
795
  }) => {
796
796
  const Z = [
797
797
  "sa-select-field",
798
- `sa-select-field-size-${i}`,
798
+ `sa-select-field-size-${a}`,
799
799
  H ? "sa-select-field-fullwidth" : ""
800
800
  ].filter(Boolean).join(" "), E = d !== void 0, Q = M(), un = y || !!h, [c, S] = W(
801
801
  E ? d || [] : s || []
802
802
  ), [hn, en] = W(""), [k, X] = W(-1), [fn, q] = W(
803
803
  () => {
804
- var e, a;
805
- 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) ?? "" : "";
804
+ var e, i;
805
+ return !r && (d != null && d.length || s != null && s.length) ? ((e = d == null ? void 0 : d[0]) == null ? void 0 : e.label) ?? ((i = s == null ? void 0 : s[0]) == null ? void 0 : i.label) ?? "" : "";
806
806
  }
807
807
  ), g = M(null), { isComponentVisible: f, ref: Y, setIsComponentVisible: C } = En(!1), I = o !== void 0, on = c.length > 0, bn = (e) => {
808
808
  e.stopPropagation();
809
- const a = [];
810
- E || S(a), p(a), w && q(""), K == null || K();
809
+ const i = [];
810
+ E || S(i), p(i), w && q(""), K == null || K();
811
811
  }, gn = () => {
812
812
  I && C((e) => !e);
813
- }, G = (e, a) => {
813
+ }, G = (e, i) => {
814
814
  if (r) {
815
- if (c == null ? void 0 : c.find((x) => x.value === a)) {
816
- const x = c.filter((kn) => kn.value !== a);
815
+ if (c == null ? void 0 : c.find((x) => x.value === i)) {
816
+ const x = c.filter((kn) => kn.value !== i);
817
817
  E || S(x), p(x);
818
818
  } else {
819
- const x = [...c, { label: e, value: a }];
819
+ const x = [...c, { label: e, value: i }];
820
820
  E || S(x), p(x);
821
821
  }
822
822
  w && q("");
823
823
  } else {
824
- const b = [{ label: e, value: a }];
824
+ const b = [{ label: e, value: i }];
825
825
  E || S(b), p(b), w && q(P ? "" : e), C(!1);
826
826
  }
827
827
  };
@@ -830,7 +830,7 @@ const In = ({
830
830
  }, [d]), v(() => {
831
831
  E || JSON.stringify(Q.current) === JSON.stringify(s) || (Q.current = s, S(Q.current || []));
832
832
  }, [s]);
833
- const xn = () => c.length ? r ? c == null ? void 0 : c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
833
+ const xn = () => c.length ? r ? c == null ? void 0 : c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
834
834
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
835
835
  /* @__PURE__ */ n(
836
836
  sn,
@@ -840,10 +840,10 @@ const In = ({
840
840
  }
841
841
  }
842
842
  )
843
- ] }, 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 = () => {
843
+ ] }, 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: R }), z = () => {
844
844
  if (Y.current && g.current) {
845
- const e = window.innerHeight, a = Y.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), x = a.bottom + b.height;
846
- 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`, en("top")) : (g.current.style.top = `${a.top + a.height + 4}px`, en("bottom"));
845
+ const e = window.innerHeight, i = Y.current.getBoundingClientRect(), b = g.current.getBoundingClientRect(), x = i.bottom + b.height;
846
+ g.current.style.left = `${i.left}px`, g.current.style.width = `${i.width}px`, x >= e - 10 ? (g.current.style.top = `${i.top - b.height - 5}px`, en("top")) : (g.current.style.top = `${i.top + i.height + 4}px`, en("bottom"));
847
847
  }
848
848
  };
849
849
  v(() => (window.addEventListener("scroll", z), window.addEventListener("resize", z), () => {
@@ -869,14 +869,14 @@ const In = ({
869
869
  switch (e.key) {
870
870
  case "ArrowDown": {
871
871
  e.preventDefault();
872
- const a = tn(o, k, 1);
873
- a !== -1 && X(a);
872
+ const i = tn(o, k, 1);
873
+ i !== -1 && X(i);
874
874
  break;
875
875
  }
876
876
  case "ArrowUp": {
877
877
  e.preventDefault();
878
- const a = tn(o, k, -1);
879
- a !== -1 && X(a);
878
+ const i = tn(o, k, -1);
879
+ i !== -1 && X(i);
880
880
  break;
881
881
  }
882
882
  case "Enter": {
@@ -891,7 +891,7 @@ const In = ({
891
891
  break;
892
892
  }
893
893
  }
894
- }, O = i === "lg" || i === "xl" ? 20 : i === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
894
+ }, O = a === "lg" || a === "xl" ? 20 : a === "xs" ? 14 : 16, vn = cn && !N ? /* @__PURE__ */ n(
895
895
  "button",
896
896
  {
897
897
  type: "button",
@@ -904,7 +904,7 @@ const In = ({
904
904
  children: /* @__PURE__ */ n(Dn, { width: O, height: O })
905
905
  }
906
906
  ) : null, mn = w ? /* @__PURE__ */ l(dn, { children: [
907
- r && c.map((e, a) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
907
+ r && c.map((e, i) => /* @__PURE__ */ l("div", { className: "sa-input-dropdown-preview-item", children: [
908
908
  /* @__PURE__ */ n("p", { style: { minWidth: "max-content" }, children: e == null ? void 0 : e.label }),
909
909
  /* @__PURE__ */ n(
910
910
  sn,
@@ -914,15 +914,15 @@ const In = ({
914
914
  }
915
915
  }
916
916
  )
917
- ] }, a)),
917
+ ] }, i)),
918
918
  /* @__PURE__ */ n(
919
919
  "input",
920
920
  {
921
921
  className: "sa-input-dropdown-trigger-input",
922
922
  value: fn,
923
923
  onChange: (e) => {
924
- const a = e.target.value;
925
- q(a), L == null || L(a), !f && I && C(!0);
924
+ const i = e.target.value;
925
+ q(i), L == null || L(i), !f && I && C(!0);
926
926
  },
927
927
  onFocus: () => {
928
928
  !N && I && C(!0);
@@ -941,7 +941,7 @@ const In = ({
941
941
  className: [
942
942
  "sa-input-dropdown-container",
943
943
  j,
944
- `sa-input-dropdown-size-${i}`,
944
+ `sa-input-dropdown-size-${a}`,
945
945
  w ? "trigger-input" : "",
946
946
  f ? "active" : "",
947
947
  un ? "error" : "",
@@ -1018,11 +1018,11 @@ const In = ({
1018
1018
  ] });
1019
1019
  }, tn = (o, p, s) => {
1020
1020
  const d = o.length;
1021
- let i = p + s;
1022
- for (; i >= 0 && i < d; ) {
1023
- if (!o[i].disable)
1024
- return i;
1025
- i += s;
1021
+ let a = p + s;
1022
+ for (; a >= 0 && a < d; ) {
1023
+ if (!o[a].disable)
1024
+ return a;
1025
+ a += s;
1026
1026
  }
1027
1027
  if (s === 1) {
1028
1028
  for (let r = 0; r < d; r++)
@@ -548,4 +548,4 @@
548
548
  display: none;
549
549
  }
550
550
 
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"})});
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:f,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:()=>f(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 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",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(!(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:d,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: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: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||[]: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(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: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&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),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:"*"})]}),S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]}):n.jsxs("div",{className:J,children:[S&&n.jsx("p",{className:"sa-select-field-helper-top",children:S}),Y,D&&!h&&n.jsx("p",{className:"sa-select-field-helper",children:D}),h&&n.jsx("p",{className:"sa-select-field-error-msg",children:h})]})},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},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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",