react-ts-timepicker
Version:
Simple timepicker for React
1 lines • 22 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define("react-ts-timepicker",["React","ReactDOM"],t):"object"==typeof exports?exports["react-ts-timepicker"]=t(require("react"),require("react-dom")):e["react-ts-timepicker"]=t(e.React,e.ReactDOM)}(window,function(e,t){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var s=t[o]={i:o,l:!1,exports:{}};return e[o].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(o,s,function(t){return e[t]}.bind(null,s));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=3)}([function(e,t,n){e.exports=n(4)()},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=n(1),s=n(11);n(6);const i=86400;class r extends o.Component{constructor(e){super(e),this.onChange=(e=>{const{onChange:t}=this.props;if(t)if(this.props.value instanceof Date){const n=this.convertSecondsToDate(e);t(new Date(this.props.value.getFullYear(),this.props.value.getMonth(),this.props.value.getDate(),n.getHours(),n.getMinutes(),n.getSeconds()))}else{const{value:n,inputValue:o}=this.state;t(n?this.convertSecondsToFormattedString(e):o)}}),this.onInputChange=(e=>{const t=this.convertTimeToSeconds(e.target.value);this.setState({inputValue:e.target.value,value:t},()=>{const{showSuggestions:e}=this.state;e?this.scrollSuggestionList(t):this.showSuggestions(),this.onChange(t)})}),this.onInputBlur=(()=>{null!==this.state.value&&this.setState({inputValue:this.convertSecondsToFormattedString(this.state.value)})}),this.onInputFocus=(()=>{this.showSuggestions()}),this.onInputClick=(()=>{this.state.showSuggestions||this.showSuggestions()}),this.onSuggestionSelect=(e=>{const t=parseInt(e.target.value,10);this.setState({inputValue:this.convertSecondsToFormattedString(t),value:t},()=>{this.hideSuggestions(),this.onChange(t)})}),this.onArrowUpDown=(e=>{const{value:t,suggestions:n,highlightedSuggestionIndex:o}=this.state;let s=0;if(null===o)if(t){const o=n.findIndex(e=>this.isNearestSuggestion(t,e));s="down"===e?o+1:o-1}else s=0;else s="down"===e?o+1:o-1;s<0&&(s=0),s===n.length&&(s=n.length-1),s!==o&&this.setState({highlightedSuggestionIndex:s},()=>{this.scrollSuggestionList(this.state.suggestions[s])})}),this.onKeyDown=(e=>{if(this.inputEl===document.activeElement)switch(e.key){case"Escape":this.hideSuggestions();break;case"Enter":{const{highlightedSuggestionIndex:e,value:t,suggestions:n}=this.state;if(e){const t=n[e];this.setState({inputValue:this.convertSecondsToFormattedString(t),value:t}),this.onChange(t)}else this.setState({inputValue:this.convertSecondsToFormattedString(t)});this.hideSuggestions();break}case"ArrowUp":this.onArrowUpDown("up");break;case"ArrowDown":this.state.showSuggestions?this.onArrowUpDown("down"):this.showSuggestions();break;case"Tab":this.state.showSuggestions&&this.hideSuggestions()}}),this.prependZero=(e=>e<10?`0${e}`:e.toString()),this.convertSecondsToDate=(e=>{return new Date(1970,0,2,e/3600%24,e/60%60,e%60,0)}),this.convertSecondsToFormattedString=(e=>{const{timeFormat:t}=this.props,n=this.convertSecondsToDate(e);return t.split("").reduce((e,t,o,s)=>{if(o>0&&s[o-1]===t)return e;switch(t){case"a":return e+(n.getHours()>11?"pm":"am");case"h":{const t=n.getHours()%12;return 0===t?e+"12":e+t}case"H":return e+n.getHours();case"m":return e+this.prependZero(n.getMinutes());case"s":return e+this.prependZero(n.getSeconds());default:return e+t}},"")}),this.convertTimeToSeconds=(e=>{if(""===e||null===e)return null;if(e instanceof Date)return 3600*e.getHours()+60*e.getMinutes()+e.getSeconds();let t=e.toLowerCase().replace(/[\s]/g,"");"a"!==t.slice(-1)&&"p"!==t.slice(-1)||(t+="m");const n=new RegExp("^(am|pm|AM|PM)?([0-9]?[0-9])\\W?([0-5][0-9])?\\W?([0-5][0-9])?(am|pm|AM|PM)?$"),o=t.match(n);if(!o)return null;const s=parseInt(o[2],10),r=parseInt(o[3],10)||0,a=parseInt(o[4],10)||0,u=o[1]||o[5];let l=s;if(s<=12&&u){const e="pm"===u||"PM"===u;l=12===s?e?12:0:s+(e?12:0)}let c=3600*l+60*r+a;if(c>i){if(!this.props.normalizeTime)return null;c=s%24*3600+60*r+a}return this.props.allowOnlySuggestions?this.roundTime(c):c}),this.hideSuggestionsOnOutsideClick=(e=>{e.target!==this.inputEl&&this.suggestionsWrapperEl&&!this.suggestionsWrapperEl.contains(e.target)&&this.hideSuggestions()}),this.hideSuggestionsOnScroll=(()=>{this.state.showSuggestions&&this.hideSuggestions()}),this.showSuggestions=(()=>{this.setState({showSuggestions:!0},()=>{this.positionSuggestions(),this.scrollSuggestionList(this.state.value),document.addEventListener("click",this.hideSuggestionsOnOutsideClick),this.props.hideOnScroll&&window.addEventListener("scroll",this.hideSuggestionsOnScroll)})}),this.hideSuggestions=(()=>{this.setState({highlightedSuggestionIndex:null,showSuggestions:!1,suggestionsPosition:null},()=>{document.removeEventListener("click",this.hideSuggestionsOnOutsideClick),this.props.hideOnScroll&&window.removeEventListener("scroll",this.hideSuggestionsOnScroll)})}),this.positionSuggestions=(()=>{const e=this.inputEl.getBoundingClientRect(),t=document.documentElement,n=(window.pageYOffset||t.scrollTop)-(t.clientTop||0),o=!!this.suggestionsWrapperEl&&this.suggestionsWrapperEl.getBoundingClientRect(),s=o?o.height:0,i=window.innerHeight||t.clientHeight||document.body.clientHeight;let r,a;null===this.props.appendTo?(r=0,a=e.height):(r=e.left,a=e.top+e.height+n),i-(e.top+e.height)<s&&(a=e.top-s+n),this.setState({suggestionsPosition:{left:r,top:a}})}),this.scrollSuggestionList=(e=>{const{suggestions:t,showSuggestions:n}=this.state;if(!this.suggestionsWrapperEl||!n)return;const o=this.suggestionEl?this.suggestionEl.offsetHeight:0;if(e){for(let n=0;n<t.length;n++)if(Math.abs(e-t[n])<=30*this.props.step){this.suggestionsWrapperEl.scrollTop=o*n-o;break}}else this.suggestionsWrapperEl.scrollTop=0}),this.createSuggestions=((e,t,n)=>{const o=60*e;let s=this.convertTimeToSeconds(t)||0;const r=this.convertTimeToSeconds(n)||i,a=[];for(;this.props.includeMax&&r<i?s<=r:s<r;)a.push(s),s+=o;return a}),this.roundTime=(e=>{const{step:t}=this.props,n=60*t,o=e%n;return o>=n/2?e+(n-o):e-o}),this.isNearestSuggestion=((e,t)=>Math.abs(e-t)<30*this.props.step/2),this.renderSuggestions=(()=>{const{highlightedSuggestionIndex:e,showSuggestions:t,suggestionsPosition:n,suggestions:i,value:r}=this.state,{appendTo:a}=this.props,u=o.createElement("div",{className:"time-picker__suggestion-list",ref:e=>{this.suggestionsWrapperEl=e},style:{display:t?"block":"none",left:n?n.left:-9999,top:n?n.top:-9999,zIndex:999999}},i.map((t,n)=>o.createElement("button",{value:t,key:`${name}-${t}`,type:"button",className:`time-picker__suggestion ${null!==e&&e===n||null===e&&r&&this.isNearestSuggestion(r,t)?"time-picker__suggestion_selected":""}`,onClick:this.onSuggestionSelect,tabIndex:-1,ref:e=>{0===n&&(this.suggestionEl=e)}},this.convertSecondsToFormattedString(t))));return null===a?u:o.createElement(s.Portal,{node:"body"!==a&&document&&document.querySelector(a)},u)});const{value:t,step:n,minTime:r,maxTime:a}=e,u=this.convertTimeToSeconds(t);this.state={highlightedSuggestionIndex:null,inputValue:u?this.convertSecondsToFormattedString(u):"",showSuggestions:!1,suggestions:this.createSuggestions(n,r,a),suggestionsPosition:null,value:u}}componentDidMount(){document.addEventListener("keydown",this.onKeyDown)}componentDidUpdate(e){const{value:t}=this.props;let n=!1;if(!e.value&&t||e.value&&!t?n=!0:t instanceof Date&&e.value instanceof Date?n=e.value.getTime()!==t.getTime():"string"==typeof t&&"string"==typeof e.value&&(n=e.value!==t),n){const e=this.convertTimeToSeconds(t);this.setState({inputValue:e?this.convertSecondsToFormattedString(e):"",value:e})}}componentWillUnmount(){document.removeEventListener("keydown",this.onKeyDown)}render(){const{className:e,inputClass:t}=this.props,{suggestions:n,showSuggestions:s}=this.state;return o.createElement("div",{className:`time-picker ${e||""}`},o.createElement("input",{className:`time-picker__input ${t}`,value:this.state.inputValue,onChange:this.onInputChange,onBlur:this.onInputBlur,onFocus:this.onInputFocus,onClick:this.onInputClick,ref:e=>{this.inputEl=e}}),(s&&n.length>0||this.suggestionsWrapperEl)&&this.renderSuggestions())}}r.defaultProps={allowOnlySuggestions:!1,appendTo:"body",hideOnScroll:!1,includeMax:!0,inputClass:"",maxTime:null,minTime:null,name:"",normalizeTime:!0,step:30,timeFormat:"hh:mma",value:null},t.default=r},function(e,t,n){"use strict";var o=n(5);function s(){}function i(){}i.resetWarningCache=s,e.exports=function(){function e(e,t,n,s,i,r){if(r!==o){var a=new Error("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");throw a.name="Invariant Violation",a}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:s};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){var o=n(7);"string"==typeof o&&(o=[[e.i,o,""]]);var s={hmr:!0,transform:void 0,insertInto:void 0};n(9)(o,s);o.locals&&(e.exports=o.locals)},function(e,t,n){(e.exports=n(8)(!1)).push([e.i,"",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"==typeof btoa){var s=(r=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */"),i=o.sources.map(function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"});return[n].concat(i).concat([s]).join("\n")}var r;return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},s=0;s<this.length;s++){var i=this[s][0];"number"==typeof i&&(o[i]=!0)}for(s=0;s<e.length;s++){var r=e[s];"number"==typeof r[0]&&o[r[0]]||(n&&!r[2]?r[2]=n:n&&(r[2]="("+r[2]+") and ("+n+")"),t.push(r))}},t}},function(e,t,n){var o,s,i={},r=(o=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===s&&(s=o.apply(this,arguments)),s}),a=function(e){var t={};return function(e,n){if("function"==typeof e)return e();if(void 0===t[e]){var o=function(e,t){return t?t.querySelector(e):document.querySelector(e)}.call(this,e,n);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}t[e]=o}return t[e]}}(),u=null,l=0,c=[],p=n(10);function h(e,t){for(var n=0;n<e.length;n++){var o=e[n],s=i[o.id];if(s){s.refs++;for(var r=0;r<s.parts.length;r++)s.parts[r](o.parts[r]);for(;r<o.parts.length;r++)s.parts.push(y(o.parts[r],t))}else{var a=[];for(r=0;r<o.parts.length;r++)a.push(y(o.parts[r],t));i[o.id]={id:o.id,refs:1,parts:a}}}}function d(e,t){for(var n=[],o={},s=0;s<e.length;s++){var i=e[s],r=t.base?i[0]+t.base:i[0],a={css:i[1],media:i[2],sourceMap:i[3]};o[r]?o[r].parts.push(a):n.push(o[r]={id:r,parts:[a]})}return n}function f(e,t){var n=a(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var o=c[c.length-1];if("top"===e.insertAt)o?o.nextSibling?n.insertBefore(t,o.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),c.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var s=a(e.insertAt.before,n);n.insertBefore(t,s)}}function g(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=c.indexOf(e);t>=0&&c.splice(t,1)}function m(e){var t=document.createElement("style");if(void 0===e.attrs.type&&(e.attrs.type="text/css"),void 0===e.attrs.nonce){var o=function(){0;return n.nc}();o&&(e.attrs.nonce=o)}return v(t,e.attrs),f(e,t),t}function v(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}function y(e,t){var n,o,s,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var r=l++;n=u||(u=m(t)),o=w.bind(null,n,r,!1),s=w.bind(null,n,r,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",v(t,e.attrs),f(e,t),t}(t),o=function(e,t,n){var o=n.css,s=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&s;(t.convertToAbsoluteUrls||i)&&(o=p(o));s&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(s))))+" */");var r=new Blob([o],{type:"text/css"}),a=e.href;e.href=URL.createObjectURL(r),a&&URL.revokeObjectURL(a)}.bind(null,n,t),s=function(){g(n),n.href&&URL.revokeObjectURL(n.href)}):(n=m(t),o=function(e,t){var n=t.css,o=t.media;o&&e.setAttribute("media",o);if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,n),s=function(){g(n)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else s()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=r()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=d(e,t);return h(n,t),function(e){for(var o=[],s=0;s<n.length;s++){var r=n[s];(a=i[r.id]).refs--,o.push(a)}e&&h(d(e,t),t);for(s=0;s<o.length;s++){var a;if(0===(a=o[s]).refs){for(var u=0;u<a.parts.length;u++)a.parts[u]();delete i[a.id]}}}};var b,S=(b=[],function(e,t){return b[e]=t,b.filter(Boolean).join("\n")});function w(e,t,n,o){var s=n?"":o.css;if(e.styleSheet)e.styleSheet.cssText=S(t,s);else{var i=document.createTextNode(s),r=e.childNodes;r[t]&&e.removeChild(r[t]),r.length?e.insertBefore(i,r[t]):e.appendChild(i)}}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,o=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var s,i=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(s=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:o+i.replace(/^\.\//,""),"url("+JSON.stringify(s)+")")})}},function(e,t,n){"use strict";n.r(t);var o=n(2),s=n.n(o),i=n(1),r=n.n(i),a=n(0),u=n.n(a),l=!("undefined"==typeof window||!window.document||!window.document.createElement),c=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();var p=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(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)}(t,r.a.Component),c(t,[{key:"componentWillUnmount",value:function(){this.defaultNode&&document.body.removeChild(this.defaultNode),this.defaultNode=null}},{key:"render",value:function(){return l?(this.props.node||this.defaultNode||(this.defaultNode=document.createElement("div"),document.body.appendChild(this.defaultNode)),s.a.createPortal(this.props.children,this.props.node||this.defaultNode)):null}}]),t}();p.propTypes={children:u.a.node.isRequired,node:u.a.any};var h=p,d=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();var f=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return function(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)}(t,r.a.Component),d(t,[{key:"componentDidMount",value:function(){this.renderPortal()}},{key:"componentDidUpdate",value:function(e){this.renderPortal()}},{key:"componentWillUnmount",value:function(){s.a.unmountComponentAtNode(this.defaultNode||this.props.node),this.defaultNode&&document.body.removeChild(this.defaultNode),this.defaultNode=null,this.portal=null}},{key:"renderPortal",value:function(e){this.props.node||this.defaultNode||(this.defaultNode=document.createElement("div"),document.body.appendChild(this.defaultNode));var t=this.props.children;"function"==typeof this.props.children.type&&(t=r.a.cloneElement(this.props.children)),this.portal=s.a.unstable_renderSubtreeIntoContainer(this,t,this.props.node||this.defaultNode)}},{key:"render",value:function(){return null}}]),t}(),g=f;f.propTypes={children:u.a.node.isRequired,node:u.a.any};var m=s.a.createPortal?h:g,v=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();var y=27,b=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(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}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.portalNode=null,n.state={active:!!e.defaultOpen},n.openPortal=n.openPortal.bind(n),n.closePortal=n.closePortal.bind(n),n.wrapWithPortal=n.wrapWithPortal.bind(n),n.handleOutsideMouseClick=n.handleOutsideMouseClick.bind(n),n.handleKeydown=n.handleKeydown.bind(n),n}return function(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)}(t,r.a.Component),v(t,[{key:"componentDidMount",value:function(){this.props.closeOnEsc&&document.addEventListener("keydown",this.handleKeydown),this.props.closeOnOutsideClick&&document.addEventListener("click",this.handleOutsideMouseClick)}},{key:"componentWillUnmount",value:function(){this.props.closeOnEsc&&document.removeEventListener("keydown",this.handleKeydown),this.props.closeOnOutsideClick&&document.removeEventListener("click",this.handleOutsideMouseClick)}},{key:"openPortal",value:function(e){this.state.active||(e&&e.nativeEvent&&e.nativeEvent.stopImmediatePropagation(),this.setState({active:!0},this.props.onOpen))}},{key:"closePortal",value:function(){this.state.active&&this.setState({active:!1},this.props.onClose)}},{key:"wrapWithPortal",value:function(e){var t=this;return this.state.active?r.a.createElement(m,{node:this.props.node,key:"react-portal",ref:function(e){return t.portalNode=e}},e):null}},{key:"handleOutsideMouseClick",value:function(e){if(this.state.active){var t=this.portalNode.props.node||this.portalNode.defaultNode;!t||t.contains(e.target)||e.button&&0!==e.button||this.closePortal()}}},{key:"handleKeydown",value:function(e){e.keyCode===y&&this.state.active&&this.closePortal()}},{key:"render",value:function(){return this.props.children({openPortal:this.openPortal,closePortal:this.closePortal,portal:this.wrapWithPortal,isOpen:this.state.active})}}]),t}();b.propTypes={children:u.a.func.isRequired,defaultOpen:u.a.bool,node:u.a.any,closeOnEsc:u.a.bool,closeOnOutsideClick:u.a.bool,onOpen:u.a.func,onClose:u.a.func},b.defaultProps={onOpen:function(){},onClose:function(){}};var S=b;n.d(t,"Portal",function(){return m}),n.d(t,"PortalWithState",function(){return S})}])});