react-toastify
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("prop-types"),require("react-transition-group/TransitionGroup")):"function"==typeof define&&define.amd?define(["react","prop-types","react-transition-group/TransitionGroup"],t):"object"==typeof exports?exports.ReactOnScreen=t(require("react"),require("prop-types"),require("react-transition-group/TransitionGroup")):e.ReactOnScreen=t(e.react,e["prop-types"],e["react-transition-group/TransitionGroup"])}(this,function(e,t,n){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},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=11)}([function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default={POSITION:{TOP_LEFT:"top-left",TOP_RIGHT:"top-right",TOP_CENTER:"top-center",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right",BOTTOM_CENTER:"bottom-center"},TYPE:{INFO:"info",SUCCESS:"success",WARNING:"warning",ERROR:"error",DEFAULT:"default"},ACTION:{SHOW:"SHOW_TOAST",CLEAR:"CLEAR_TOAST"}}},function(e,n){e.exports=t},function(e,t,n){"use strict";function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var r={eventList:new Map,on:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return this.eventList.has(e)||this.eventList.set(e,[]),this.eventList.get(e).push({callback:t,context:n||this}),this},off:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(null!=e&&null==t)return this.eventList.delete(e);if(null!=e&&null!=t){var n=this.eventList.get(e);return this.eventList.set(e,n.filter(function(e){return!(e.callback===t||e.callback.toString()===t.toString())})),n.length>0||this.eventList.delete(e),!0}return null===e&&null===t&&(this.eventList.clear(),!0)},once:function(e,t,n){this.on(e,t,n);var o=this.eventList.get(e);return o[o.length-1].once=!0,this},emit:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(!this.eventList.has(e))return console.warn("<"+e+"> Event is not registered. Did you forgot to bind the event ?"),!1;var s=this.eventList.get(e);return this.eventList.set(e,s.filter(function(e){var t;return(t=e.callback).call.apply(t,[e.context].concat(o(n))),!e.once})),!0}};t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[];return Object.keys(e).forEach(function(n){return t.push(e[n])}),t}},function(e,t,n){"use strict";function o(e){return Object.prototype.toString.call(e).slice(8,-1)}function r(e){return"Number"===o(e)&&!isNaN(e)&&e>0}function s(e){return e.isRequired=function(t,n,o){if(void 0===t[n])return new Error("The prop "+n+" is marked as required in \n "+o+", but its value is undefined.");e(t,n,o)},e}Object.defineProperty(t,"__esModule",{value:!0}),t.falseOrElement=t.falseOrNumber=void 0,t.typeOf=o,t.isValidDelay=r;var i=n(0);t.falseOrNumber=s(function(e,t,n){var o=e[t];return!1===o||r(o)?null:new Error(n+" expect "+t+" \n to be a valid Number > 0 or equal to false. "+o+" given.")}),t.falseOrElement=s(function(e,t,n){var o=e[t];return!1===o||(0,i.isValidElement)(o)?null:new Error(n+" expect "+t+" \n to be a valid react element or equal to false. "+o+" given.")})},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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});var l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},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}}(),f=n(0),p=o(f),d=n(2),h=o(d),y=n(12),v=o(y),O=n(10),b=o(O),m=n(8),T=o(m),g=n(1),_=o(g),P=n(3),E=o(P),C=n(4),j=o(C),R=n(5),N=function(e){function t(e){i(this,t);var n=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.state={toast:[]},n.toastId=0,n.collection={},n}return a(t,e),c(t,[{key:"componentDidMount",value:function(){var e=this;E.default.on(_.default.ACTION.SHOW,function(t,n){return e.show(t,n)}).on(_.default.ACTION.CLEAR,function(){return e.clear()})}},{key:"componentWillUnmount",value:function(){E.default.off(_.default.ACTION.SHOW),E.default.off(_.default.ACTION.CLEAR)}},{key:"removeToast",value:function(e){this.setState({toast:this.state.toast.filter(function(t){return t!==parseInt(e,10)})})}},{key:"with",value:function(e,t){return(0,f.cloneElement)(e,l({},t,e.props))}},{key:"makeCloseButton",value:function(e,t){var n=this,o=this.props.closeButton;return((0,f.isValidElement)(e)||!1===e)&&(o=e),!1!==o&&this.with(o,{closeToast:function(){return n.removeToast(t)}})}},{key:"getAutoCloseDelay",value:function(e){return!1===e||(0,R.isValidDelay)(e)?e:this.props.autoClose}},{key:"isFunction",value:function(e){return!!(e&&e.constructor&&e.call&&e.apply)}},{key:"canBeRendered",value:function(e){return(0,f.isValidElement)(e)||"String"===(0,R.typeOf)(e)||"Number"===(0,R.typeOf)(e)}},{key:"show",value:function(e,t){var n=this;if(this.canBeRendered(e)){var o=++this.toastId,i=function(){return n.removeToast(o)},u={id:o,type:t.type,closeButton:this.makeCloseButton(t.closeButton,o)};this.isFunction(t.onOpen)&&(u.onOpen=t.onOpen),this.isFunction(t.onClose)&&(u.onClose=t.onClose),u.autoClose=this.getAutoCloseDelay(!1!==t.autoClose?parseInt(t.autoClose,10):t.autoClose),u.hideProgressBar="boolean"==typeof t.hideProgressBar?t.hideProgressBar:this.props.hideProgressBar,u.closeToast=i,(0,f.isValidElement)(e)&&"String"!==(0,R.typeOf)(e.type)&&(e=this.with(e,{closeToast:i})),this.collection=Object.assign({},this.collection,s({},o,this.makeToast(e,u))),this.setState({toast:[].concat(r(this.state.toast),[o])})}}},{key:"makeToast",value:function(e,t){return p.default.createElement(b.default,l({},t,{position:this.props.position,key:"toast-"+t.id+" "}),e)}},{key:"clear",value:function(){this.collection={},this.setState({toast:[]})}},{key:"hasToast",value:function(){return this.state.toast.length>0}},{key:"renderProps",value:function(){var e={className:"toastify toastify--"+this.props.position};return this.hasToast()||(e.style={pointerEvents:"none"}),null!==this.props.className&&(e.className=e.className+" "+this.props.className),null!==this.props.style&&(e.style=Object.assign({},this.props.style,void 0!==e.style?e.style:{})),e}},{key:"renderToast",value:function(){var e=this,t=[];return Object.keys(this.collection).forEach(function(n){e.state.toast.includes(parseInt(n,10))?t.push(e.collection[n]):delete e.collection[n]}),t}},{key:"render",value:function(){return p.default.createElement("div",this.renderProps(),p.default.createElement(v.default,null,this.hasToast()?this.renderToast():null))}}]),t}(f.Component);N.propTypes={position:h.default.oneOf((0,j.default)(_.default.POSITION)),autoClose:R.falseOrNumber,closeButton:R.falseOrElement,hideProgressBar:h.default.bool,className:h.default.string,style:h.default.object},N.defaultProps={position:_.default.POSITION.TOP_RIGHT,autoClose:5e3,hideProgressBar:!1,closeButton:p.default.createElement(T.default,null),className:null,style:null},t.default=N},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){return Object.assign({},p,e)}Object.defineProperty(t,"__esModule",{value:!0});var s=n(3),i=o(s),u=n(1),a=o(u),l=a.default.POSITION,c=a.default.TYPE,f=a.default.ACTION,p={type:c.DEFAULT,autoClose:null,closeButton:null,hideProgressBar:null},d=function(e,t){return i.default.emit(f.SHOW,e,t)};t.default=Object.assign(function(e,t){return d(e,r(t))},{success:function(e,t){return d(e,Object.assign(r(t),{type:c.SUCCESS}))},info:function(e,t){return d(e,Object.assign(r(t),{type:c.INFO}))},warn:function(e,t){return d(e,Object.assign(r(t),{type:c.WARNING}))},error:function(e,t){return d(e,Object.assign(r(t),{type:c.ERROR}))},dismiss:function(){return i.default.emit(f.CLEAR)}},{POSITION:l,TYPE:c})},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){var t=e.closeToast;return i.default.createElement("button",{className:"toastify__close",type:"button",onClick:t},"✖")}Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),i=o(s),u=n(2),a=o(u);r.propTypes={closeToast:a.default.func},t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){var t=e.delay,n=e.isRunning,o=e.closeToast,r=e.type,s=e.hide,u={animationDuration:t+"ms",animationPlayState:n?"running":"paused"};return u.WebkitAnimationPlayState=u.animationPlayState,s&&(u.opacity=0),i.default.createElement("div",{className:"toastify__progress toastify__progress--"+r,style:u,onAnimationEnd:o})}Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),i=o(s),u=n(2),a=o(u),l=n(1),c=o(l);r.propTypes={delay:a.default.number.isRequired,isRunning:a.default.bool.isRequired,closeToast:a.default.func.isRequired,type:a.default.string,hide:a.default.bool},r.defaultProps={type:c.default.TYPE.DEFAULT,hide:!1},t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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 i(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});var u=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}}(),a=n(0),l=o(a),c=n(2),f=o(c),p=n(9),d=o(p),h=n(1),y=o(h),v=n(4),O=o(v),b=n(5),m=function(e){function t(e){r(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.setRef=function(e){n.ref=e},n.pauseToast=function(){n.setState({isRunning:!1})},n.playToast=function(){n.setState({isRunning:!0})},n.ref=null,n.state={isRunning:!0},n}return i(t,e),u(t,[{key:"componentDidMount",value:function(){null!==this.props.onOpen&&this.props.onOpen(this.getChildrenProps())}},{key:"componentWillUnmount",value:function(){null!==this.props.onClose&&this.props.onClose(this.getChildrenProps())}},{key:"getChildrenProps",value:function(){return this.props.children.props}},{key:"getToastProps",value:function(){var e={className:"toastify-content toastify-content--"+this.props.type,ref:this.setRef};return!1!==this.props.autoClose&&(e.onMouseEnter=this.pauseToast,e.onMouseLeave=this.playToast),e}},{key:"componentWillEnter",value:function(e){this.ref.classList.add("toast-enter--"+this.props.position,"animated"),e()}},{key:"componentWillLeave",value:function(e){this.ref.classList.remove("toast-enter--"+this.props.position,"animated"),this.ref.classList.add("toast-exit--"+this.props.position,"animated"),setTimeout(function(){return e()},750)}},{key:"render",value:function(){var e=this.props,t=e.closeButton,n=e.children,o=e.autoClose,r=e.type,s=e.hideProgressBar,i=e.closeToast;return l.default.createElement("div",this.getToastProps(),!1!==t&&t,l.default.createElement("div",{className:"toastify__body"},n),!1!==o&&l.default.createElement(d.default,{delay:o,isRunning:this.state.isRunning,closeToast:i,hide:s,type:r}))}}]),t}(a.Component);m.propTypes={closeButton:b.falseOrElement.isRequired,autoClose:b.falseOrNumber.isRequired,children:f.default.node.isRequired,closeToast:f.default.func.isRequired,position:f.default.oneOf((0,O.default)(y.default.POSITION)).isRequired,hideProgressBar:f.default.bool,onOpen:f.default.func,onClose:f.default.func,type:f.default.oneOf((0,O.default)(y.default.TYPE))},m.defaultProps={type:y.default.TYPE.DEFAULT,hideProgressBar:!1,onOpen:null,onClose:null},t.default=m},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.toast=t.ToastContainer=void 0;var r=n(6),s=o(r),i=n(7),u=o(i);t.ToastContainer=s.default,t.toast=u.default},function(e,t){e.exports=n}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("prop-types"),require("react-transition-group/TransitionGroup")):"function"==typeof define&&define.amd?define(["react","prop-types","react-transition-group/TransitionGroup"],t):"object"==typeof exports?exports.ReactOnScreen=t(require("react"),require("prop-types"),require("react-transition-group/TransitionGroup")):e.ReactOnScreen=t(e.react,e["prop-types"],e["react-transition-group/TransitionGroup"])}(this,function(e,t,n){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},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=11)}([function(t,n){t.exports=e},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default={POSITION:{TOP_LEFT:"top-left",TOP_RIGHT:"top-right",TOP_CENTER:"top-center",BOTTOM_LEFT:"bottom-left",BOTTOM_RIGHT:"bottom-right",BOTTOM_CENTER:"bottom-center"},TYPE:{INFO:"info",SUCCESS:"success",WARNING:"warning",ERROR:"error",DEFAULT:"default"},ACTION:{SHOW:"SHOW_TOAST",CLEAR:"CLEAR_TOAST",MOUNTED:"CONTAINER_MOUNTED"}}},function(e,n){e.exports=t},function(e,t,n){"use strict";function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}Object.defineProperty(t,"__esModule",{value:!0});var r={eventList:new Map,on:function(e,t){return this.eventList.has(e)||this.eventList.set(e,[]),this.eventList.get(e).push(t),this},off:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return this.eventList.delete(e)},emit:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),s=1;s<n;s++)r[s-1]=arguments[s];return this.eventList.has(e)?(this.eventList.get(e).forEach(function(e){return setTimeout(function(){return e.call.apply(e,[t].concat(o(r)))},0)}),!0):(console.warn("<"+e+"> Event is not registered. Did you forgot to bind the event ?"),!1)}};t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=[];return Object.keys(e).forEach(function(n){return t.push(e[n])}),t}},function(e,t,n){"use strict";function o(e){return Object.prototype.toString.call(e).slice(8,-1)}function r(e){return"Number"===o(e)&&!isNaN(e)&&e>0}function s(e){return e.isRequired=function(t,n,o){if(void 0===t[n])return new Error("The prop "+n+" is marked as required in \n "+o+", but its value is undefined.");e(t,n,o)},e}Object.defineProperty(t,"__esModule",{value:!0}),t.falseOrElement=t.falseOrNumber=void 0,t.typeOf=o,t.isValidDelay=r;var i=n(0);t.falseOrNumber=s(function(e,t,n){var o=e[t];return!1===o||r(o)?null:new Error(n+" expect "+t+" \n to be a valid Number > 0 or equal to false. "+o+" given.")}),t.falseOrElement=s(function(e,t,n){var o=e[t];return!1===o||(0,i.isValidElement)(o)?null:new Error(n+" expect "+t+" \n to be a valid react element or equal to false. "+o+" given.")})},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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});var l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},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}}(),f=n(0),p=o(f),d=n(2),y=o(d),h=n(12),O=o(h),v=n(10),m=o(v),T=n(8),b=o(T),g=n(1),_=o(g),E=n(3),P=o(E),C=n(4),N=o(C),R=n(5),j=function(e){function t(e){i(this,t);var n=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.state={toast:[]},n.collection={},n}return a(t,e),c(t,[{key:"componentDidMount",value:function(){var e=this;P.default.on(_.default.ACTION.SHOW,function(t,n){return e.show(t,n)}).on(_.default.ACTION.CLEAR,function(t){return null!==t?e.removeToast(t):e.clear()}).emit(_.default.ACTION.MOUNTED)}},{key:"componentWillUnmount",value:function(){P.default.off(_.default.ACTION.SHOW),P.default.off(_.default.ACTION.CLEAR)}},{key:"removeToast",value:function(e){this.setState({toast:this.state.toast.filter(function(t){return t!==parseInt(e,10)})})}},{key:"with",value:function(e,t){return(0,f.cloneElement)(e,l({},t,e.props))}},{key:"makeCloseButton",value:function(e,t){var n=this,o=this.props.closeButton;return((0,f.isValidElement)(e)||!1===e)&&(o=e),!1!==o&&this.with(o,{closeToast:function(){return n.removeToast(t)}})}},{key:"getAutoCloseDelay",value:function(e){return!1===e||(0,R.isValidDelay)(e)?e:this.props.autoClose}},{key:"isFunction",value:function(e){return!!(e&&e.constructor&&e.call&&e.apply)}},{key:"canBeRendered",value:function(e){return(0,f.isValidElement)(e)||"String"===(0,R.typeOf)(e)||"Number"===(0,R.typeOf)(e)}},{key:"show",value:function(e,t){var n=this;if(this.canBeRendered(e)){var o=t.toastId,i=function(){return n.removeToast(o)},u={id:o,type:t.type,closeButton:this.makeCloseButton(t.closeButton,o)};this.isFunction(t.onOpen)&&(u.onOpen=t.onOpen),this.isFunction(t.onClose)&&(u.onClose=t.onClose),u.autoClose=this.getAutoCloseDelay(!1!==t.autoClose?parseInt(t.autoClose,10):t.autoClose),u.hideProgressBar="boolean"==typeof t.hideProgressBar?t.hideProgressBar:this.props.hideProgressBar,u.closeToast=i,(0,f.isValidElement)(e)&&"String"!==(0,R.typeOf)(e.type)&&(e=this.with(e,{closeToast:i})),this.collection=Object.assign({},this.collection,s({},o,this.makeToast(e,u))),this.setState({toast:[].concat(r(this.state.toast),[o])})}}},{key:"makeToast",value:function(e,t){return p.default.createElement(m.default,l({},t,{position:this.props.position,key:"toast-"+t.id+" "}),e)}},{key:"clear",value:function(){this.collection={},this.setState({toast:[]})}},{key:"hasToast",value:function(){return this.state.toast.length>0}},{key:"renderProps",value:function(){var e={className:"toastify toastify--"+this.props.position};return this.hasToast()||(e.style={pointerEvents:"none"}),null!==this.props.className&&(e.className=e.className+" "+this.props.className),null!==this.props.style&&(e.style=Object.assign({},this.props.style,void 0!==e.style?e.style:{})),e}},{key:"renderToast",value:function(){var e=this,t=[];return Object.keys(this.collection).forEach(function(n){e.state.toast.includes(parseInt(n,10))?t.push(e.collection[n]):delete e.collection[n]}),t}},{key:"render",value:function(){return p.default.createElement("div",this.renderProps(),p.default.createElement(O.default,null,this.hasToast()?this.renderToast():null))}}]),t}(f.Component);j.propTypes={position:y.default.oneOf((0,N.default)(_.default.POSITION)),autoClose:R.falseOrNumber,closeButton:R.falseOrElement,hideProgressBar:y.default.bool,className:y.default.string,style:y.default.object},j.defaultProps={position:_.default.POSITION.TOP_RIGHT,autoClose:5e3,hideProgressBar:!1,closeButton:p.default.createElement(b.default,null),className:null,style:null},t.default=j},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){return Object.assign({},p,e,{toastId:++h})}Object.defineProperty(t,"__esModule",{value:!0});var s=n(3),i=o(s),u=n(1),a=o(u),l=a.default.POSITION,c=a.default.TYPE,f=a.default.ACTION,p={type:c.DEFAULT,autoClose:null,closeButton:null,hideProgressBar:null},d=!1,y=[],h=0;i.default.on(f.MOUNTED,function(){d=!0,y.forEach(function(e){i.default.emit(e.action,e.content,e.options)}),y=[]});var O=function(e,t){return d?i.default.emit(f.SHOW,e,t):y.push({action:f.SHOW,content:e,options:t}),t.toastId};t.default=Object.assign(function(e,t){return O(e,r(t))},{success:function(e,t){return O(e,Object.assign(r(t),{type:c.SUCCESS}))},info:function(e,t){return O(e,Object.assign(r(t),{type:c.INFO}))},warn:function(e,t){return O(e,Object.assign(r(t),{type:c.WARNING}))},error:function(e,t){return O(e,Object.assign(r(t),{type:c.ERROR}))},dismiss:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return i.default.emit(f.CLEAR,e)}},{POSITION:l,TYPE:c})},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){var t=e.closeToast;return i.default.createElement("button",{className:"toastify__close",type:"button",onClick:t},"✖")}Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),i=o(s),u=n(2),a=o(u);r.propTypes={closeToast:a.default.func},t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e){var t=e.delay,n=e.isRunning,o=e.closeToast,r=e.type,s=e.hide,u={animationDuration:t+"ms",animationPlayState:n?"running":"paused"};return u.WebkitAnimationPlayState=u.animationPlayState,s&&(u.opacity=0),i.default.createElement("div",{className:"toastify__progress toastify__progress--"+r,style:u,onAnimationEnd:o})}Object.defineProperty(t,"__esModule",{value:!0});var s=n(0),i=o(s),u=n(2),a=o(u),l=n(1),c=o(l);r.propTypes={delay:a.default.number.isRequired,isRunning:a.default.bool.isRequired,closeToast:a.default.func.isRequired,type:a.default.string,hide:a.default.bool},r.defaultProps={type:c.default.TYPE.DEFAULT,hide:!1},t.default=r},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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 i(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});var u=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}}(),a=n(0),l=o(a),c=n(2),f=o(c),p=n(9),d=o(p),y=n(1),h=o(y),O=n(4),v=o(O),m=n(5),T=function(e){function t(e){r(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.setRef=function(e){n.ref=e},n.pauseToast=function(){n.setState({isRunning:!1})},n.playToast=function(){n.setState({isRunning:!0})},n.ref=null,n.state={isRunning:!0},n}return i(t,e),u(t,[{key:"componentDidMount",value:function(){null!==this.props.onOpen&&this.props.onOpen(this.getChildrenProps())}},{key:"componentWillUnmount",value:function(){null!==this.props.onClose&&this.props.onClose(this.getChildrenProps())}},{key:"getChildrenProps",value:function(){return this.props.children.props}},{key:"getToastProps",value:function(){var e={className:"toastify-content toastify-content--"+this.props.type,ref:this.setRef};return!1!==this.props.autoClose&&(e.onMouseEnter=this.pauseToast,e.onMouseLeave=this.playToast),e}},{key:"componentWillEnter",value:function(e){this.ref.classList.add("toast-enter--"+this.props.position,"toastify-animated"),e()}},{key:"componentWillLeave",value:function(e){this.ref.classList.remove("toast-enter--"+this.props.position,"toastify-animated"),this.ref.classList.add("toast-exit--"+this.props.position,"toastify-animated"),setTimeout(function(){return e()},750)}},{key:"render",value:function(){var e=this.props,t=e.closeButton,n=e.children,o=e.autoClose,r=e.type,s=e.hideProgressBar,i=e.closeToast;return l.default.createElement("div",this.getToastProps(),!1!==t&&t,l.default.createElement("div",{className:"toastify__body"},n),!1!==o&&l.default.createElement(d.default,{delay:o,isRunning:this.state.isRunning,closeToast:i,hide:s,type:r}))}}]),t}(a.Component);T.propTypes={closeButton:m.falseOrElement.isRequired,autoClose:m.falseOrNumber.isRequired,children:f.default.node.isRequired,closeToast:f.default.func.isRequired,position:f.default.oneOf((0,v.default)(h.default.POSITION)).isRequired,hideProgressBar:f.default.bool,onOpen:f.default.func,onClose:f.default.func,type:f.default.oneOf((0,v.default)(h.default.TYPE))},T.defaultProps={type:h.default.TYPE.DEFAULT,hideProgressBar:!1,onOpen:null,onClose:null},t.default=T},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.toast=t.ToastContainer=void 0;var r=n(6),s=o(r),i=n(7),u=o(i);t.ToastContainer=s.default,t.toast=u.default},function(e,t){e.exports=n}])}); | ||
//# sourceMappingURL=ReactToastify.min.js.map |
@@ -24,4 +24,5 @@ 'use strict'; | ||
SHOW: 'SHOW_TOAST', | ||
CLEAR: 'CLEAR_TOAST' | ||
CLEAR: 'CLEAR_TOAST', | ||
MOUNTED: 'CONTAINER_MOUNTED' | ||
} | ||
}; |
@@ -99,3 +99,3 @@ 'use strict'; | ||
value: function componentWillEnter(callback) { | ||
this.ref.classList.add('toast-enter--' + this.props.position, 'animated'); | ||
this.ref.classList.add('toast-enter--' + this.props.position, 'toastify-animated'); | ||
callback(); | ||
@@ -106,4 +106,4 @@ } | ||
value: function componentWillLeave(callback) { | ||
this.ref.classList.remove('toast-enter--' + this.props.position, 'animated'); | ||
this.ref.classList.add('toast-exit--' + this.props.position, 'animated'); | ||
this.ref.classList.remove('toast-enter--' + this.props.position, 'toastify-animated'); | ||
this.ref.classList.add('toast-exit--' + this.props.position, 'toastify-animated'); | ||
setTimeout(function () { | ||
@@ -110,0 +110,0 @@ return callback(); |
@@ -68,3 +68,2 @@ 'use strict'; | ||
}; | ||
_this.toastId = 0; | ||
_this.collection = {}; | ||
@@ -81,5 +80,5 @@ return _this; | ||
return _this2.show(content, options); | ||
}).on(_config2.default.ACTION.CLEAR, function () { | ||
return _this2.clear(); | ||
}); | ||
}).on(_config2.default.ACTION.CLEAR, function (id) { | ||
return id !== null ? _this2.removeToast(id) : _this2.clear(); | ||
}).emit(_config2.default.ACTION.MOUNTED); | ||
} | ||
@@ -149,3 +148,3 @@ }, { | ||
if (this.canBeRendered(content)) { | ||
var toastId = ++this.toastId; | ||
var toastId = options.toastId; | ||
var closeToast = function closeToast() { | ||
@@ -152,0 +151,0 @@ return _this4.removeToast(toastId); |
@@ -35,8 +35,26 @@ 'use strict'; | ||
var isContainerMounted = false; | ||
var queue = []; | ||
var toastId = 0; | ||
function mergeOptions(options) { | ||
return Object.assign({}, defaultOptions, options); | ||
return Object.assign({}, defaultOptions, options, { toastId: ++toastId }); | ||
} | ||
_EventManager2.default.on(ACTION.MOUNTED, function () { | ||
isContainerMounted = true; | ||
queue.forEach(function (item) { | ||
_EventManager2.default.emit(item.action, item.content, item.options); | ||
}); | ||
queue = []; | ||
}); | ||
var emitEvent = function emitEvent(content, options) { | ||
return _EventManager2.default.emit(ACTION.SHOW, content, options); | ||
if (isContainerMounted) { | ||
_EventManager2.default.emit(ACTION.SHOW, content, options); | ||
} else { | ||
queue.push({ action: ACTION.SHOW, content: content, options: options }); | ||
} | ||
return options.toastId; | ||
}; | ||
@@ -60,3 +78,4 @@ | ||
dismiss: function dismiss() { | ||
return _EventManager2.default.emit(ACTION.CLEAR); | ||
var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
return _EventManager2.default.emit(ACTION.CLEAR, id); | ||
} | ||
@@ -63,0 +82,0 @@ }, { |
@@ -12,74 +12,17 @@ "use strict"; | ||
/** | ||
* Bind event | ||
* | ||
* @param event | ||
* @param callback | ||
* @param context | ||
* @returns {eventManager.on} | ||
*/ | ||
on: function on(event, callback) { | ||
var context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
this.eventList.has(event) || this.eventList.set(event, []); | ||
this.eventList.get(event).push({ | ||
callback: callback, | ||
context: context || this | ||
}); | ||
this.eventList.get(event).push(callback); | ||
return this; | ||
}, | ||
/** | ||
* Unbind events | ||
* Strict comparison voluntary omitted to check both null and undefined | ||
* | ||
* @param event | ||
* @param callback | ||
* @returns {boolean} | ||
*/ | ||
off: function off() { | ||
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (event != null && callback == null) { | ||
return this.eventList.delete(event); | ||
} else if (event != null && callback != null) { | ||
var listeners = this.eventList.get(event); | ||
this.eventList.set(event, listeners.filter(function (el) { | ||
return !(el.callback === callback || el.callback.toString() === callback.toString()); | ||
})); | ||
listeners.length > 0 || this.eventList.delete(event); | ||
return true; | ||
} else if (event === null && callback === null) { | ||
this.eventList.clear(); | ||
return true; | ||
} | ||
return false; | ||
return this.eventList.delete(event); | ||
}, | ||
emit: function emit(event) { | ||
var _this = this; | ||
/** | ||
* @param event | ||
* @param callback | ||
* @param context | ||
* @returns {eventManager.once} | ||
*/ | ||
once: function once(event, callback, context) { | ||
this.on(event, callback, context); | ||
var listener = this.eventList.get(event); | ||
var idx = listener.length - 1; | ||
listener[idx].once = true; | ||
return this; | ||
}, | ||
/** | ||
* @param event | ||
* @param args | ||
* @returns {boolean} | ||
*/ | ||
emit: function emit(event) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -94,11 +37,9 @@ args[_key - 1] = arguments[_key]; | ||
} | ||
var listeners = this.eventList.get(event); | ||
this.eventList.set(event, listeners.filter(function (listener) { | ||
var _listener$callback; | ||
this.eventList.get(event).forEach(function (callback) { | ||
return setTimeout(function () { | ||
return callback.call.apply(callback, [_this].concat(_toConsumableArray(args))); | ||
}, 0); | ||
}); | ||
(_listener$callback = listener.callback).call.apply(_listener$callback, [listener.context].concat(_toConsumableArray(args))); | ||
return !listener.once; | ||
})); | ||
return true; | ||
@@ -105,0 +46,0 @@ } |
{ | ||
"name": "react-toastify", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "React notification made easy", | ||
@@ -23,3 +23,3 @@ "keywords": [ | ||
"prestyle": "sass src/scss/main.scss dist/ReactToastify.css", | ||
"style": "postcss --use autoprefixer -b 'last 2 versions' < dist/ReactToastify.css | postcss --use cssnano > dist/ReactToastify.min.css" | ||
"style": "postcss --use autoprefixer -b 'last 2 versions' < dist/ReactToastify.css | cssnano --no-reduceIdents > dist/ReactToastify.min.css" | ||
}, | ||
@@ -49,4 +49,4 @@ "repository": { | ||
"babel-preset-stage-0": "^6.5.0", | ||
"chai": "^3.5.0", | ||
"cssnano": "^3.8.0", | ||
"cssnano-cli": "^1.0.5", | ||
"enzyme": "^2.8.2", | ||
@@ -59,5 +59,2 @@ "eslint": "^3.2.2", | ||
"jest": "^20.0.1", | ||
"jsdom": "^10.1.0", | ||
"karma": "^1.2.0", | ||
"mocha": "^3.0.2", | ||
"postcss": "^5.2.5", | ||
@@ -64,0 +61,0 @@ "postcss-cli": "^3.2.0", |
@@ -37,2 +37,3 @@ # React Toastify [![Build Status](https://travis-ci.org/fkhadra/react-toastify.svg?branch=master)](https://travis-ci.org/fkhadra/react-toastify) [![npm](https://img.shields.io/npm/dt/react-toastify.svg)]() [![npm](https://img.shields.io/npm/v/react-toastify.svg)]() [![license](https://img.shields.io/github/license/fkhadra/react-toastify.svg?maxAge=2592000)]() | ||
- Can be positioned | ||
- Can remove toast programmatically | ||
- Define behavior per toast | ||
@@ -101,6 +102,6 @@ - Easy to setup | ||
|style|object|-|Add optional inline style to the container| | ||
|closeButton|React Element|-|A React Component to replace the default close button| | ||
|closeButton|React Element\|false|-|A React Component to replace the default close button or `false` to hide the button| | ||
|hideProgressBar|bool|false|Display or not the progress bar below the toast(remaining time)| | ||
|removeCloseButton|bool|false|If you don't want the toast to render a close button| | ||
- Position accept the following value : | ||
@@ -140,3 +141,4 @@ | ||
All the function inside toast can take 2 parameters : | ||
All the method of toast return a **toastId** except `dismiss`. The **toastId** can be used to remove a toast programmatically. | ||
All the method but `dismiss` can take 2 parameters : | ||
@@ -168,4 +170,5 @@ |Parameter|Type|Required|Description| | ||
}; | ||
toast(<Img foo={bar}/>, options) // default, type: 'default' | ||
// each method return a toast id except dismiss. | ||
const toastId = toast(<Img foo={bar}/>, options) // default, type: 'default' | ||
toast.success("Hello", options) // add type: 'success' to options | ||
@@ -176,2 +179,3 @@ toast.info("World", options) // add type: 'info' to options | ||
toast.dismiss() // Remove all toasts ! | ||
toast.dismiss(toastId) // Remove given toast | ||
``` | ||
@@ -182,2 +186,16 @@ | ||
### v1.6.0 | ||
#### New Features | ||
- Can now remove a toast programmatically. When you display a toast, the function return a **toastId**. You can use it | ||
as follow to remove a given toast `toast.dismiss(toastId)` | ||
- If the container is not mounted, the notification will be added to a queue and dispatched as soon as the container is mounted. | ||
For more details check [issue #4](https://github.com/fkhadra/react-toastify/issues/4) | ||
#### Others | ||
- Added --no-idents flag to cssnano to avoid animation name collision with others libs. | ||
- Tests are no longer transpiled | ||
### v1.5.0 | ||
@@ -184,0 +202,0 @@ |
@@ -19,4 +19,5 @@ export default { | ||
SHOW: 'SHOW_TOAST', | ||
CLEAR: 'CLEAR_TOAST' | ||
CLEAR: 'CLEAR_TOAST', | ||
MOUNTED: 'CONTAINER_MOUNTED' | ||
} | ||
}; |
@@ -68,3 +68,3 @@ import React, { Component } from 'react'; | ||
componentWillEnter(callback) { | ||
this.ref.classList.add(`toast-enter--${this.props.position}`, 'animated'); | ||
this.ref.classList.add(`toast-enter--${this.props.position}`, 'toastify-animated'); | ||
callback(); | ||
@@ -75,4 +75,4 @@ } | ||
this.ref.classList.remove(`toast-enter--${this.props.position}`, | ||
'animated'); | ||
this.ref.classList.add(`toast-exit--${this.props.position}`, 'animated'); | ||
'toastify-animated'); | ||
this.ref.classList.add(`toast-exit--${this.props.position}`, 'toastify-animated'); | ||
setTimeout(() => callback(), 750); | ||
@@ -79,0 +79,0 @@ } |
@@ -69,3 +69,2 @@ import React, { | ||
}; | ||
this.toastId = 0; | ||
this.collection = {}; | ||
@@ -75,5 +74,8 @@ } | ||
componentDidMount() { | ||
EventManager.on(config.ACTION.SHOW, | ||
EventManager | ||
.on(config.ACTION.SHOW, | ||
(content, options) => this.show(content, options)) | ||
.on(config.ACTION.CLEAR, () => this.clear()); | ||
.on(config.ACTION.CLEAR, | ||
id => (id !== null ? this.removeToast(id) : this.clear())) | ||
.emit(config.ACTION.MOUNTED); | ||
} | ||
@@ -131,3 +133,3 @@ | ||
if (this.canBeRendered(content)) { | ||
const toastId = ++this.toastId; | ||
const toastId = options.toastId; | ||
const closeToast = () => this.removeToast(toastId); | ||
@@ -134,0 +136,0 @@ const toastOptions = { |
@@ -19,8 +19,28 @@ /* | ||
let isContainerMounted = false; | ||
let queue = []; | ||
let toastId = 0; | ||
function mergeOptions(options) { | ||
return Object.assign({}, defaultOptions, options); | ||
return Object.assign({}, defaultOptions, options, { toastId: ++toastId }); | ||
} | ||
const emitEvent = (content, options) => EventManager.emit(ACTION.SHOW, content, options); | ||
EventManager.on(ACTION.MOUNTED, () => { | ||
isContainerMounted = true; | ||
queue.forEach(item => { | ||
EventManager.emit(item.action, item.content, item.options); | ||
}); | ||
queue = []; | ||
}); | ||
const emitEvent = (content, options) => { | ||
if (isContainerMounted) { | ||
EventManager.emit(ACTION.SHOW, content, options); | ||
} else { | ||
queue.push({ action: ACTION.SHOW, content, options }); | ||
} | ||
return options.toastId; | ||
}; | ||
export default Object.assign( | ||
@@ -33,3 +53,3 @@ (content, options) => emitEvent(content, mergeOptions(options)), | ||
error: (content, options) => emitEvent(content, Object.assign(mergeOptions(options), { type: TYPE.ERROR })), | ||
dismiss: () => EventManager.emit(ACTION.CLEAR) | ||
dismiss: (id = null) => EventManager.emit(ACTION.CLEAR, id) | ||
}, | ||
@@ -36,0 +56,0 @@ { |
@@ -5,17 +5,6 @@ | ||
/** | ||
* Bind event | ||
* | ||
* @param event | ||
* @param callback | ||
* @param context | ||
* @returns {eventManager.on} | ||
*/ | ||
on(event, callback, context = null) { | ||
on(event, callback) { | ||
this.eventList.has(event) || this.eventList.set(event, []); | ||
this.eventList.get(event).push({ | ||
callback, | ||
context: context || this | ||
}); | ||
this.eventList.get(event).push(callback); | ||
@@ -25,46 +14,6 @@ return this; | ||
/** | ||
* Unbind events | ||
* Strict comparison voluntary omitted to check both null and undefined | ||
* | ||
* @param event | ||
* @param callback | ||
* @returns {boolean} | ||
*/ | ||
off(event = null, callback = null) { | ||
if (event != null && callback == null) { | ||
return this.eventList.delete(event); | ||
} else if (event != null && callback != null) { | ||
const listeners = this.eventList.get(event); | ||
off(event = null) { | ||
return this.eventList.delete(event); | ||
}, | ||
this.eventList.set(event, listeners.filter(el => | ||
!(el.callback === callback || el.callback.toString() === callback.toString()) | ||
)); | ||
listeners.length > 0 || this.eventList.delete(event); | ||
return true; | ||
} else if (event === null && callback === null) { | ||
this.eventList.clear(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
/** | ||
* @param event | ||
* @param callback | ||
* @param context | ||
* @returns {eventManager.once} | ||
*/ | ||
once(event, callback, context) { | ||
this.on(event, callback, context); | ||
const listener = this.eventList.get(event); | ||
const idx = listener.length - 1; | ||
listener[idx].once = true; | ||
return this; | ||
}, | ||
/** | ||
* @param event | ||
* @param args | ||
* @returns {boolean} | ||
*/ | ||
emit(event, ...args) { | ||
@@ -76,8 +25,6 @@ if (!this.eventList.has(event)) { | ||
} | ||
const listeners = this.eventList.get(event); | ||
this.eventList.set(event, listeners.filter(listener => { | ||
listener.callback.call(listener.context, ...args); | ||
return !listener.once; | ||
})); | ||
this.eventList | ||
.get(event) | ||
.forEach(callback => setTimeout(() => callback.call(this, ...args), 0)); | ||
@@ -84,0 +31,0 @@ return true; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24
277
339724
42
1424