react-toastify
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-addons-transition-group")):"function"==typeof define&&define.amd?define(["react","react-addons-transition-group"],t):"object"==typeof exports?exports.ReactToastify=t(require("react"),require("react-addons-transition-group")):e.ReactToastify=t(e.React,e.React.addons.TransitionGroup)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([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(5),s=o(r),a=n(6),i=o(a);t.ToastContainer=s.default,t.toast=i.default},function(e,t){"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,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n={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),r=o.length-1;return o[r].once=!0,this},emit:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(!this.eventList.has(e))return console.warn("<"+e+"> Event is not registered. Did you forgot to bind the event ?"),!1;var r=this.eventList.get(e);return this.eventList.set(e,r.filter(function(e){var t;return(t=e.callback).call.apply(t,[e.context].concat(n)),!e.once})),!0}};t.default=n},function(t,n){t.exports=e},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 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 i=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},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}}(),l=n(3),c=o(l),f=n(1),p=o(f),d={id:l.PropTypes.number.isRequired,handleCloseBtn:l.PropTypes.func.isRequired,children:l.PropTypes.node.isRequired,autoCloseId:l.PropTypes.number,autoCloseDelay:l.PropTypes.number,handleMouseEnter:l.PropTypes.func,handleMouseLeave:l.PropTypes.func,type:l.PropTypes.oneOf(Object.values(p.default.TYPE)),childrenProps:l.PropTypes.object,position:l.PropTypes.oneOf(Object.values(p.default.POSITION))},h={type:p.default.TYPE.DEFAULT},y=function(e){function t(e){r(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.setRef=n.setRef.bind(n),n.ref=null,n}return a(t,e),u(t,[{key:"setRef",value:function(e){this.ref=e}},{key:"getChildren",value:function(){var e=this.props.childrenProps||{};return l.Children.map(this.props.children,function(t){return(0,l.cloneElement)(t,i({},e))})}},{key:"getToastProps",value:function(){var e=this.props,t=e.autoCloseId,n=e.autoCloseDelay,o=e.handleMouseEnter,r=e.handleMouseLeave,s={"data-toast-id":this.props.id,className:"toastify-content toastify-content--"+this.props.type,ref:this.setRef};return this.props.autoCloseId&&(s["data-auto-close-id"]=t,s["data-auto-close-delay"]=n,s.onMouseEnter=o,s.onMouseLeave=r),s}},{key:"componentWillEnter",value:function(e){this.ref.classList.add("bounceIn--"+this.props.position,"animated"),e()}},{key:"componentWillLeave",value:function(e){this.ref.classList.remove("bounceIn--"+this.props.position,"animated"),this.ref.classList.add("bounceOut--"+this.props.position,"animated"),setTimeout(function(){return e()},1e3)}},{key:"render",value:function(){return c.default.createElement("div",this.getToastProps(),c.default.createElement("button",{className:"toastify__close",type:"button",onClick:this.props.handleCloseBtn,value:this.props.id},"×"),c.default.createElement("div",{className:"toastify__body"},this.getChildren()))}}]),t}(l.Component);y.defaultProps=h,y.propTypes=d,t.default=y},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(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=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},l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof 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(3),p=o(f),d=n(7),h=o(d),y=n(2),v=o(y),b=n(4),O=o(b),T=n(1),m=o(T),P={position:f.PropTypes.oneOf(Object.values(m.default.POSITION)),autoClose:f.PropTypes.oneOfType([f.PropTypes.bool,f.PropTypes.number]),className:f.PropTypes.string,style:f.PropTypes.object},C={position:m.default.POSITION.TOP_RIGHT,autoClose:5e3},g=function(e){function t(e){s(this,t);var n=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.state={toast:{}},n.toastId=0,n.handleCloseBtn=n.handleCloseBtn.bind(n),n.handleMouseEnter=n.handleMouseEnter.bind(n),n.handleMouseLeave=n.handleMouseLeave.bind(n),n}return i(t,e),c(t,[{key:"componentDidMount",value:function(){var e=this;v.default.on(m.default.ACTION.SHOW,function(t,n){return e.show(t,n)}).on(m.default.ACTION.CLEAR,function(){return e.clear()})}},{key:"shouldComponentUpdate",value:function(e,t){return!this.isEqualToPreviousState(t)}},{key:"componentWillUnmount",value:function(){v.default.off(m.default.ACTION.SHOW),v.default.off(m.default.ACTION.CLEAR)}},{key:"setAutoClose",value:function(e,t){var n=this;return setTimeout(function(){return n.removeToast(e)},t)}},{key:"isEqualToPreviousState",value:function(e){var t=Object.keys(e.toast),n=Object.keys(this.state.toast);if(t.length!==n.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o])return!1;return!0}},{key:"isContentValid",value:function(e){return(0,f.isValidElement)(e)}},{key:"childrenHasProps",value:function(e){return"object"===("undefined"==typeof e?"undefined":l(e))&&"Object"===e.constructor.name}},{key:"shouldAutoClose",value:function(e){return!!(this.props.autoClose!==!1&&e!==!1||this.props.autoClose===!1&&e!==!1&&null!==e)}},{key:"removeToast",value:function(e){var t=Object.assign({},this.state.toast);delete t[e],this.setState({toast:t})}},{key:"show",value:function(e,t){if(e="string"==typeof e?p.default.createElement("div",null,e):e,this.isContentValid(e)){var n=++this.toastId,o=t.autoClose,s={id:n,type:t.type};if(this.childrenHasProps(t.props)&&(s.childrenProps=t.props),this.shouldAutoClose(o)){var a=null!==o?parseInt(o,10):this.props.autoClose;s.autoCloseId=this.setAutoClose(n,a),s.autoCloseDelay=a,s.handleMouseEnter=this.handleMouseEnter,s.handleMouseLeave=this.handleMouseLeave}this.setState({toast:Object.assign({},this.state.toast,r({},n,this.makeToast(e,s)))})}}},{key:"makeToast",value:function(e,t){return p.default.createElement(O.default,u({},t,{position:this.props.position,key:"toast-"+t.id+" ",handleCloseBtn:this.handleCloseBtn}),e)}},{key:"clear",value:function(){this.setState({toast:{}})}},{key:"handleCloseBtn",value:function(e){this.removeToast(e.target.value)}},{key:"handleMouseEnter",value:function(e){clearTimeout(e.currentTarget.dataset.autoCloseId)}},{key:"handleMouseLeave",value:function(e){var t=e.currentTarget.dataset,n=t.toastId,o=t.autoCloseDelay,r=(0,f.cloneElement)(this.state.toast[n],{autoCloseId:this.setAutoClose(n,o)}),s=Object.assign({},this.state.toast);delete s[n],s[n]=r,this.setState({toast:s})}},{key:"isObjectEmpty",value:function(){return 0===Object.keys(this.state.toast).length}},{key:"renderProps",value:function(){var e={className:"toastify toastify--"+this.props.position};return this.props.className&&(e.className=e.className+" "+this.props.className),this.props.style&&(e.style=this.props.style),e}},{key:"renderToast",value:function(){return Object.values(this.state.toast)}},{key:"render",value:function(){return p.default.createElement("div",this.renderProps(),p.default.createElement(h.default,null,this.isObjectEmpty()?null:this.renderToast()))}}]),t}(f.Component);g.defaultProps=C,g.propTypes=P,t.default=g},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(2),a=o(s),i=n(1),u=o(i),l=u.default.POSITION,c=u.default.TYPE,f=u.default.ACTION,p={type:c.DEFAULT,autoClose:null},d=function(e,t){return a.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 a.default.emit(f.CLEAR)}},{POSITION:l,TYPE:c})},function(e,n){e.exports=t}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-addons-transition-group")):"function"==typeof define&&define.amd?define(["react","react-addons-transition-group"],t):"object"==typeof exports?exports.ReactToastify=t(require("react"),require("react-addons-transition-group")):e.ReactToastify=t(e.React,e.React.addons.TransitionGroup)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([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(5),s=o(r),i=n(6),a=o(i);t.ToastContainer=s.default,t.toast=a.default},function(e,t){"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,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n={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),r=o.length-1;return o[r].once=!0,this},emit:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];if(!this.eventList.has(e))return console.warn("<"+e+"> Event is not registered. Did you forgot to bind the event ?"),!1;var r=this.eventList.get(e);return this.eventList.set(e,r.filter(function(e){var t;return(t=e.callback).call.apply(t,[e.context].concat(n)),!e.once})),!0}};t.default=n},function(t,n){t.exports=e},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 a=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},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}}(),l=n(3),c=o(l),f=n(1),p=o(f),d={id:l.PropTypes.number.isRequired,handleCloseBtn:l.PropTypes.func.isRequired,children:l.PropTypes.node.isRequired,autoCloseId:l.PropTypes.number,autoCloseDelay:l.PropTypes.number,handleMouseEnter:l.PropTypes.func,handleMouseLeave:l.PropTypes.func,onOpen:l.PropTypes.func,onClose:l.PropTypes.func,type:l.PropTypes.oneOf(Object.values(p.default.TYPE)),childrenProps:l.PropTypes.object,position:l.PropTypes.oneOf(Object.values(p.default.POSITION))},h={type:p.default.TYPE.DEFAULT},y=function(e){function t(e){r(this,t);var n=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.setRef=n.setRef.bind(n),n.ref=null,n}return i(t,e),u(t,[{key:"componentDidMount",value:function(){this.props.onOpen(this.props.childrenProps)}},{key:"componentWillUnmount",value:function(){this.props.onClose(this.props.childrenProps)}},{key:"setRef",value:function(e){this.ref=e}},{key:"getChildren",value:function(){var e=this.props.childrenProps||{};return l.Children.map(this.props.children,function(t){return(0,l.cloneElement)(t,a({},e))})}},{key:"getToastProps",value:function(){var e=this.props,t=e.autoCloseId,n=e.autoCloseDelay,o=e.handleMouseEnter,r=e.handleMouseLeave,s={"data-toast-id":this.props.id,className:"toastify-content toastify-content--"+this.props.type,ref:this.setRef};return this.props.autoCloseId&&(s["data-auto-close-id"]=t,s["data-auto-close-delay"]=n,s.onMouseEnter=o,s.onMouseLeave=r),s}},{key:"componentWillEnter",value:function(e){this.ref.classList.add("bounceIn--"+this.props.position,"animated"),e()}},{key:"componentWillLeave",value:function(e){this.ref.classList.remove("bounceIn--"+this.props.position,"animated"),this.ref.classList.add("bounceOut--"+this.props.position,"animated"),setTimeout(function(){return e()},1e3)}},{key:"render",value:function(){return c.default.createElement("div",this.getToastProps(),c.default.createElement("button",{className:"toastify__close",type:"button",onClick:this.props.handleCloseBtn,value:this.props.id},"×"),c.default.createElement("div",{className:"toastify__body"},this.getChildren()))}}]),t}(l.Component);y.defaultProps=h,y.propTypes=d,t.default=y},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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 u=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},l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof 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(3),p=o(f),d=n(7),h=o(d),y=n(2),v=o(y),b=n(4),O=o(b),T=n(1),m=o(T),P={position:f.PropTypes.oneOf(Object.values(m.default.POSITION)),autoClose:f.PropTypes.oneOfType([f.PropTypes.bool,f.PropTypes.number]),className:f.PropTypes.string,style:f.PropTypes.object},C={position:m.default.POSITION.TOP_RIGHT,autoClose:5e3},g=function(e){function t(e){s(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.state={toast:{}},n.toastId=0,n.handleCloseBtn=n.handleCloseBtn.bind(n),n.handleMouseEnter=n.handleMouseEnter.bind(n),n.handleMouseLeave=n.handleMouseLeave.bind(n),n}return a(t,e),c(t,[{key:"componentDidMount",value:function(){var e=this;v.default.on(m.default.ACTION.SHOW,function(t,n){return e.show(t,n)}).on(m.default.ACTION.CLEAR,function(){return e.clear()})}},{key:"shouldComponentUpdate",value:function(e,t){return!this.isEqualToPreviousState(t)}},{key:"componentWillUnmount",value:function(){v.default.off(m.default.ACTION.SHOW),v.default.off(m.default.ACTION.CLEAR)}},{key:"setAutoClose",value:function(e,t){var n=this;return setTimeout(function(){return n.removeToast(e)},t)}},{key:"isEqualToPreviousState",value:function(e){var t=Object.keys(e.toast),n=Object.keys(this.state.toast);if(t.length!==n.length)return!1;for(var o=0;o<n.length;o++)if(n[o]!==t[o])return!1;return!0}},{key:"isContentValid",value:function(e){return(0,f.isValidElement)(e)}},{key:"isFunction",value:function(e){return!!(e&&e.constructor&&e.call&&e.apply)}},{key:"childrenHasProps",value:function(e){return"object"===("undefined"==typeof e?"undefined":l(e))&&"Object"===e.constructor.name}},{key:"shouldAutoClose",value:function(e){return!!(this.props.autoClose!==!1&&e!==!1||this.props.autoClose===!1&&e!==!1&&null!==e)}},{key:"removeToast",value:function(e){var t=Object.assign({},this.state.toast);delete t[e],this.setState({toast:t})}},{key:"show",value:function(e,t){if(e="string"==typeof e?p.default.createElement("div",null,e):e,this.isContentValid(e)){var n=++this.toastId,o=t.autoClose,s=function(){},i={id:n,type:t.type,onOpen:this.isFunction(t.onOpen)?t.onOpen:s,onClose:this.isFunction(t.onClose)?t.onClose:s};if(this.childrenHasProps(t.props)&&(i.childrenProps=t.props),this.shouldAutoClose(o)){var a=null!==o?parseInt(o,10):this.props.autoClose;i.autoCloseId=this.setAutoClose(n,a),i.autoCloseDelay=a,i.handleMouseEnter=this.handleMouseEnter,i.handleMouseLeave=this.handleMouseLeave}this.setState({toast:Object.assign({},this.state.toast,r({},n,this.makeToast(e,i)))})}}},{key:"makeToast",value:function(e,t){return p.default.createElement(O.default,u({},t,{position:this.props.position,key:"toast-"+t.id+" ",handleCloseBtn:this.handleCloseBtn}),e)}},{key:"clear",value:function(){this.setState({toast:{}})}},{key:"handleCloseBtn",value:function(e){this.removeToast(e.target.value)}},{key:"handleMouseEnter",value:function(e){clearTimeout(e.currentTarget.dataset.autoCloseId)}},{key:"handleMouseLeave",value:function(e){var t=e.currentTarget.dataset,n=t.toastId,o=t.autoCloseDelay,r=(0,f.cloneElement)(this.state.toast[n],{autoCloseId:this.setAutoClose(n,o)}),s=Object.assign({},this.state.toast);delete s[n],s[n]=r,this.setState({toast:s})}},{key:"isObjectEmpty",value:function(){return 0===Object.keys(this.state.toast).length}},{key:"renderProps",value:function(){var e={className:"toastify toastify--"+this.props.position};return this.props.className&&(e.className=e.className+" "+this.props.className),this.props.style&&(e.style=this.props.style),e}},{key:"renderToast",value:function(){return Object.values(this.state.toast)}},{key:"render",value:function(){return p.default.createElement("div",this.renderProps(),p.default.createElement(h.default,null,this.isObjectEmpty()?null:this.renderToast()))}}]),t}(f.Component);g.defaultProps=C,g.propTypes=P,t.default=g},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(2),i=o(s),a=n(1),u=o(a),l=u.default.POSITION,c=u.default.TYPE,f=u.default.ACTION,p={type:c.DEFAULT,autoClose: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,n){e.exports=t}])}); |
@@ -35,2 +35,4 @@ 'use strict'; | ||
handleMouseLeave: _react.PropTypes.func, | ||
onOpen: _react.PropTypes.func, | ||
onClose: _react.PropTypes.func, | ||
type: _react.PropTypes.oneOf(Object.values(_config2.default.TYPE)), | ||
@@ -59,2 +61,12 @@ childrenProps: _react.PropTypes.object, | ||
_createClass(Toast, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
this.props.onOpen(this.props.childrenProps); | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.props.onClose(this.props.childrenProps); | ||
} | ||
}, { | ||
key: 'setRef', | ||
@@ -61,0 +73,0 @@ value: function setRef(ref) { |
@@ -128,2 +128,7 @@ 'use strict'; | ||
}, { | ||
key: 'isFunction', | ||
value: function isFunction(object) { | ||
return !!(object && object.constructor && object.call && object.apply); | ||
} | ||
}, { | ||
key: 'childrenHasProps', | ||
@@ -157,3 +162,9 @@ value: function childrenHasProps(props) { | ||
var autoCloseOpt = options.autoClose; | ||
var toastOptions = { id: toastId, type: options.type }; | ||
var fn = function fn() {}; | ||
var toastOptions = { | ||
id: toastId, | ||
type: options.type, | ||
onOpen: this.isFunction(options.onOpen) ? options.onOpen : fn, | ||
onClose: this.isFunction(options.onClose) ? options.onClose : fn | ||
}; | ||
@@ -160,0 +171,0 @@ if (this.childrenHasProps(options.props)) { |
{ | ||
"name": "react-toastify", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "React notification made easy", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# 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/sniphpet/react-toastify.svg?maxAge=2592000)]() | ||
React-Toastify allow you to add toast notification to your app with ease. | ||
## Demo | ||
Check the demo [here](https://sniphpet.github.io/react-toastify/) | ||
## Installation | ||
@@ -19,6 +23,7 @@ | ||
- Can display a react component inside the toast ! | ||
- Has ```onOpen``` and ```onClose``` hooks. Both can access the props passed to the react component rendered inside the toast | ||
- Can be positioned | ||
- Define behavior per toast | ||
- Super easy to style | ||
- Can display a react component inside the toast ! | ||
@@ -112,2 +117,5 @@ ## How it works ? | ||
const options = { | ||
//callback can access props passed to the component | ||
onOpen: (props) => {console.log(props.foo)}, | ||
onClose: (props) => {console.log(props.foo)}, | ||
autoClose: false, //The user need to close the toast to remove it | ||
@@ -123,3 +131,3 @@ props: { // props will be passed to the component displayed by the notification | ||
toast.info("World", options) // add type: 'info' to options | ||
toast.warning(<Img />, options) // add type: 'warning' to options | ||
toast.warn(<Img />, options) // add type: 'warning' to options | ||
toast.error(<Img />, options) // add type: 'error' to options | ||
@@ -129,2 +137,11 @@ toast.dismiss() // Remove all toasts ! | ||
## Release Notes | ||
### 1.1.0 | ||
#### Features | ||
- Added onOpen callback | ||
- Added onClose callback | ||
## Contribute | ||
@@ -131,0 +148,0 @@ |
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
57060
721
150