toast-me
![Build Status](https://travis-ci.org/a-kalinin/toast-me.svg?branch=master)
Tiny, easy to use tool to show toast-like notifications on the web page.
![Demo](https://alexkalinin.ru/works/toast-me/toast-demo.gif)
Table of Contents
Features
- Exported in a umd format so works everywhere.
- Customizable
- Light-weight (15kB until gzip, 5kB zipped)
- Supports actions
How to use
Install
Install package from npm
yarn add toast-me
# or
npm install toast-me
Import module to your script
import toast from 'toast-me';
Using
toast('My message');
Using with own customization
toast('My message', { duration: 3000, toastClass: 'my-toast-class' });
Toast function arguments
toast(message, [options, [action]]);
Function accepts three arguments:
message
- message to show in toast,options
- toast customization options,action
- some action button options.
Message argument
Accepts string
, any message to put in toast.
Text shown in one line, no wraps allowed.
Overflowed text will be hidden with ellipsis.
Complete text shown on hover with the title
attribute on toast node.
Options argument
Optional - Accepts object
with any allowed fields, or string
as a name of options preset, or null
.
If you don't need to set options, but need to pass an action - pass null
instead options.
Accepted options
position
- string, one of "top"
"bottom"
. Default "top"
.toastClass
- string, CSS class name for toast node, can be used for custom toast styling.
Default ""
- empty stringcloseable
- boolean, enables/hides "close" button on toast. Default true
timeoutOnRemove
- number, time in ms, till node should be removed from DOM after toast hides.
Can be useful when you change hide animation by CSS and set new animation duration.
To avoid element disappearing until animation ends set this option to larger or equal
value than animation duration. Default 1000
duration
- number, time in ms, how long should toast be shown. Default 5000
Options presets
default
- all default options,error
- everything default, except background color - #D40D00
Action argument
Optional - Accepts object with three fields:
label
- string, text to put in button.action
- callback function - to be called on button click.class
- string, CSS class for button node.
#Contributing
%%%%%%%%%%%%%%%%%%%%%%%%%
SECTION BELOW IS IN WORK
%%%%%%%%%%%%%%%%%%%%%%%%%
Getting started
You will need node.js and preferred to have
yarn to run the project.
Copy project to your local folder and then run in project's root
folder next command to load dependencies:
yarn
Scripts
When you load all dependencies, you able to run several commands:
yarn build
- produces production pack of library under the lib
folderyarn run-dev
- produces development version of your library, runs file watcher
and http server on http://localhost:3005yarn watch
- produces development version of your library, runs a file watcheryarn test
- runs the tests
Structure
Root folder
dev/
- Folder, containing development environment files. This folder is
published with yarn run-dev
command. toast-me.js
and taos-me.js.map
files inside are generated by webpack watcher from /src
folder. You are
able to change files in both folders and they are to be reloaded in browser.lib/
- The place production pack will be located after build. Usually you won't
need it, until you wan't to compile library by yourself and insert in your
project manuallyscripts/
- Node.js executable scripts' folder, such as dev-server.js
or test.js
.
config/
- Configuration files' folder.
src/
- Here is the code of library itself.
Readings
- Git-flow workflow
- AirBnB Style Guide
- Webpack
- Node.js
- Yarn
- SASS
- Jest - main documentation