├── .DS_Store ├── .babelrc ├── .gitignore ├── .npmignore ├── README.md ├── dist └── bundle.js ├── index.html ├── lib └── toast.js ├── package-lock.json ├── package.json ├── src ├── App.js ├── index.js ├── radioinput.js └── toast.js ├── webpack.config.js ├── yarn-error.log └── yarn.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwaniarya/react-nextjs-toast/32f1d819faa630be01288c651101cb00ab056cc4/.DS_Store -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "react", 4 | "env", 5 | "stage-0" 6 | ], 7 | "plugins": [ 8 | "styled-jsx/babel" 9 | ] 10 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | src 3 | webpack.config.js 4 | .node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A simple nextjs toast component 2 | This toast component can be used on nextjs projects or any other react project which uses style-jsx. 3 | 4 |

DEMO

5 | 6 | ## Installation 7 | 8 | Using npm 9 | ``` 10 | npm install react-nextjs-toast 11 | ``` 12 | 13 | Using yarn 14 | ``` 15 | yarn add react-nextjs-toast 16 | ``` 17 | 18 | ## How to use 19 | 20 | The component is very simple to use. Just follow the instructions. 21 | ### Add toast container component 22 | ```jsx 23 | import { ToastContainer } from 'react-nextjs-toast' 24 | 25 | //... 26 | 27 | //... 28 | 29 | ``` 30 | ### To show toast 31 | ```jsx 32 | toast.notify( msg, { options } ) 33 | ``` 34 | 35 | *check option section to learn more* 36 | ### To remove toast 37 | ```jsx 38 | toast.remove() 39 | ``` 40 | Let's assume you have a react component where you want to use the toast component to notify a user about certain event. 41 | 42 | ```jsx 43 | import React from 'react' 44 | 45 | // import toast object and toast container from react-nextjs-toast 46 | import { toast, ToastContainer } from 'react-nextjs-toast' 47 | 48 | // Your react component 49 | class Card extends React.Component { 50 | 51 | // something ... 52 | 53 | // call toast.notify() here 54 | onClickNotify = () => { 55 | toast.notify(`Hi, I am a toast!`) 56 | } 57 | 58 | render(){ 59 | return (
60 | 61 | {/** Add toast component **/} 62 | 63 | 64 | 65 | 68 |
69 | ) 70 | } 71 | } 72 | ``` 73 | 74 | ## Toast container props 75 | 76 | | props | description | Data Type | 77 | |----------|-------------|-------| 78 | | align | left, center, right | *String* | 79 | | position | top, bottom | *String*| 80 | | id | Container id ( must be unique ) | *String* | 81 | 82 | For example to show toast at the top right 83 | ```jsx 84 | 85 | ``` 86 | 87 | ## Toast Options 88 | 89 | The toast has 4 types of default events - info, success, error and warning and also supports custom duration. 90 | 91 | 92 | | property | description | Data Type | 93 | |----------|-------------|-------| 94 | | duration | Number of seconds to show toast on screen | *Integer* | 95 | | type | Type of toast - info, error, success and warning | *String*| 96 | | title | The title of the toast | *String* | 97 | | targetId | Target container id | *String* | 98 | | position | top , bottom | *String* | 99 | | | default value is bottom || 100 | 101 | 102 | 103 | For example, to show success toast that lasts for 5 seconds. 104 | ``` 105 | toast.notify('This is a success toast', { 106 | duration: 5, 107 | type: "success" 108 | }) 109 | ``` 110 | 111 | ---- 112 | 113 | # Todo 114 | * Custom design 115 | * Toast stacking 116 | 117 | # Miscellaneous 118 | 119 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | React nextjs toast 6 | 7 | 8 | 18 | 19 | 20 |
21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /lib/toast.js: -------------------------------------------------------------------------------- 1 | module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},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="",n(n.s=2)}([function(e,t,n){"use strict";e.exports=n(5)},function(e,t,n){"use strict"; 2 | /* 3 | object-assign 4 | (c) Sindre Sorhus 5 | @license MIT 6 | */var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;function o(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,a,u=o(e),s=1;s1&&void 0!==arguments[1]?arguments[1]:null,n=5,r="info",o="toast-container",a=null,u="bottom",s=null;t&&(t.duration&&(n=t.duration),t.type&&(r=t.type),t.targetId&&(o=t.targetId),t.title&&(a=t.title),t.position&&(u=t.position),t.onRemove&&(s=t.onRemove));var c=100/n*.3;"bottom"===u?(0,l.render)(i.default.createElement(f,{message:e,slideIn:!0,type:r||"info",transitionPercentage:c,targetId:o,title:a,onRemove:s,duration:n}),document.getElementById(o)):(0,l.render)(i.default.createElement(d,{message:e,slideIn:!0,type:r||"info",transitionPercentage:c,targetId:o,title:a,onRemove:s,duration:n}),document.getElementById(o))}},t.ToastContainer=function(e){var t=e.id||"toast-container";return i.default.createElement("div",{id:t,className:_JSXStyle.dynamic([["3672192840",["bottom"===e.position?"bottom: 0px;":"top"===e.position?"top: 16px;":"bottom: 0px;",e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center"]]])+" toast-container"},i.default.createElement(_JSXStyle,{id:"3672192840",dynamic:["bottom"===e.position?"bottom: 0px;":"top"===e.position?"top: 16px;":"bottom: 0px;",e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center"]},".toast-container.__jsx-style-dynamic-selector{position:fixed;width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-align-items:flex-end;-webkit-box-align:flex-end;-ms-flex-align:flex-end;align-items:flex-end;left:0px;height:0px;background-color:red;}.toast-container.__jsx-style-dynamic-selector{position:fixed;width:100%;"+("bottom"===e.position?"bottom: 0px;":"top"===e.position?"top: 16px;":"bottom: 0px;")+" display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-align-items:"+(e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center")+";-webkit-box-align:"+(e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center")+";-ms-flex-align:"+(e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center")+";align-items:"+(e.align?"center"===e.align?"center":"left"===e.align?"flex-start":"right"===e.align?"flex-end":void 0:"center")+";left:0px;}"))}},function(e,t,n){e.exports=n(4)},function(e,t,n){"use strict";t.__esModule=!0,t.flush=function(){var e=l.cssRules();return l.flush(),e},t.default=void 0;var r,i=n(0);var l=new(((r=n(6))&&r.__esModule?r:{default:r}).default),o=function(e){var t,n;function r(t){var n;return(n=e.call(this,t)||this).prevProps={},n}n=e,(t=r).prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n,r.dynamic=function(e){return e.map((function(e){var t=e[0],n=e[1];return l.computeId(t,n)})).join(" ")};var i=r.prototype;return i.shouldComponentUpdate=function(e){return this.props.id!==e.id||String(this.props.dynamic)!==String(e.dynamic)},i.componentWillUnmount=function(){l.remove(this.props)},i.render=function(){return this.shouldComponentUpdate(this.prevProps)&&(this.prevProps.id&&l.remove(this.prevProps),l.add(this.props),this.prevProps=this.props),null},r}(i.Component);t.default=o},function(e,t,n){"use strict"; 7 | /** @license React v16.14.0 8 | * react.production.min.js 9 | * 10 | * Copyright (c) Facebook, Inc. and its affiliates. 11 | * 12 | * This source code is licensed under the MIT license found in the 13 | * LICENSE file in the root directory of this source tree. 14 | */var r=n(1),i="function"==typeof Symbol&&Symbol.for,l=i?Symbol.for("react.element"):60103,o=i?Symbol.for("react.portal"):60106,a=i?Symbol.for("react.fragment"):60107,u=i?Symbol.for("react.strict_mode"):60108,s=i?Symbol.for("react.profiler"):60114,c=i?Symbol.for("react.provider"):60109,f=i?Symbol.for("react.context"):60110,d=i?Symbol.for("react.forward_ref"):60112,p=i?Symbol.for("react.suspense"):60113,m=i?Symbol.for("react.memo"):60115,h=i?Symbol.for("react.lazy"):60116,y="function"==typeof Symbol&&Symbol.iterator;function g(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;nz.length&&z.push(e)}function I(e,t,n){return null==e?0:function e(t,n,r,i){var a=typeof t;"undefined"!==a&&"boolean"!==a||(t=null);var u=!1;if(null===t)u=!0;else switch(a){case"string":case"number":u=!0;break;case"object":switch(t.$$typeof){case l:case o:u=!0}}if(u)return r(i,t,""===n?"."+F(t,0):n),1;if(u=0,n=""===n?".":n+":",Array.isArray(t))for(var s=0;s>>0}},function(e,t,n){"use strict";(function(e){function n(e,t){for(var n=0;n1)for(var n=1;n