@wbe/react-transition
Version:
    • 1.11 kB
JavaScript
import l,{useRef as n,useState as t,useLayoutEffect as e}from"react";function a(a){const r=n(null),[u,i]=t(()=>a.appear?null:a.if?"visible":"hidden"),p=n(!0);e(()=>{a.appear||!p.current?i(a.if?"play-in":"play-out"):p.current=!1},[a.if,a.appear]);const o=n(null);return e(()=>{const l=r.current;l&&("play-in"!==u&&"play-out"!==u||null==o.current||o.current(),(async()=>{"play-in"===u&&(await new Promise((n,t)=>{null==a.playIn||a.playIn(l,n),o.current=t}),null==a.onPlayInComplete||a.onPlayInComplete(),i("visible")),"play-out"===u&&(await new Promise((n,t)=>{null==a.playOut||a.playOut(l,n),o.current=t}),null==a.onPlayOutComplete||a.onPlayOutComplete(),null==a.dispatchPlayState||a.dispatchPlayState("hidden"),i("hidden"))})(),null==a.dispatchPlayState||a.dispatchPlayState(u))},[u]),"hidden"===u&&a.unmountAfterPlayOut?null:/*#__PURE__*/l.cloneElement(a.children,{className:[a.children.props.className||null,`transition-${u}`].filter(l=>l).join(" "),ref:l=>r.current=l})}a.defaultProps={if:!0,children:null,appear:!1,unmountAfterPlayOut:!0};export{a as Transition};
//# sourceMappingURL=index.modern.js.map