UNPKG

react-toasts-forked-esm

Version:
1 lines 6.22 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],e):"object"==typeof exports?exports.MyLib=e(require("react"),require("react-dom")):t.MyLib=e(t.react,t["react-dom"])}(window,function(t,e){return function(t){var e={};function o(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){"use strict";function r(t){for(var o in t)e.hasOwnProperty(o)||(e[o]=t[o])}Object.defineProperty(e,"__esModule",{value:!0}),r(o(1)),r(o(5))},function(t,e,o){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)},function(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}),s=this&&this.__assign||function(){return(s=Object.assign||function(t){for(var e,o=1,r=arguments.length;o<r;o++)for(var n in e=arguments[o])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0});var i,a=o(2),c=o(3),u=o(4);!function(t){t.BOTTOM_CENTER="bottom_center",t.BOTTOM_LEFT="bottom_left",t.BOTTOM_RIGHT="bottom_right",t.TOP_CENTER="top_center",t.TOP_LEFT="top_left",t.TOP_RIGHT="top_right"}(i=e.ToastsContainerPosition||(e.ToastsContainerPosition={}));var f=function(t){function e(e){var o=t.call(this,e)||this;return o.state={styles:{},toasts:[]},o.storeSubscriptionId=-1,o.timeoutArray=[],o}return n(e,t),e.prototype.componentDidMount=function(){var t=this;this.storeSubscriptionId=this.props.store.watch(function(e){var o=s({},e,{id:Math.random()});t.setState({toasts:[o].concat(t.state.toasts)}),t.timeoutArray.push(setTimeout(function(){t.setState({toasts:t.state.toasts.filter(function(t){return t.id!==o.id})})},e.timer||3e3))});var e={};switch(this.props.position){case i.TOP_LEFT:e.top=10,e.left=10;break;case i.TOP_RIGHT:e.top=10,e.right=10;break;case i.TOP_CENTER:e.top=10,e.left="50%",e.transform="translateX(-50%)";break;case i.BOTTOM_LEFT:e.bottom=10,e.left=10;break;case i.BOTTOM_RIGHT:e.bottom=10,e.right=10;break;case i.BOTTOM_CENTER:e.bottom=10,e.left="50%",e.transform="translateX(-50%)";break;default:e.bottom=10,e.right=10}this.setState({styles:e})},e.prototype.componentWillUnmount=function(){this.props.store.unwatch(this.storeSubscriptionId),this.timeoutArray.forEach(clearTimeout)},e.prototype.render=function(){return c.createPortal(this._renderContainer(),document.body)},e.prototype._renderContainer=function(){var t=this.props.lightBackground?u.LightColors:u.DarkColors;return a.createElement("div",{style:this.state.styles,className:"toasts-container "+(this.props.className||"")},this.state.toasts.map(function(e){return a.createElement("div",{key:e.id,className:"toast toast-"+e.status+" "+e.classNames,style:t[e.status]},e.message)}))},e}(a.Component);e.ToastsContainer=f},function(e,o){e.exports=t},function(t,o){t.exports=e},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.LightColors={error:{backgroundColor:"#f2dede",borderColor:"#eed3d7",color:"#b94a48"},info:{backgroundColor:"#d9edf7",borderColor:"#bce8f1",color:"#3a87ad"},success:{backgroundColor:"#dff0d8",borderColor:"#d6e9c6",color:"#468847"},warning:{backgroundColor:"#fcf8e3",borderColor:"#fbeed5",color:"#c09853"}},e.DarkColors={error:{backgroundColor:"#e74c3c",borderColor:"#00000000",color:"#000000"},info:{backgroundColor:"#ecf0f1",borderColor:"#00000000",color:"#000000"},success:{backgroundColor:"#2ecc71",borderColor:"#00000000",color:"#000000"},warning:{backgroundColor:"#f1c40f",borderColor:"#00000000",color:"#000000"}}},function(t,e,o){"use strict";var r,n=this&&this.__extends||(r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)},function(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)});Object.defineProperty(e,"__esModule",{value:!0});var s=function(t){function e(){return t.call(this,{status:"",message:"",timer:0,classNames:""})||this}return n(e,t),e.prototype.success=function(t,e,o){this._toast("success",t,e,o)},e.prototype.info=function(t,e,o){this._toast("info",t,e,o)},e.prototype.warning=function(t,e,o){this._toast("warning",t,e,o)},e.prototype.error=function(t,e,o){this._toast("error",t,e,o)},e.prototype._toast=function(t,e,o,r){this.data={classNames:r||"",message:e,status:t,timer:o||3e3}},e}(o(6).WatchableStore);e.ToastsStore=new s},function(t,e,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(){function t(t){this._data=t,this._watchers=[],this._nextHandlerId=0}return Object.defineProperty(t.prototype,"data",{get:function(){return this._data},set:function(t){var e=this;this._data=t,this._watchers.forEach(function(t){t.trigger(e._data)})},enumerable:!0,configurable:!0}),t.prototype.watch=function(t){var e=this._nextHandlerId;return this._watchers.push({id:e,trigger:t}),this._nextHandlerId++,e},t.prototype.unwatch=function(t){for(var e=0;e<this._watchers.length;e++)if(this._watchers[e].id===t){this._watchers.splice(e,1);break}},t}();e.WatchableStore=r}])});