react-block-ui
Version:
Block UI for react
3 lines (2 loc) • 5.84 kB
JavaScript
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b(require('react')):'function'==typeof define&&define.amd?define(['react'],b):a.ReactBlockUi=b(a.React)})(this,function(a){'use strict';function b(a){a=a||document;var b;try{b=document.activeElement,b&&b.nodeName||(b=a.body)}catch(c){b=a.body}return b}var c='default'in a?a['default']:a,d=function(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')},e=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},g=function(a,b){if('function'!=typeof b&&null!==b)throw new TypeError('Super expression must either be null or a function, not '+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)},h=function(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c},i=function(a,b){if(!a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return b&&('object'==typeof b||'function'==typeof b)?b:a},j=function(a){function j(a){d(this,j);var b=i(this,(j.__proto__||Object.getPrototypeOf(j)).call(this,a));return b.tabbedUpTop=b.tabbedUpTop.bind(b),b.tabbedDownTop=b.tabbedDownTop.bind(b),b.tabbedUpBottom=b.tabbedUpBottom.bind(b),b.tabbedDownBottom=b.tabbedDownBottom.bind(b),b.setHelper=b.setRef.bind(b,'helper'),b.setBlocker=b.setRef.bind(b,'blocker'),b.setTopFocus=b.setRef.bind(b,'topFocus'),b.setContainer=b.setRef.bind(b,'container'),b.setMessageContainer=b.setRef.bind(b,'messageContainer'),b.handleScroll=b.handleScroll.bind(b),b.state={top:'50%'},b}return g(j,a),e(j,[{key:'componentWillReceiveProps',value:function(a){var c=this;if(a.blocking!==this.props.blocking)if(a.blocking)this.helper&&this.helper.parentNode&&this.helper.parentNode.contains&&this.helper.parentNode.contains(b())&&(this.focused=b(),this.focused&&this.focused!==document.body&&(window.setImmediate||setTimeout)(function(){return c.focused&&'function'==typeof c.focused.blur&&c.focused.blur()}));else{this.detachListeners();var d=b();this.focused&&(!d||d===document.body||d===this.topFocus)&&('function'==typeof this.focused.focus&&this.focused.focus(),this.focused=null)}a.keepInView&&(a.keepInView!==this.props.keepInView||a.blocking&&a.blocking!==this.props.blocking)&&(this.attachListeners(),this.keepInView(a))}},{key:'componentWillUnmount',value:function(){this.detachListeners()}},{key:'setRef',value:function(a,b){this[a]=b,b&&'container'===a&&this.keepInView()}},{key:'attachListeners',value:function(){window.addEventListener('scroll',this.handleScroll)}},{key:'detachListeners',value:function(){window.removeEventListener('scroll',this.handleScroll)}},{key:'blockingTab',value:function(a){var b=1<arguments.length&&void 0!==arguments[1]&&arguments[1];return this.props.blocking&&('Tab'===a.key||9===a.keyCode)&&a.shiftKey==b}},{key:'tabbedUpTop',value:function(a){this.blockingTab(a)&&this.blocker.focus()}},{key:'tabbedDownTop',value:function(a){this.blockingTab(a)&&(a.preventDefault(),this.blocker.focus())}},{key:'tabbedUpBottom',value:function(a){this.blockingTab(a,!0)&&this.topFocus.focus()}},{key:'tabbedDownBottom',value:function(a){this.blockingTab(a,!0)&&(a.preventDefault(),this.topFocus.focus())}},{key:'keepInView',value:function(){var a=Math.max,b=Math.min,c=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.props;if(c.blocking&&c.keepInView&&this.container){var d=this.container.getBoundingClientRect(),e=window.innerHeight;if(d.top>e||0>d.bottom)return;if(0<=d.top&&d.bottom<=e)return void('50%'!==this.state.top&&this.setState({top:'50%'}));var f=this.messageContainer?this.messageContainer.getBoundingClientRect().height:0,g=a(b(e,d.bottom)-a(d.top,0),f)/2;0>d.top&&(g=b(g-d.top,d.height-f/2)),this.state.top!==g&&this.setState({top:g})}}},{key:'handleScroll',value:function(){this.keepInView()}},{key:'render',value:function(){var a=this.props,b=a.tag,d=a.blocking,e=a.className,g=a.children,i=a.message,j=a.loader,k=a.renderChildren,l=a.keepInView,m=a.ariaLabel,n=void 0===m?'loading':m,o=h(a,['tag','blocking','className','children','message','loader','renderChildren','keepInView','ariaLabel']),p=d?'block-ui '+e:e;return c.createElement(b,f({},o,{className:p,"aria-busy":d}),d&&c.createElement('div',{tabIndex:'0',onKeyUp:this.tabbedUpTop,onKeyDown:this.tabbedDownTop,ref:this.setTopFocus},c.createElement('div',{className:'sr-only'},i||n)),(!d||k)&&g,d&&c.createElement('div',{className:'block-ui-container',tabIndex:'0',ref:this.setBlocker,onKeyUp:this.tabbedUpBottom,onKeyDown:this.tabbedDownBottom},c.createElement('div',{className:'block-ui-overlay',ref:this.setContainer}),c.createElement('div',{className:'block-ui-message-container',ref:this.setMessageContainer,style:{top:l?this.state.top:void 0}},c.createElement('div',{className:'block-ui-message'},i||c.createElement('span',{className:'sr-only'},n),c.createElement('div',{"aria-hidden":!0},c.isValidElement(j)?j:c.createElement(j,null))))),c.createElement('span',{ref:this.setHelper}))}}]),j}(a.Component);return j.defaultProps={tag:'div',renderChildren:!0,loader:function(){return c.createElement('div',{className:'loading-indicator'},c.createElement('span',{className:'loading-bullet'},'\u2022'),' ',c.createElement('span',{className:'loading-bullet'},'\u2022'),' ',c.createElement('span',{className:'loading-bullet'},'\u2022'))}},j});
//# sourceMappingURL=reactblockui.min.js.map