react-16-height
Version:
Component-wrapper to determine and report children elements height
1 lines • 4.82 kB
JavaScript
!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.ReactHeight=t(require("react")):e.ReactHeight=t(e.React)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var r={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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 a(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}),t.ReactHeight=void 0;var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),f=r(6),p=n(f),l=r(5),h=n(l),d=function(e){return e.clientHeight},y=t.ReactHeight=function(e){function t(e){i(this,t);var r=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.setWrapperRef=function(e){r.wrapper=e},r.state={dirty:e.dirty,height:0},r}return a(t,e),s(t,[{key:"componentDidMount",value:function(){var e=this.props.getElementHeight(this.wrapper);this.setState({height:e,dirty:!1})}},{key:"componentWillReceiveProps",value:function(e){var t=e.children,r=e.dirty;(t!==this.props.children||r)&&this.setState({dirty:!0})}},{key:"componentDidUpdate",value:function(e,t){var r=this.props.getElementHeight(this.wrapper);t.height!==this.state.height&&this.props.onHeightReady(this.state.height),r===this.state.height?this.setState({dirty:!1}):this.setState({height:r,dirty:!1})}},{key:"render",value:function(){var e=this.props,t=(e.onHeightReady,e.getElementHeight,e.dirty,e.hidden),r=e.children,n=o(e,["onHeightReady","getElementHeight","dirty","hidden","children"]),i=this.state.dirty;return t&&!i?null:t?p.default.createElement("div",{style:{height:0,overflow:"hidden"}},p.default.createElement("div",c({ref:this.setWrapperRef},n),r)):p.default.createElement("div",c({ref:this.setWrapperRef},n),r)}}]),t}(f.PureComponent);y.propTypes={children:h.default.node.isRequired,onHeightReady:h.default.func.isRequired,hidden:h.default.bool,dirty:h.default.bool,getElementHeight:h.default.func},y.defaultProps={hidden:!1,dirty:!0,getElementHeight:d}},function(e,t,r){"use strict";var n=r(0),o=n.ReactHeight;o.ReactHeight=o,e.exports=o},function(e,t,r){"use strict";function n(e){return function(){return e}}var o=function(){};o.thatReturns=n,o.thatReturnsFalse=n(!1),o.thatReturnsTrue=n(!0),o.thatReturnsNull=n(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,r){"use strict";function n(e,t,r,n,i,u,a,c){if(o(t),!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,n,i,u,a,c],p=0;s=new Error(t.replace(/%s/g,function(){return f[p++]})),s.name="Invariant Violation"}throw s.framesToPop=1,s}}var o=function(e){};e.exports=n},function(e,t,r){"use strict";var n=r(2),o=r(3);e.exports=function(){function e(){o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return r.checkPropTypes=n,r.PropTypes=r,r}},function(e,t,r){e.exports=r(4)()},function(t,r){t.exports=e}])});