Skip to content

KromPass/vue-toasted

 
 

Repository files navigation

Introduction

vue-toasted is a cool material toast plugin with variety of options and styles. it is touch compatible and responsive. issues and pr's are always welcome

Checkout the Interactive Demo here.

Usage

It is simple. couple of lines all what you need.

# install it via npm
npm install vue-toasted --save
// register the plugin on vue
import Toasted from 'vue-toasted';

Vue.use(Toasted)

// you can also pass options, check options reference below
Vue.use(Toasted, Options)
// you can call like this in your component
this.$toasted.show('hello billo')

// and also
Vue.toasted.show('hola billo');

All Good Now you have this cool toast in your project.. let's take a look at the api

API

vue-toasted has methods which makes it much easier to use

methods

all the below methods return the Toasted Object of the toast.

Vue.toasted.success( {string | html } message, {object} options)

// available methods
Vue.toasted.show(message, options)
Vue.toasted.success(message, options)
Vue.toasted.info(message, options)
Vue.toasted.error(message, options)

Toast Object

check the examples to see how to manipulate the object.

// html element of the toast
el : HtmlElement

// change text or html of the toast
text : Function(text)

// fadeAway the toast. default delay will be 800ms
goAway : Function(delay = 800)

using the toast object

let myToast = this.$toasted.show("Holla !!");
myToast.text("Changing the text !!!").goAway(1500);

options

below are the available options

Option Description Values Default
position position of the toast container 'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left' 'top-right'
duration display time of the toast in millisecond null
className custom css class name of the toast null
theme theme of the toast you prefer 'primary', 'outline', 'bubble' 'primary'
onComplete on complete event of toast a callback function null

Reusable Global Toasts

you can register your global toasts under globalToasts. they will be available globally for use in $toasted.global. take a look at the detailed example here

// Global Plugin Register
Vue.use(Toasted, {
  globalToasts : {

    myGlobalToast : function(payload, initiate){
        
        // your logic using payload here...
        
        // this will initiate the toast
        return initiate("My Deepest Condolence", 'error');
    },
    // my another toast...
  }
});

viola !! now you can use your toast in anywhere

// send your payload to global toast
$toasted.global.myGlobalToast(payload);

Credits

  • Whoever contributes to this project 😉
  • Inspired and developed from materialize-css toast.

Enjoy Toasting !!

About

😎 Responsive Touch Compatible Toast plugin for VueJS 2+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 82.1%
  • CSS 17.6%
  • Vue 0.3%