Cogo Toast

Beautiful, Zero Configuration, Toast Messages for React. Only ~ 4kb gzip, w...

README

cogo-toast

Cogo Toast

Beautiful, Zero Configuration, Toast Messages for React ~4kb gzip (with styles and icons)

https://cogoport.github.io/cogo-toast/

Dependencies npm package Small size npm downloads
Code style License

cogo-toast-preview


Install via NPM:


  1. ``` sh
  2. npm install --save cogo-toast
  3. ```

Install via Yarn:


  1. ``` sh
  2. yarn add cogo-toast
  3. ```

Note:


The latest version ^3.0.0 makes the use of React Hooks internally.

To use this package in projects that don't support hooks, use v2.0.1 instead.

  1. ``` sh
  2. yarn add cogo-toast@2.0.1
  3. ```

Usage


Its Plug and Play. No configuration required. Just import and you are good to go.

  1. ``` js
  2. import cogoToast from 'cogo-toast';

  3. cogoToast.success('This is a success message!');
  4. ```

5 Built in Types


There are 5 built-in types to handle the most common cases in any application.

  1. ``` js
  2. cogoToast.success('This is a success message');

  3. cogoToast.info('This is a info message');

  4. cogoToast.loading('This is a loading message');

  5. cogoToast.warn('This is a warn message');

  6. cogoToast.error('This is a error message');
  7. ```

Use JSX


cogoToast is built using React. Which means any valid jsx can be used as the message in cogoToast

  1. ``` js
  2. cogoToast.info(
  3.   <div>
  4.     <b>Awesome!</b>
  5.     <div>Isn't it?</div>
  6.   </div>,
  7. );
  8. ```

Returns a Promise


Returns a promise which resolves when the toast is about to hide.

This can be useful to do some action when the toast has completed showing.

  1. ``` js
  2. cogoToast.loading('Loading your data...').then(() => {
  3.   cogoToast.success('Data Successfully Loaded');
  4. });
  5. ```

Hide on Click


  1. ``` js
  2. const { hide } = cogoToast.success('This is a success message.', {
  3.   onClick: () => {
  4.     hide();
  5.   },
  6. });
  7. ```

Completely Customizable


The second parameter to the function is an options object that can be passed in for customization.

  1. ``` js
  2. cogoToast.info('This is an info message', options);
  3. ```

All Available Options


Here's a list of all the available options, to customize the toast to your needs.

|    Options    |                                               Type                                               |                          Default                           |
| :-----------: | :----------------------------------------------------------------------------------------------: | :--------------------------------------------------------: |
| hideAfter | Number in Seconds | `3`
(Can be `0` to disable auto-hiding of the toast) || position | `'top-left', 'top-center', 'top-right',`
`'bottom-left', 'bottom-center', 'bottom-right'` | `'top-center'` |
|    heading    |                                              String                                              |                            ''                            |
| renderIcon | Function | Icon Based on the Type || bar | Object
`{ size: '2px', style: 'solid/dashed/dotted', color: '#hex' }` | Based on the Type |
| onClick() |                                             Function                                             |                           null                           |
| role |                                             aria-role                                             |                           status                           |
| toastContainerID |                   The dom element in which the toast container is added                                         |                           ct-container                           |

Custom Styling


You can provide your own custom styling by extending the ct-toast class in your css styles.

For all classnames, refer to /src/styles/styles.css

Customize each type of Toast seperately


Customize each type of Toast seperately, by extending the `ct-toast-` class. For example, in your CSS,

  1. ```
  2. ct-toast-success {
  3.   color: #FFFFFF;
  4.   background: #6EC05F;
  5. }
  6. ```

Only ~ 4kb gzip (with Styles and Icons)


The package contains the minified build file, along with the SVG Icons and the Styles, built into the Code, with a total of only ~4kb gzip.

Contributors ✨


Thanks goes to these wonderful people (emoji key):




Anmol Mahatpurkar
Anmol Mahatpurkar

💻 🎨 📖
Balázs Orbán
Balázs Orbán

💻
Vitalii Kalchuk
Vitalii Kalchuk

💻
Amar Pathak
Amar Pathak

📖
Nataly Shrits
Nataly Shrits

💻





This project follows the all-contributors specification. Contributions of any kind welcome!