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

mw-vue-notify

v2.0.3

Published

Notification library for Vue 3 apps

Downloads

3

Readme

Introduction

This is a Vue 3 library for showing notifications to the user. There are a few built-in notification styles, but you can easily style your own if you need some custom looks.

Installation

Download from NPM:

# Yarn
yarn add mw-vue-notify

# NPM
npm install mw-vue-notify

Add to your Vue instance:

import MWVueNotify from 'mw-vue-notify';
app.use(MWVueNotify, {}); // Can provide config to change default behavior - see below.

Add this tag to your top-level Vue component. This is where all of your notification elements will be mounted into the DOM.

<mw-vn-notification-display></mw-vn-notification-display>

Usage

To show a new notification:

import { useVueNotify } from 'mw-vue-notify';

const mwVueNotify = useVueNotify();

mwVueNotify.showNotification({
    cssClasses: ['mw-vn-warning'],
    data: { message: "Task failed successfully!" },
});

If you need a non-built-in way to delete a notification (for example, dismissing notifications when the user navigates to a different page), showNotification() returns an ID. Pass this ID into deleteNotification() to delete the notification:

let notificationId = mwVueNotify.showNotification(...);

// ...something gets triggered...

mwVueNotify.deleteNotification(notificationId)

Configuration

Any subset of configuration options can be provided to either:

  • The library when it's configured (modifies the default behavior across the whole application)

    // Library configuration
    // (default values shown)
    import MWVueNotify from 'mw-vue-notify';
    app.use(MWVueNotify, {
        defaults: {
            position: 'bottom-right',
            dismissButton: true,
            dismissAfterMillis: 0,
            cssClasses: [],
            componentName: 'mw-vn-plaintext',
            data: {}, // Doesn't make sense to provide this option here, but listed for completeness.
        }
    });
  • An individual notification when it's shown

    // Per-notification configuration
    // (non-specified values default to the library configuration)
    mwVueNotify.showNotification({
        cssClasses: ['mw-vn-info'],
        dismissButton: false,
        dismissAfterMillis: 0,
        data: { message: "Did you know - you can display a notification that can't be closed? Fascinating." },
    });

Available Configuration Options

{
    // The screen position for your notification
    //   'top-left',    'top-center',    'top-right'
    //   'middle-left', 'middle-center', 'middle-right'
    //   'bottom-left', 'bottom-center', 'bottom-right'
    position: 'bottom-right',

    // Whether to show a small "X" to close the notification
    dismissButton: true,

    // Auto-close the notification after this many milliseconds.
    // 0 = disables the feature
    dismissAfterMillis: 0,

    // Additional css classes to apply. Default styling is gray/black.
    // Built-in classes include:
    //   'mw-vn-failure' = Red notifications
    //   'mw-vn-warning' = Yellow notifications
    //   'mw-vn-success' = Green notifications
    //   'mw-vn-info'    = Blue notifications
    cssClasses: [],

    // The layout for the notification's contents. Can use a custom component registered with
    // Vue, or one of our built-in components:
    //   'mw-vn-plaintext'         = One or more paragraphs of text.
    //   'mw-vn-message-with-list' = One paragraph, followed by an unordered list of items.
    componentName: 'mw-vn-plaintext',

    // The data shown in your notification. Depending on your chosen layout (`componentName`),
    // this will contain different keys and values.
    data: {},
}

Layouts

A layout is a Vue component that defines how to display the notification's content. We provide some basic built-in layouts, but you can also create your own by making a custom vue component.

Built-in

mw-vn-plaintext

This is the default layout. Its data configuration takes a single parameter message which can either be a string or an array of strings. Each provided string is displayed in a paragraph tag.

// Single message
mwVueNotify.showNotification({
    componentName: 'mw-vn-plaintext', // This is the default value, so can be omitted.
    data: { message: "I am a single message. Fear me!" },
});

// Multiple messages
mwVueNotify.showNotification({
    componentName: 'mw-vn-plaintext', // This is the default value, so can be omitted.
    data: { message: [
        "I have two paragraphs worth of messages.",
        "Everyone knows the second paragraph is where all the good stuff is.",
    ]},
});

mw-vn-message-with-list

This layout displays a paragraph followed by an unordered list of items. Its data configuration takes two parameters:

  • message (Optional) = The paragraph to display.
  • items = An array of strings. Each element is an item in the unordered list.
// A message with a list of items.
mwVueNotify.showNotification({
    componentName: 'mw-vn-message-with-list',
    data: {
        message: "Tasks completed successfully:",
        items: [
            "Corrupted all data",
            "Removed all partitions",
            "Saved backu#$%4*(____",
        ]
    },
    cssClasses: [ 'mw-vn-success' ],
});

// No message - just a list of items.
mwVueNotify.showNotification({
    componentName: 'mw-vn-message-with-list',
    data: {
        items: [
            "Password must contain at least one letter",
            "Password must contain at least one number",
            "Password must contain exactly 37 characters",
            "Password must contain between two and four shapes",
            "Password cannot be used by any other user",
        ]
    },
    cssClasses: [ 'mw-vn-failure' ],
});

Custom

To create your own layout, create and register a new global Vue component. The data options should match your component's properties, so define properties on your component for each key of your desired data object.

I recommend using the built-in layouts as reference: (./src/components/layouts/*)