GithubHelp home page GithubHelp logo

renatodeleao / vuex-toast Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ktsn/vuex-toast

0.0 2.0 0.0 323 KB

Simple toast notification using Vuex

License: MIT License

JavaScript 56.47% Vue 43.53%

vuex-toast's Introduction

Vuex Toast

Simple toast notification using Vuex

Requirements

  • Vue >= 2.0
  • Vuex >= 2.0

Demo

http://codepen.io/ktsn/pen/Bzxkjd

Install

npm install vuex-toast --save

Example

First, you should register a toast module to your Vuex store. You can use a default style at dist/vuex-toast.css.

import Vue from 'vue'
import Vuex from 'vuex'
import { createModule } from 'vuex-toast'

// If you want to use the default style (with webpack css-loader)
import 'vuex-toast/dist/vuex-toast.css'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    // ...
    toast: createModule({
      dismissInterval: 8000
    })
    // ...
  }
})

Put Toast component anywhere in your application.

<template>
  <div>
    <article><!-- Your contents --></article>
    <toast position="ne"></toast>
  </div>
</template>

<script>
import { Toast } from 'vuex-toast'

export default {
  // ...
  components: {
    Toast
  }
  // ...
}
</script>

You can send notifications to the toast component with toast type.

import { mapActions } from 'vuex'
import { ADD_TOAST_MESSAGE } from 'vuex-toast'

export default {
  methods: {
    ...mapActions({
      addToast: ADD_TOAST_MESSAGE
    }),

    sendNotification(text) {
      this.addToast({
        text,
        type: 'success',
        dismissAfter: 10000
      })
    }
  }
}

API

Toast

A Vue component that shows toast messages.

  • props
    • position
    • html
    • namespace
      • Vuex module's namespace if you install toast module into some namespaced module.

createModule(options): VuexModule

Create Vuex module for managing toast messages.

  • options
    • dismissInterval

createComponent(options): VueComponent

Create customized toast component.

  • options
    • transition

Action Types

  • ADD_TOAST_MESSAGE
    • dispatch(ADD_TOAST_MESSAGE, { text, type, dismissAfter })
  • REMOVE_TOAST_MESSAGE
    • dispatch(REMOVE_TOAST_MESSAGE, messageId)

Getters

  • toastMessage
    • get all toast messages.

Toast Message Type

  • id Auto generated message ID
  • text Text of the toast message
  • type Type of the toast message
    • You can use any value for styling purpose.
    • There are default styles for info, success, warning, and danger
  • dismissAfter Milli-second that indicates the message dismiss after this time

License

MIT

vuex-toast's People

Contributors

ktsn avatar loghorn avatar jaumebalust avatar

Watchers

James Cloos avatar Renato de Leão avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.