UNPKG

react-show

Version:

react-show React component

6 lines 10.5 kB
/*! * react-show v3.0.4 - https://react-show.js.org * MIT Licensed */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactShow=t(require("react")):e.ReactShow=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";function r(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),n.d(t,"easings",function(){return b}),n.d(t,"Animate",function(){return y});var s,a,c,l=n(2),f=n.n(l),h=n(3),p=n.n(h),d=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},b={easeInCubic:"cubic-bezier(0.550, 0.055, 0.675, 0.190)",easeOutCubic:"cubic-bezier(0.215, 0.610, 0.355, 1.000)",easeInOutCubic:"cubic-bezier(0.645, 0.045, 0.355, 1.000)",easeInCirc:"cubic-bezier(0.600, 0.040, 0.980, 0.335)",easeOutCirc:"cubic-bezier(0.075, 0.820, 0.165, 1.000)",easeInOutCirc:"cubic-bezier(0.785, 0.135, 0.150, 0.860)",easeInExpo:"cubic-bezier(0.950, 0.050, 0.795, 0.035)",easeOutExpo:"cubic-bezier(0.190, 1.000, 0.220, 1.000)",easeInOutExpo:"cubic-bezier(1.000, 0.000, 0.000, 1.000)",easeInQuad:"cubic-bezier(0.550, 0.085, 0.680, 0.530)",easeOutQuad:"cubic-bezier(0.250, 0.460, 0.450, 0.940)",easeInOutQuad:"cubic-bezier(0.455, 0.030, 0.515, 0.955)",easeInQuart:"cubic-bezier(0.895, 0.030, 0.685, 0.220)",easeOutQuart:"cubic-bezier(0.165, 0.840, 0.440, 1.000)",easeInOutQuart:"cubic-bezier(0.770, 0.000, 0.175, 1.000)",easeInQuint:"cubic-bezier(0.755, 0.050, 0.855, 0.060)",easeOutQuint:"cubic-bezier(0.230, 1.000, 0.320, 1.000)",easeInOutQuint:"cubic-bezier(0.860, 0.000, 0.070, 1.000)",easeInSine:"cubic-bezier(0.470, 0.000, 0.745, 0.715)",easeOutSine:"cubic-bezier(0.390, 0.575, 0.565, 1.000)",easeInOutSine:"cubic-bezier(0.445, 0.050, 0.550, 0.950)",easeInBack:"cubic-bezier(0.600, -0.280, 0.735, 0.045)",easeOutBack:"cubic-bezier(0.175, 0.885, 0.320, 1.275)",easeInOutBack:"cubic-bezier(0.680, -0.550, 0.265, 1.550)"},y=(a=s=function(e){function t(n){i(this,t);var r=o(this,e.call(this,n));c.call(r);var u=r.props,s=u.show,a=u.preMount,l=u.transitionOnMount,f=u.start,h=u.enter;return r.stage=!1,r.stageStyles={},r.transitioning=!1,r.state={mountContent:a||s,currentStyle:l?f:h,styleOverrides:{}},r}return u(t,e),t.prototype.componentDidMount=function(){var e=this.props,t=e.transitionOnMount,n=e.show,r=e.enter;t&&n&&this.transition("enter",r)},t.prototype.componentDidUpdate=function(e){var t=this.props,n=t.show,r=t.enter,i=t.leave,o=t.start,u=this.stage;if(n){if(!e.show)return"leave"===u?this.transition("clean"):r?this.transition("enter",r):this.transition("clean");if("didEnter"===u)return this.transition("clean")}else if(e.show)return this.transition("leave",i||o)},t.prototype.render=function(){var e=this,t=this.props,n=t.component,i=t.children,o=(t.show,t.easing,t.duration,t.transitionProperty,t.stayMounted,t.transitionOnMount,t.show,t.style,t.leave,t.enter,t.innerRef),u=(t.onFinish,t.preMount,r(t,["component","children","show","easing","duration","transitionProperty","stayMounted","transitionOnMount","show","style","leave","enter","innerRef","onFinish","preMount"])),s=this.state,a=s.mountContent,c=s.currentStyle,l=s.styleOverrides;return a?f.a.createElement(n,d({ref:function(t){e.handleRef(t),o&&o(t)},onTransitionEnd:this.transitionEnd,style:this.makeStyles(c,l)},u),i):null},t}(f.a.Component),s.easings=b,s.defaultProps={component:"div",show:!0,easing:"easeOutQuad",duration:300,transitionProperty:"all",preMount:!1,stayMounted:!0,transitionOnMount:!1,style:void 0,start:void 0,enter:void 0,leave:void 0,onFinish:function(){}},c=function(){var e=this;this.ensureMounted=function(){return new Promise(function(t){!function n(){if(e.el)return t();p()(function(){e.setState({mountContent:!0},n)})}()})},this.setCurrentStyle=function(t){return e.setState({currentStyle:t})},this.overrideStyle=function(t){return new Promise(function(n){!function r(){e.setState({styleOverrides:t},function(){p()(function(){if(Object.keys(t).some(function(n){return!e.el||e.el.style[n]!==t[n]}))return r();n()})})}()})},this.transition=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.props.show;e.stage=t,e.stageStyles=n,e.transitioning=!0;var i=void 0,o=void 0,u=void 0,s=void 0,a=void 0;return Promise.resolve().then(function(){if(r)return e.ensureMounted()}).then(function(){var t=e.state,r=t.currentStyle,c=t.styleOverrides,l=e.makeStyles(r,c),f=e.makeStyles(n);i=e.isProp(l,"width","auto"),o=e.isProp(l,"height","auto"),u=e.isProp(f,"width","auto"),s=e.isProp(f,"height","auto");var h=i!==u,p=o!==s;if(a=h||p)return e.overrideStyle({display:"block",overflow:"hidden"}).then(function(){var t=e.measure();return e.overrideStyle(d({},h?{width:t.width+"px"}:{},p?{height:t.height+"px"}:{}))})}).then(function(){p()(function(){e.setState(function(e){var t=e.styleOverrides;return t=a?d({},t,i?{width:n.width}:{},o?{height:n.height}:{}):t,{mountContent:!0,currentStyle:n,styleOverrides:t}},function(){})})})},this.transitionEnd=function(t){t&&(t.persist(),t.target!==e.el)||(e.transitionRAF&&p.a.cancel(e.transitionRAF),e.transitionRAF=p()(e.completeTransition))},this.completeTransition=function(){var t=e.props,n=t.stayMounted,r=t.onFinish,i="leave"===e.stage;e.transitioning=!1,"enter"===e.stage?e.stage="didEnter":"mount"===e.stage?e.stage="mounted":e.stage=!1,e.setState({mountContent:!(i&&!n),styleOverrides:{}},r)},this.handleRef=function(t){e.el=t},this.isProp=function(e,t,n){return e[t]===n},this.measure=function(){return e.el?{width:e.el.scrollWidth,height:e.el.scrollHeight}:{}},this.makeStyles=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.props,i=r.style,o=r.transitionProperty,u=r.duration,s=r.easing,a=b[s]||s||"ease-out";return d({transitionProperty:o,transitionDuration:u+"ms",transitionTimingFunction:""+a},i,t,n)}},a)},function(t,n){t.exports=e},function(e,t,n){(function(t){for(var r=n(5),i="undefined"==typeof window?t:window,o=["moz","webkit"],u="AnimationFrame",s=i["request"+u],a=i["cancel"+u]||i["cancelRequest"+u],c=0;!s&&c<o.length;c++)s=i[o[c]+"Request"+u],a=i[o[c]+"Cancel"+u]||i[o[c]+"CancelRequest"+u];if(!s||!a){var l=0,f=0,h=[];s=function(e){if(0===h.length){var t=r(),n=Math.max(0,1e3/60-(t-l));l=n+t,setTimeout(function(){var e=h.slice(0);h.length=0;for(var t=0;t<e.length;t++)if(!e[t].cancelled)try{e[t].callback(l)}catch(e){setTimeout(function(){throw e},0)}},Math.round(n))}return h.push({handle:++f,callback:e,cancelled:!1}),f},a=function(e){for(var t=0;t<h.length;t++)h[t].handle===e&&(h[t].cancelled=!0)}}e.exports=function(e){return s.call(i,e)},e.exports.cancel=function(){a.apply(i,arguments)},e.exports.polyfill=function(e){e||(e=i),e.requestAnimationFrame=s,e.cancelAnimationFrame=a}}).call(t,n(4))},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){(function(){var n,r,i,o,u,s;"undefined"!=typeof performance&&null!==performance&&performance.now?e.exports=function(){return performance.now()}:void 0!==t&&null!==t&&t.hrtime?(e.exports=function(){return(n()-u)/1e6},r=t.hrtime,n=function(){var e;return e=r(),1e9*e[0]+e[1]},o=n(),s=1e9*t.uptime(),u=o-s):Date.now?(e.exports=function(){return Date.now()-i},i=Date.now()):(e.exports=function(){return(new Date).getTime()-i},i=(new Date).getTime())}).call(this)}).call(t,n(6))},function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===n||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function o(e){if(f===clearTimeout)return clearTimeout(e);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch(t){try{return f.call(null,e)}catch(t){return f.call(this,e)}}}function u(){b&&p&&(b=!1,p.length?d=p.concat(d):y=-1,d.length&&s())}function s(){if(!b){var e=i(u);b=!0;for(var t=d.length;t;){for(p=d,d=[];++y<t;)p&&p[y].run();y=-1,t=d.length}p=null,b=!1,o(e)}}function a(e,t){this.fun=e,this.array=t}function c(){}var l,f,h=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:n}catch(e){l=n}try{f="function"==typeof clearTimeout?clearTimeout:r}catch(e){f=r}}();var p,d=[],b=!1,y=-1;h.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new a(e,t)),1!==d.length||b||i(s)},a.prototype.run=function(){this.fun.apply(null,this.array)},h.title="browser",h.browser=!0,h.env={},h.argv=[],h.version="",h.versions={},h.on=c,h.addListener=c,h.once=c,h.off=c,h.removeListener=c,h.removeAllListeners=c,h.emit=c,h.prependListener=c,h.prependOnceListener=c,h.listeners=function(e){return[]},h.binding=function(e){throw new Error("process.binding is not supported")},h.cwd=function(){return"/"},h.chdir=function(e){throw new Error("process.chdir is not supported")},h.umask=function(){return 0}}])}); //# sourceMappingURL=react-show.min.js.map