@starasia/dropdown 1.0.2 → 1.0.4

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,35 +1,4 @@
1
- (function(V,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],c):(V=typeof globalThis<"u"?globalThis:V||self,c(V.Dropdown={},V.React))})(this,function(V,c){"use strict";var tr={exports:{}},G={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var hr;function Yr(){if(hr)return G;hr=1;var p=c,f=Symbol.for("react.element"),m=Symbol.for("react.fragment"),E=Object.prototype.hasOwnProperty,v=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,w={key:!0,ref:!0,__self:!0,__source:!0};function I(j,b,S){var _,W={},R=null,N=null;S!==void 0&&(R=""+S),b.key!==void 0&&(R=""+b.key),b.ref!==void 0&&(N=b.ref);for(_ in b)E.call(b,_)&&!w.hasOwnProperty(_)&&(W[_]=b[_]);if(j&&j.defaultProps)for(_ in b=j.defaultProps,b)W[_]===void 0&&(W[_]=b[_]);return{$$typeof:f,type:j,key:R,ref:N,props:W,_owner:v.current}}return G.Fragment=m,G.jsx=I,G.jsxs=I,G}var X={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var wr;function Mr(){return wr||(wr=1,process.env.NODE_ENV!=="production"&&function(){var p=c,f=Symbol.for("react.element"),m=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),I=Symbol.for("react.provider"),j=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),N=Symbol.for("react.offscreen"),L=Symbol.iterator,y="@@iterator";function o(r){if(r===null||typeof r!="object")return null;var n=L&&r[L]||r[y];return typeof n=="function"?n:null}var h=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function l(r){{for(var n=arguments.length,e=new Array(n>1?n-1:0),a=1;a<n;a++)e[a-1]=arguments[a];g("error",r,e)}}function g(r,n,e){{var a=h.ReactDebugCurrentFrame,d=a.getStackAddendum();d!==""&&(n+="%s",e=e.concat([d]));var u=e.map(function(s){return String(s)});u.unshift("Warning: "+n),Function.prototype.apply.call(console[r],console,u)}}var C=!1,B=!1,Y=!1,or=!1,$=!1,q;q=Symbol.for("react.module.reference");function M(r){return!!(typeof r=="string"||typeof r=="function"||r===E||r===w||$||r===v||r===S||r===_||or||r===N||C||B||Y||typeof r=="object"&&r!==null&&(r.$$typeof===R||r.$$typeof===W||r.$$typeof===I||r.$$typeof===j||r.$$typeof===b||r.$$typeof===q||r.getModuleId!==void 0))}function T(r,n,e){var a=r.displayName;if(a)return a;var d=n.displayName||n.name||"";return d!==""?e+"("+d+")":e}function O(r){return r.displayName||"Context"}function F(r){if(r==null)return null;if(typeof r.tag=="number"&&l("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof r=="function")return r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case E:return"Fragment";case m:return"Portal";case w:return"Profiler";case v:return"StrictMode";case S:return"Suspense";case _:return"SuspenseList"}if(typeof r=="object")switch(r.$$typeof){case j:var n=r;return O(n)+".Consumer";case I:var e=r;return O(e._context)+".Provider";case b:return T(r,r.render,"ForwardRef");case W:var a=r.displayName||null;return a!==null?a:F(r.type)||"Memo";case R:{var d=r,u=d._payload,s=d._init;try{return F(s(u))}catch{return null}}}return null}var P=Object.assign,U=0,xr,mr,yr,kr,Er,Rr,jr;function _r(){}_r.__reactDisabledLog=!0;function $r(){{if(U===0){xr=console.log,mr=console.info,yr=console.warn,kr=console.error,Er=console.group,Rr=console.groupCollapsed,jr=console.groupEnd;var r={configurable:!0,enumerable:!0,value:_r,writable:!0};Object.defineProperties(console,{info:r,log:r,warn:r,error:r,group:r,groupCollapsed:r,groupEnd:r})}U++}}function qr(){{if(U--,U===0){var r={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},r,{value:xr}),info:P({},r,{value:mr}),warn:P({},r,{value:yr}),error:P({},r,{value:kr}),group:P({},r,{value:Er}),groupCollapsed:P({},r,{value:Rr}),groupEnd:P({},r,{value:jr})})}U<0&&l("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ir=h.ReactCurrentDispatcher,sr;function rr(r,n,e){{if(sr===void 0)try{throw Error()}catch(d){var a=d.stack.trim().match(/\n( *(at )?)/);sr=a&&a[1]||""}return`
18
- `+sr+r}}var dr=!1,nr;{var rn=typeof WeakMap=="function"?WeakMap:Map;nr=new rn}function Cr(r,n){if(!r||dr)return"";{var e=nr.get(r);if(e!==void 0)return e}var a;dr=!0;var d=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=ir.current,ir.current=null,$r();try{if(n){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(A){a=A}Reflect.construct(r,[],s)}else{try{s.call()}catch(A){a=A}r.call(s.prototype)}}else{try{throw Error()}catch(A){a=A}r()}}catch(A){if(A&&a&&typeof A.stack=="string"){for(var i=A.stack.split(`
19
- `),D=a.stack.split(`
20
- `),x=i.length-1,k=D.length-1;x>=1&&k>=0&&i[x]!==D[k];)k--;for(;x>=1&&k>=0;x--,k--)if(i[x]!==D[k]){if(x!==1||k!==1)do if(x--,k--,k<0||i[x]!==D[k]){var z=`
21
- `+i[x].replace(" at new "," at ");return r.displayName&&z.includes("<anonymous>")&&(z=z.replace("<anonymous>",r.displayName)),typeof r=="function"&&nr.set(r,z),z}while(x>=1&&k>=0);break}}}finally{dr=!1,ir.current=u,qr(),Error.prepareStackTrace=d}var K=r?r.displayName||r.name:"",H=K?rr(K):"";return typeof r=="function"&&nr.set(r,H),H}function nn(r,n,e){return Cr(r,!1)}function en(r){var n=r.prototype;return!!(n&&n.isReactComponent)}function er(r,n,e){if(r==null)return"";if(typeof r=="function")return Cr(r,en(r));if(typeof r=="string")return rr(r);switch(r){case S:return rr("Suspense");case _:return rr("SuspenseList")}if(typeof r=="object")switch(r.$$typeof){case b:return nn(r.render);case W:return er(r.type,n,e);case R:{var a=r,d=a._payload,u=a._init;try{return er(u(d),n,e)}catch{}}}return""}var Z=Object.prototype.hasOwnProperty,Sr={},Tr=h.ReactDebugCurrentFrame;function ar(r){if(r){var n=r._owner,e=er(r.type,r._source,n?n.type:null);Tr.setExtraStackFrame(e)}else Tr.setExtraStackFrame(null)}function an(r,n,e,a,d){{var u=Function.call.bind(Z);for(var s in r)if(u(r,s)){var i=void 0;try{if(typeof r[s]!="function"){var D=Error((a||"React class")+": "+e+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof r[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw D.name="Invariant Violation",D}i=r[s](n,s,a,e,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(x){i=x}i&&!(i instanceof Error)&&(ar(d),l("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",a||"React class",e,s,typeof i),ar(null)),i instanceof Error&&!(i.message in Sr)&&(Sr[i.message]=!0,ar(d),l("Failed %s type: %s",e,i.message),ar(null))}}}var tn=Array.isArray;function cr(r){return tn(r)}function on(r){{var n=typeof Symbol=="function"&&Symbol.toStringTag,e=n&&r[Symbol.toStringTag]||r.constructor.name||"Object";return e}}function sn(r){try{return Or(r),!1}catch{return!0}}function Or(r){return""+r}function Pr(r){if(sn(r))return l("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",on(r)),Or(r)}var Q=h.ReactCurrentOwner,dn={key:!0,ref:!0,__self:!0,__source:!0},Ir,Dr,lr;lr={};function cn(r){if(Z.call(r,"ref")){var n=Object.getOwnPropertyDescriptor(r,"ref").get;if(n&&n.isReactWarning)return!1}return r.ref!==void 0}function ln(r){if(Z.call(r,"key")){var n=Object.getOwnPropertyDescriptor(r,"key").get;if(n&&n.isReactWarning)return!1}return r.key!==void 0}function un(r,n){if(typeof r.ref=="string"&&Q.current&&n&&Q.current.stateNode!==n){var e=F(Q.current.type);lr[e]||(l('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',F(Q.current.type),r.ref),lr[e]=!0)}}function pn(r,n){{var e=function(){Ir||(Ir=!0,l("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};e.isReactWarning=!0,Object.defineProperty(r,"key",{get:e,configurable:!0})}}function fn(r,n){{var e=function(){Dr||(Dr=!0,l("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};e.isReactWarning=!0,Object.defineProperty(r,"ref",{get:e,configurable:!0})}}var vn=function(r,n,e,a,d,u,s){var i={$$typeof:f,type:r,key:n,ref:e,props:s,_owner:u};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:d}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function hn(r,n,e,a,d){{var u,s={},i=null,D=null;e!==void 0&&(Pr(e),i=""+e),ln(n)&&(Pr(n.key),i=""+n.key),cn(n)&&(D=n.ref,un(n,d));for(u in n)Z.call(n,u)&&!dn.hasOwnProperty(u)&&(s[u]=n[u]);if(r&&r.defaultProps){var x=r.defaultProps;for(u in x)s[u]===void 0&&(s[u]=x[u])}if(i||D){var k=typeof r=="function"?r.displayName||r.name||"Unknown":r;i&&pn(s,k),D&&fn(s,k)}return vn(r,i,D,d,a,Q.current,s)}}var ur=h.ReactCurrentOwner,Fr=h.ReactDebugCurrentFrame;function J(r){if(r){var n=r._owner,e=er(r.type,r._source,n?n.type:null);Fr.setExtraStackFrame(e)}else Fr.setExtraStackFrame(null)}var pr;pr=!1;function fr(r){return typeof r=="object"&&r!==null&&r.$$typeof===f}function Ar(){{if(ur.current){var r=F(ur.current.type);if(r)return`
22
-
23
- Check the render method of \``+r+"`."}return""}}function wn(r){{if(r!==void 0){var n=r.fileName.replace(/^.*[\\\/]/,""),e=r.lineNumber;return`
24
-
25
- Check your code at `+n+":"+e+"."}return""}}var Wr={};function gn(r){{var n=Ar();if(!n){var e=typeof r=="string"?r:r.displayName||r.name;e&&(n=`
26
-
27
- Check the top-level render call using <`+e+">.")}return n}}function Lr(r,n){{if(!r._store||r._store.validated||r.key!=null)return;r._store.validated=!0;var e=gn(n);if(Wr[e])return;Wr[e]=!0;var a="";r&&r._owner&&r._owner!==ur.current&&(a=" It was passed a child from "+F(r._owner.type)+"."),J(r),l('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',e,a),J(null)}}function zr(r,n){{if(typeof r!="object")return;if(cr(r))for(var e=0;e<r.length;e++){var a=r[e];fr(a)&&Lr(a,n)}else if(fr(r))r._store&&(r._store.validated=!0);else if(r){var d=o(r);if(typeof d=="function"&&d!==r.entries)for(var u=d.call(r),s;!(s=u.next()).done;)fr(s.value)&&Lr(s.value,n)}}}function bn(r){{var n=r.type;if(n==null||typeof n=="string")return;var e;if(typeof n=="function")e=n.propTypes;else if(typeof n=="object"&&(n.$$typeof===b||n.$$typeof===W))e=n.propTypes;else return;if(e){var a=F(n);an(e,r.props,"prop",a,r)}else if(n.PropTypes!==void 0&&!pr){pr=!0;var d=F(n);l("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",d||"Unknown")}typeof n.getDefaultProps=="function"&&!n.getDefaultProps.isReactClassApproved&&l("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function xn(r){{for(var n=Object.keys(r.props),e=0;e<n.length;e++){var a=n[e];if(a!=="children"&&a!=="key"){J(r),l("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),J(null);break}}r.ref!==null&&(J(r),l("Invalid attribute `ref` supplied to `React.Fragment`."),J(null))}}var Nr={};function Br(r,n,e,a,d,u){{var s=M(r);if(!s){var i="";(r===void 0||typeof r=="object"&&r!==null&&Object.keys(r).length===0)&&(i+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var D=wn(d);D?i+=D:i+=Ar();var x;r===null?x="null":cr(r)?x="array":r!==void 0&&r.$$typeof===f?(x="<"+(F(r.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):x=typeof r,l("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",x,i)}var k=hn(r,n,e,d,u);if(k==null)return k;if(s){var z=n.children;if(z!==void 0)if(a)if(cr(z)){for(var K=0;K<z.length;K++)zr(z[K],r);Object.freeze&&Object.freeze(z)}else l("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else zr(z,r)}if(Z.call(n,"key")){var H=F(r),A=Object.keys(n).filter(function(jn){return jn!=="key"}),vr=A.length>0?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}";if(!Nr[H+vr]){var Rn=A.length>0?"{"+A.join(": ..., ")+": ...}":"{}";l(`A props object containing a "key" prop is being spread into JSX:
28
- let props = %s;
29
- <%s {...props} />
30
- React keys must be passed directly to JSX without using spread:
31
- let props = %s;
32
- <%s key={someKey} {...props} />`,vr,H,Rn,H),Nr[H+vr]=!0}}return r===E?xn(k):bn(k),k}}function mn(r,n,e){return Br(r,n,e,!0)}function yn(r,n,e){return Br(r,n,e,!1)}var kn=yn,En=mn;X.Fragment=E,X.jsx=kn,X.jsxs=En}()),X}process.env.NODE_ENV==="production"?tr.exports=Yr():tr.exports=Mr();var t=tr.exports;const Vr=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
1
+ (function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,n(w.Dropdown={},w.jsxRuntime,w.React))})(this,function(w,n,o){"use strict";const q=`@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
33
2
  * {
34
3
  margin: 0;
35
4
  padding: 0;
@@ -232,12 +201,6 @@ React keys must be passed directly to JSX without using spread:
232
201
  white-space: nowrap; */
233
202
  }
234
203
 
235
- /* remove default focus outline when container is focused for keyboard handling */
236
- .starasia-input-dropdown-lists-container:focus {
237
- outline: none;
238
- box-shadow: none;
239
- }
240
-
241
204
  .starasia-input-dropdown-lists-container-bottom {
242
205
  top: 100%;
243
206
  margin-top: var(--starasia-ui-dropdown-spacing-xs);
@@ -310,10 +273,6 @@ React keys must be passed directly to JSX without using spread:
310
273
  /* box-shadow: 0px 0px 0px -1px #f0f0f0; */
311
274
  }
312
275
 
313
- .starasia-input-dropdwon-item.highlight {
314
- background-color: rgba(100, 181, 246, 0.21);
315
- }
316
-
317
276
  .starasia-input-dropdwon-item-disable {
318
277
  color: var(--starasia-ui-dropdown-color-disable) !important;
319
278
  pointer-events: none;
@@ -443,4 +402,4 @@ React keys must be passed directly to JSX without using spread:
443
402
  height: 100%;
444
403
  width: 100%;
445
404
  }
446
- `;function Ur(p){const[f,m]=c.useState(p),E=c.useRef(null),v=w=>{E.current&&!E.current.contains(w.target)&&m(!1)};return c.useEffect(()=>(document.addEventListener("click",v,!0),()=>{document.removeEventListener("click",v,!0)}),[]),{ref:E,isComponentVisible:f,setIsComponentVisible:m}}const Hr=({...p})=>t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...p,viewBox:"0 0 24 24",fill:"none",color:"#939E99",children:t.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),Jr=({...p})=>t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...p,viewBox:"0 0 20 20",fill:"none",children:[t.jsx("circle",{cx:"9.80547",cy:"9.8055",r:"7.49047",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M15.0153 15.4043L17.9519 18.3333",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]}),Kr=({isChecked:p})=>t.jsxs("div",{className:"checkbox-wrapper-30",children:[t.jsxs("span",{className:"checkbox",children:[t.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:p}),t.jsx("svg",{children:t.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:t.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:t.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),Gr=c.forwardRef(({positionDropdown:p,dropdownLists:f,isComponentVisible:m,searchAble:E,onSearch:v,value:w,handleChangeValue:I,multiSelect:j,searchValue:b},S)=>{const[_,W]=c.useState(0),[R,N]=c.useState(),L=c.useRef(null),y=c.useRef(null);return c.useEffect(()=>{if(L.current){const o=L.current.getBoundingClientRect();W(o.width)}},[L,m]),c.useEffect(()=>{f&&b?f.forEach(o=>{if(o.label.startsWith(b||"")){N(o.value);return}}):N(void 0)},[b,f]),c.useEffect(()=>{const o=y.current||(S==null?void 0:S.current);if(!o||!m)return;const h=f.filter(g=>!g.disable),l=g=>{if(g.key==="ArrowDown"){if(g.preventDefault(),!h.length)return;const C=h.findIndex(Y=>Y.value===R),B=C===-1?0:(C+1)%h.length;N(h[B].value)}else if(g.key==="ArrowUp"){if(g.preventDefault(),!h.length)return;const C=h.findIndex(Y=>Y.value===R),B=C<=0?h.length-1:C-1;N(h[B].value)}else if(g.key==="Enter"){if(g.preventDefault(),!R)return;const C=f.find(B=>B.value===R);C&&!C.disable&&I(C.label,C.value)}};return o.addEventListener("keydown",l),()=>o.removeEventListener("keydown",l)},[m,f,R,I,S]),c.useEffect(()=>{if(!R)return;const o=L.current;if(!o)return;const h=o.querySelector(`[data-value="${R}"]`);h&&h.scrollIntoView&&h.scrollIntoView({block:"nearest"})},[R]),t.jsx(t.Fragment,{children:m?t.jsxs("div",{className:"starasia-input-dropdown-lists-container",onClick:o=>o.stopPropagation(),ref:o=>{if(y.current=o,typeof S=="function")S(o);else if(S)try{S.current=o}catch{}},tabIndex:0,children:[E?t.jsxs("div",{className:"starasia-input-dropdown-container-dropdown-search",style:{order:p=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[t.jsx("div",{style:{display:"flex"},children:t.jsx(Jr,{strokeWidth:2,width:20})}),t.jsx("input",{onChange:o=>{v&&v(o.target.value)},value:b,autoFocus:!0,style:{width:"100%"}})]}):null,t.jsx("div",{className:`starasia-input-dropdwon-item-container ${j?"multi":""}`,ref:L,children:f.map((o,h)=>{const l=!!(w!=null&&w.find(g=>g.value===o.value));return t.jsxs("div",{"data-value":o.value,className:`starasia-input-dropdwon-item ${l?"active":" "} ${R===o.value?"highlight":""} ${o.disable?"starasia-input-dropdwon-item-disable":null}`,onClick:()=>I(o.label,o.value),children:[j?t.jsx("div",{style:{marginRight:"8px"},children:t.jsx(Kr,{isChecked:l})}):null,o.icon?t.jsx("div",{children:c.cloneElement(o.icon,{width:16})}):null,t.jsxs("div",{children:[t.jsx("p",{className:`starasia-input-dropdwon-item-text ${l?"active":null} ${o.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${_-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:o.label}),o.description?t.jsx("p",{className:`starasia-input-dropdwon-item-text-description ${l?"active":null} ${o.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${_-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:o.description}):null]})]},h)})})]}):null})}),Xr=({children:p,handleChangePosition:f})=>{const m=c.useRef(null);c.useEffect(()=>{var I;const v=()=>{if(m.current){let j=m.current.parentElement;for(;j&&!E(j);)j=j.parentElement;j&&f()}};let w=(I=m.current)==null?void 0:I.parentElement;for(;w&&!E(w);)w=w.parentElement;return w&&w.addEventListener("scroll",v),v(),()=>{w&&w.removeEventListener("scroll",v)}},[]);const E=v=>v&&(v.scrollHeight>v.clientHeight||v.scrollWidth>v.clientWidth);return t.jsx("div",{ref:m,children:p})},gr="starasia-input-dropdown-styles";(p=>{if(!document.getElementById(gr)){const f=document.createElement("style");f.id=gr,f.textContent=p,document.head.appendChild(f)}})(Vr);const Zr=({dropdownLists:p,onChange:f,defaultValue:m,size:E="md",multiSelect:v,searchAble:w,iconLeft:I,placeholder:j,onSearch:b,error:S,onBlur:_,onFocus:W,disable:R,searchValue:N})=>{const L=c.useRef(),[y,o]=c.useState([]),[h,l]=c.useState(""),g=c.useRef(null),{isComponentVisible:C,ref:B,setIsComponentVisible:Y}=Ur(!1),or=()=>{Y(T=>!T)},$=(T,O)=>{if(!v)o([{label:T,value:O}]),f([{label:T,value:O}]),Y(!1);else if(y==null?void 0:y.find(P=>P.value===O)){const P=[...y?y.filter(U=>U.value!==O):[]];o(P),f(P)}else{const P=[...y||[],{label:T,value:O}];o(P),f(P)}};c.useEffect(()=>{JSON.stringify(L.current)===JSON.stringify(m)||(L.current=m,o(L.current||[]))},[m]);const q=()=>y.length?v?y==null?void 0:y.map((T,O)=>t.jsxs("div",{className:"starasia-input-dropdown-preview-item",children:[t.jsx("p",{style:{minWidth:"max-content"},children:T==null?void 0:T.label},O),t.jsx(Qr,{onClick:()=>$(T.label,T.value)})]})):t.jsx("p",{style:{minWidth:"max-content"},children:y==null?void 0:y[0].label}):t.jsx("p",{className:"starasia-input-dropdown-placeholder",children:j}),M=()=>{if(B.current&&g.current){const T=window.innerHeight,O=B.current.getBoundingClientRect(),F=g.current.getBoundingClientRect(),P=O.bottom+F.height;g.current.style.left=`${O.left}px`,g.current.style.width=`${O.width}px`,P>=T-10?(g.current.style.top=`${O.top-F.height-5}px`,l("top")):(g.current.style.top=`${O.top+O.height}px`,l("bottom"))}};return c.useEffect(()=>(window.addEventListener("scroll",M),window.addEventListener("resize",M),()=>{window.removeEventListener("scroll",M),window.removeEventListener("resize",M)}),[]),c.useEffect(()=>{M()},[C]),c.useEffect(()=>{C&&g.current&&!w&&setTimeout(()=>{try{g.current&&g.current.focus()}catch{}},0)},[C,w]),t.jsx(Xr,{handleChangePosition:M,children:t.jsxs("div",{className:`starasia-input-dropdown-container ${R?"disable":""} starasia-input-dropdown-size-${E} ${C?"active":""} ${S?"error":""}`,ref:B,onClick:or,children:[t.jsxs("div",{className:"starasia-input-dropdown-preview-container",children:[I?t.jsx(t.Fragment,{children:c.cloneElement(I,{width:br(E),color:"#939E99",style:{color:"#939E99"}})}):null,t.jsx("div",{className:"starasia-input-dropdown-container-preview-item",tabIndex:100,onBlur:_,onFocus:W,children:q()}),t.jsx(Hr,{strokeWidth:2,width:br(E),style:{color:"#939E99"}})]}),t.jsx(Gr,{dropdownLists:p,handleChangeValue:$,isComponentVisible:C,positionDropdown:h,searchAble:!!w,value:y,onSearch:b,ref:g,multiSelect:v,searchValue:N})]})})},br=p=>{if(p==="sm")return 16;if(p==="md")return 16;if(p==="lg")return 20},Qr=p=>t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...p,children:t.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});V.Dropdown=Zr,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
405
+ `;function A(a){const[e,t]=o.useState(a),l=o.useRef(null),i=s=>{l.current&&!l.current.contains(s.target)&&t(!1)};return o.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:l,isComponentVisible:e,setIsComponentVisible:t}}const D=({...a})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",...a,viewBox:"0 0 24 24",fill:"none",color:"#939E99",children:n.jsx("path",{d:"M4 9L12 17L20 9",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5})}),F=({...a})=>n.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",...a,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"})]}),O=({isChecked:a})=>n.jsxs("div",{className:"checkbox-wrapper-30",children:[n.jsxs("span",{className:"checkbox",children:[n.jsx("input",{type:"checkbox",style:{pointerEvents:"none"},checked:a}),n.jsx("svg",{children:n.jsx("use",{xlinkHref:"#checkbox-30",className:"checkbox"})})]}),n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",style:{display:"none"},children:n.jsx("symbol",{id:"checkbox-30",viewBox:"0 0 22 22",children:n.jsx("path",{fill:"none",stroke:"currentColor",d:"M5.5,11.3L9,14.8L20.2,3.3l0,0c-0.5-1-1.5-1.8-2.7-1.8h-13c-1.7,0-3,1.3-3,3v13c0,1.7,1.3,3,3,3h13 c1.7,0,3-1.3,3-3v-13c0-0.4-0.1-0.8-0.3-1.2"})})})]}),H=o.forwardRef(({positionDropdown:a,dropdownLists:e,isComponentVisible:t,searchAble:l,onSearch:i,value:s,handleChangeValue:g,multiSelect:p,searchValue:v},E)=>{const[k,z]=o.useState(0),[N,m]=o.useState(),h=o.useRef(null);return o.useEffect(()=>{if(h.current){const r=h.current.getBoundingClientRect();z(r.width)}},[h,t]),o.useEffect(()=>{e&&v?e.forEach(r=>{if(r.label.startsWith(v||"")){m(r.value);return}}):m(void 0)},[v,e]),n.jsx(n.Fragment,{children:t?n.jsxs("div",{className:"starasia-input-dropdown-lists-container",onClick:r=>r.stopPropagation(),ref:E,children:[l?n.jsxs("div",{className:"starasia-input-dropdown-container-dropdown-search",style:{order:a=="bottom"?0:2,position:"sticky",top:0,bottom:0,zIndex:1},children:[n.jsx("div",{style:{display:"flex"},children:n.jsx(F,{strokeWidth:2,width:20})}),n.jsx("input",{onChange:r=>{i&&i(r.target.value)},value:v,autoFocus:!0,style:{width:"100%"}})]}):null,n.jsx("div",{className:`starasia-input-dropdwon-item-container ${p?"multi":""}`,ref:h,children:e.map((r,f)=>{const x=!!(s!=null&&s.find(C=>C.value===r.value));return n.jsxs("div",{className:`starasia-input-dropdwon-item ${x?"active":" "} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,onClick:()=>g(r.label,r.value),children:[p?n.jsx("div",{style:{marginRight:"8px"},children:n.jsx(O,{isChecked:x})}):null,r.icon?n.jsx("div",{children:o.cloneElement(r.icon,{width:16})}):null,n.jsxs("div",{children:[n.jsx("p",{className:`starasia-input-dropdwon-item-text ${x?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${k-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.label}),r.description?n.jsx("p",{className:`starasia-input-dropdwon-item-text-description ${x?"active":null} ${r.disable?"starasia-input-dropdwon-item-disable":null}`,style:{textWrap:"nowrap",width:`${k-12}px`,overflow:"hidden",textOverflow:"ellipsis"},children:r.description}):null]})]},f)})})]}):null})}),M=({children:a,handleChangePosition:e})=>{const t=o.useRef(null);o.useEffect(()=>{var g;const i=()=>{if(t.current){let p=t.current.parentElement;for(;p&&!l(p);)p=p.parentElement;p&&e()}};let s=(g=t.current)==null?void 0:g.parentElement;for(;s&&!l(s);)s=s.parentElement;return s&&s.addEventListener("scroll",i),i(),()=>{s&&s.removeEventListener("scroll",i)}},[]);const l=i=>i&&(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth);return n.jsx("div",{ref:t,children:a})},W="starasia-input-dropdown-styles";(a=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=a,document.head.appendChild(e)}})(q);const P=({dropdownLists:a,onChange:e,defaultValue:t,size:l="md",multiSelect:i,searchAble:s,iconLeft:g,placeholder:p,onSearch:v,error:E,onBlur:k,onFocus:z,disable:N,searchValue:m})=>{const h=o.useRef(),[r,f]=o.useState([]),[x,C]=o.useState(""),b=o.useRef(null),{isComponentVisible:I,ref:B,setIsComponentVisible:S}=A(!1),V=()=>{S(d=>!d)},j=(d,c)=>{if(!i)f([{label:d,value:c}]),e([{label:d,value:c}]),S(!1);else if(r==null?void 0:r.find(u=>u.value===c)){const u=[...r?r.filter(G=>G.value!==c):[]];f(u),e(u)}else{const u=[...r||[],{label:d,value:c}];f(u),e(u)}};o.useEffect(()=>{JSON.stringify(h.current)===JSON.stringify(t)||(h.current=t,f(h.current||[]))},[t]);const J=()=>r.length?i?r==null?void 0:r.map((d,c)=>n.jsxs("div",{className:"starasia-input-dropdown-preview-item",children:[n.jsx("p",{style:{minWidth:"max-content"},children:d==null?void 0:d.label},c),n.jsx(T,{onClick:()=>j(d.label,d.value)})]})):n.jsx("p",{style:{minWidth:"max-content"},children:r==null?void 0:r[0].label}):n.jsx("p",{className:"starasia-input-dropdown-placeholder",children:p}),y=()=>{if(B.current&&b.current){const d=window.innerHeight,c=B.current.getBoundingClientRect(),L=b.current.getBoundingClientRect(),u=c.bottom+L.height;b.current.style.left=`${c.left}px`,b.current.style.width=`${c.width}px`,u>=d-10?(b.current.style.top=`${c.top-L.height-5}px`,C("top")):(b.current.style.top=`${c.top+c.height}px`,C("bottom"))}};return o.useEffect(()=>(window.addEventListener("scroll",y),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y),window.removeEventListener("resize",y)}),[]),o.useEffect(()=>{y()},[I]),n.jsx(M,{handleChangePosition:y,children:n.jsxs("div",{className:`starasia-input-dropdown-container ${N?"disable":""} starasia-input-dropdown-size-${l} ${I?"active":""} ${E?"error":""}`,ref:B,onClick:V,children:[n.jsxs("div",{className:"starasia-input-dropdown-preview-container",children:[g?n.jsx(n.Fragment,{children:o.cloneElement(g,{width:$(l),color:"#939E99",style:{color:"#939E99"}})}):null,n.jsx("div",{className:"starasia-input-dropdown-container-preview-item",tabIndex:100,onBlur:k,onFocus:z,children:J()}),n.jsx(D,{strokeWidth:2,width:$(l),style:{color:"#939E99"}})]}),n.jsx(H,{dropdownLists:a,handleChangeValue:j,isComponentVisible:I,positionDropdown:x,searchAble:!!s,value:r,onSearch:v,ref:b,multiSelect:i,searchValue:m})]})})},$=a=>{if(a==="sm")return 16;if(a==="md")return 16;if(a==="lg")return 20},T=a=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",...a,children:n.jsx("path",{d:"M12 6L6 12M6.00001 6L12 12",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})});w.Dropdown=P,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/dropdown",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "dropdown component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/dropdown.umd.js",
@@ -12,16 +12,16 @@
12
12
  "dist/*.map",
13
13
  "dist/*.css"
14
14
  ],
15
- "scripts": {
16
- "dev": "vite --config vite.config.ts --port 3000",
17
- "build": "vite build --config vite.config.ts"
18
- },
19
15
  "keywords": [],
20
16
  "license": "ISC",
21
17
  "type": "module",
22
18
  "engines": {
23
19
  "node": ">=18.0.0"
24
20
  },
21
+ "peerDependencies": {
22
+ "react": ">=18.0.0 <20.0.0",
23
+ "react-dom": ">=18.0.0 <20.0.0"
24
+ },
25
25
  "devDependencies": {
26
26
  "@types/node": "^20.11.16",
27
27
  "@vitejs/plugin-react": "^4.2.1",
@@ -33,5 +33,9 @@
33
33
  "react-dom": "^18.2.0",
34
34
  "@types/react": "^18.2.55",
35
35
  "@types/react-dom": "^18.2.19"
36
+ },
37
+ "scripts": {
38
+ "dev": "vite --config vite.config.ts --port 3000",
39
+ "build": "vite build --config vite.config.ts"
36
40
  }
37
- }
41
+ }