npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-toastify

v2.0.1

Published

<p align="center">Simple and dependency free notification plugin.</p>

Downloads

6,746

Readme

🔥Vue Toastify🔥

Installation

npm i vue-toastify
import { createApp } from 'vue';
import plugin from 'vue-toastify';
// base styles
import 'vue-toastify/index.css';
// theme styles
import 'vue-toastify/themes/dark.css';
import type { Settings } from 'vue-toastify';

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

Usage with Nuxt

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
    }
})

Usage with Nuxt

The recommended way to install is by creating a plugin. As notifications are expected to be responses to user actions, we can lazy load the plugin to reduce the initial bundle size.

Be sure to familiarise yourself with the Nuxt plugin documentation.

// plugins/toast.client.ts
// .client will only run the plugin on the client side.
import type { Settings } from 'vue-toastify';

export default defineNuxtPlugin({
    name: 'toast',
    // can load the same time as the rest of the plugins
    parallel: true,
    setup: nuxt => {
        // this will lazy load the plugin therefore won't be included in the entry point
        void import('vue-toastify').then(exports => {
            nuxt.vueApp.use<Settings>(exports.default, {
                pauseOnHover: true,
                theme: 'light',
                position: 'top-right'
            });
        });
    }
});

Then specify the auto-imported preset in your configuration.

// nuxt.config.ts
export default defineNuxtConfig({
    css: [
        // required base themes
        'vue-toastify/index.css',
        // include the theme you want to use
        'vue-toastify/themes/light.css'
        // or generate one of your own as described in the custom styling section
    ],
    imports: {
        // this will include the composables that the plugin provides
        // which is negligable in size compared to the plugin itself
        presets: [
            {
                from: 'vue-toastify',
                imports: [
                    // include only the composables you need auto-imported
                    'useToast',
                    // 'useVtEvents',
                    // 'useVtSettings'
                ]
            }
        ]
    },
})