1.2.0 • Published 5 years ago

vue-sure-toast v1.2.0

Weekly downloads
57
License
-
Repository
-
Last release
5 years ago

Vue Sure Toast

Vue Sure Toast is a simple VueJS toast plugin. This plugin contains built in features for theming, position, and more. See below for a full list of features.

Samples

Here are the basic themes built into the plugin.

Alt text

Toast with the progress bar enabled (choppiness is just the gif).

Alt text

Installation

First import the plugin.

import SureToast from 'vue-sure-toast';

Then configure the plugin with Vue.

// The simplest implementation.
Vue.use(SureToast);

// You can set default option values for the plugin here.  See a full list of options below.
Vue.use(SureToast, options);

// Here is a sample that sets the position and theme for all the toasts.
Vue.use(SureToast, {
  position: 'top-left',
  theme: 'warning'
});

Basic Usage

Displaying a toast message from within a component.

// The simplest method for displaying toast.
this.$sureToast.show(message);

this.$sureToast.show(message, icon);

this.$sureToast.show(message, icon, options);

The options parameter can contain an action that will be appended to the toast an a link.

this.$sureToast.show('I am a toast message', 'fa fa-info-circle', {
  interval: 5000,
  enableManualDismiss: true,
  action: { 
    text: 'DISMISS', 
    onClick: (e, toast) => { alert('TOAST CLICKED: ' + toast); } 
  }
});

You can also pass an array of actions when displaying a toast. If you pass both the 'action' and 'actions' property the 'action' property will take precedence over 'actions'. Make sure you pass one to save yourself some trouble.

this.$sureToast.show('I am a toast message', 'fa fa-info-circle', {
  interval: 5000,
  enableManualDismiss: true,
  actions: [
    { 
      text: 'OPEN', 
      onClick: (e, toast) => { alert('OPEN CLICKED: ' + toast); } 
    },
    { 
      text: 'DISMISS', 
      onClick: (e, toast) => { alert('CLOSE CLICKED: ' + toast); } 
    }
  ]
});

Toast Hooks

There are to methods you can hook into that will get fired when a toast is opened or closed.

// If you want a fire onOpened or onClosed for a specific toast you can do it like so.
this.$sureToast.show('I am a toast message', 'fa fa-info-circle', {
  interval: 5000,
  onOpened(e) {
    console.log('toast opened');
  },
  onClosed(e) {
    console.log('toast closed');
  }
});

If you want to fire the onOpened and onClosed for all the toasts you can pass define your functions in the plugin options.

Vue.use(SureToast, {
  onOpened() {
    console.log('toast opened');
  },
  onClosed() {
    console.log('toast closed');
  }
});

Any plugin level options that are passed through the show function will be ignored by the plugin.

Plugin/Toast Options

Below is a full list of the available options for both the defaults and individual toasts.

OptionTypeValuesDefaultDescription
intervalnumberany number (milliseconds)5000msThe duration the toast is visible
enableManualDismissbooleantrue, falsefalseAllows toasts to be manually dismissed
positionstring'top-left', 'top-right', 'bottom-right', 'bottom-left', 'top', 'bottom''top-right'Screen position of the toast
themestring'success', 'error', 'info', 'warning', 'default''default'The color scheme of the toast
limitnumberany whole number3How many toasts can be displayed at once
persistbooleantrue, falsefalseForces toasts to remain on screen (overrides interval)
reverseToastOrderbooleantrue, falsefalseIf true displays the latest toasts at the bottom
showProgressBarbooleantrue, falsefalseIf true displays the a progress bar across the bottom of toast with displaying the remaining time left for the toast
onOpenedfunctionN/AundefinedExecuted after a toast is opened
onClosedfunctionN/AundefinedExecuted after a toast is closed

Plugin ONLY Options

Below is a full list of the options that can only be set at the plugin level (passed to the Vue.use function).

OptionTypeValuesDefaultDescription
positionstring'top-left', 'top-right', 'bottom-right', 'bottom-left', 'top', 'bottom''top-right'Screen position of the toast
limitnumberany whole number3How many toasts can be displayed at once
reverseToastOrderbooleantrue, falsefalseIf true displays the latest toasts at the bottom

Methods

Below is a full list of the methods available through the Vue instance.

MethodParametersDescription
showmessage, icon, optionsDisplay a toast with the default options
showSuccessmessage, icon, optionsDisplays a success toast (sets theme to 'success')
showErrormessage, icon, optionsDisplays an error toast (sets theme to 'error')
showWarningmessage, icon, optionsDisplays a warning toast (sets theme to 'warning')
showInfomessage, icon, optionsDisplay an information toast (sets theme to 'info')
dismisstoastRemoves a given toast from the DOM (NOT WORKING)
dismissAllN/ARemoves all toasts from the DOM

Properties

Below is a full list of properties availble through the Vue instance.

PropertyTypeDescription
pluginDefaultOptionsobjectStores the defaults for the plugin. This is used as a fallback if no plugin or toast level settings are set by the user
userDefaultOptionsobjectStores the default options configured at the plugin level by the user
toastsLoadednumberStores the current number of toasts visible on the DOM
toastsarrayStores an array of DOM elements that represents the toasts current visible on the DOM

Inspiration/Credit

This plugin was inspired by vue-toasted

Development

Developed by: NSSure

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago