Coder Social home page Coder Social logo

nandi95 / vue-toastify Goto Github PK

View Code? Open in Web Editor NEW
227.0 2.0 12.0 1.68 MB

🔥 Simple, extendable, dependency free notification plugin. 🔥

Home Page: https://vue-toastify.netlify.com/

License: MIT License

JavaScript 6.46% HTML 0.56% Vue 56.99% SCSS 6.24% TypeScript 29.75%
vue notification toastify laravel pause pause-action alert toast status notification-plugin

vue-toastify's Introduction

🔥Vue Toastify🔥

Simple and dependency free notification plugin.

install

npm i vue-toastify
import { createApp } from 'vue';
import plugin from 'vue-toastify';
import 'vue-toastify/index.css';
import type { Settings } from 'vue-toastify';

const app = createApp({  });
app.use<Settings>(plugin, {  });
app.mount('#app');

Options:

Custom styling

Styles include a 'dark'(default) and a 'light' theme. If you would like to create your own styles you may use the following helpers:

import { createVtTheme, getCssRules } from 'vue-toastify';

// this will create a stylesheet if doesn't exists and insert it into the head
createVtTheme('myThemeName', '#8f6b42');
// then you can set the theme of the status or the global settings
// alternatively, you can get an array of css rules using getCssRules
getCssRules('myThemeName', '#8f6b42').forEach(rule => {...});
// this will give you a good starting point to customise the theme

Custom notifications

You may create some methods on the useToast() so it will shortcut any repetition you may have in your app. To register them add a customNotifications key to the settings when registering the plugin.

app.use<Settings>(plugin, {
    customNotifications: {
        authenticationError: {
            body: 'Authentication error',
            // ... rest of the toast options here
        }
    }
});
// then later you can use it as
useToast().authenticationError();

Ambient declaration for custom notifications

import type { ToastPluginAPI, CustomMethods } from 'vue-toastify';

declare module 'vue-toastify' {
    interface MyMethods extends CustomMethods {
        authenticationError(): string;
    }

    function useToast(): ToastPluginAPI & MyMethods;
}

Events

The plugin emits events that you can listen to which allows for using callbacks at different points in the toast's lifecycle.

import { useVtEvents, useToast } from 'vue-toastify';

const toast = useToast().success({ body: 'Hello world', canTimeout: true });

useVtEvents().once('vtPaused', payload => {
    if (payload.id === toast.id) {
        // do something
    }
})

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.