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

toastbar

v1.0.33

Published

A Vue 3 plugin for toast notifications with emojis

Downloads

254

Readme

Toastbar

Toastbar is a plugin for displaying toast notifications. It provides a simple way to show info, success, warning, and error messages in your Web applications.

Features

  • Info, Success, Warning, and Error Toasts:
    • Easily display different types of messages.
  • Easy Integration:
    • Simple setup with Vue 3.
  • Themes:
    • By default its light theme and can be changed to dark if need.

Installation

To install toastbar, you need to have npm installed. Then, you can use one of the following commands:

npm install toastbar

Usage Setup for Vue3

  1. Import and use the plugin in your main.js or main.ts file:
import { createApp } from 'vue';
import App from './App.vue';
import toastPlugin from 'toastbar'; // Import the plugin

const app = createApp(App);
app.use(toastPlugin); // Use the plugin
app.mount('#app');
  1. Include the ToastBar component in your App.vue file (optional):
<!-- App.vue -->
<template>
  <div id="app">
    <ToastBar />
    <router-view />
  </div>
</template>

<script>
import ToastBar from '../src/components/exampleComponent.vue';

export default {
  components: {
    ToastBar
  }
};
</script>
  1. Use the toast() method to display a toast notification: You can now use the toast service in any Vue component. Here’s an example:
<!-- src/components/exampleComponent.vue -->
<template>
  <div>
    <button @click="showInfoToast">Show Info Toast</button>
    <button @click="showSuccess">Show Success</button>
    <button @click="showWarning">Show Warning</button>
    <button @click="showError">Show Error</button>
  </div>
</template>

<script>
export default {
  methods: {
    showInfoToast() {
      this.toast.info('This feeds Info!', 'dark-theme'); // This will show in dark theme
    },
    showSuccess() {
      this.toast.success('Operation successful!'); // This is default so white background toast
    },
    showWarning() {
      this.toast.warning('This is a warning!', 'light-theme'); // This will show in light theme
    },
    showError() {
      this.toast.error('An error occurred!'); // This is default so white background toast
    }
  }
};
</script>

Usage Setup for React JS

Installation

To install toastbar, you need to have npm installed. Then, you can use one of the following commands:

npm install toastbar

  1. Import and use the plugin in your index.js file:

Add the below code in your index.js

import toastPlugin from 'toastbar';
import { createApp } from 'vue';

// Create a Vue app instance and use the toastPlugin
const app = createApp({});
app.use(toastPlugin);

// mount the Vue app to a temperary container
const container = document.createElement('div');
document.body.appendChild(container);
app.mount(container);

// Add the toast function to the global window object for easy access

window.toast = app.config.globalProperties.toast;

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

reportWebVitals(); 
  1. Create your component to use the toast feature
import React from 'react';

const ToastComponent = () => {

  const showInfoToast = () => {
    window.toast.info('Info message', 'dark-theme');
  };

  const showSuccessToast = () => {
    window.toast.success('Success message');
  };

  const showWarningToast = () => {
    window.toast.warning('Warning message');
  };

  const showErrorToast = () => {
    window.toast.error('Error message');
  };

  return (
    <div>
      <button onClick={showInfoToast}>Show Info Toast</button>
      <button onClick={showSuccessToast}>Show Success Toast</button>
      <button onClick={showWarningToast}>Show Warning Toast</button>
      <button onClick={showErrorToast}>Show Error Toast</button>
    </div>
  );
};

export default ToastComponent;

API Reference

Toast Service Methods

  • info(message: string);
    • Displays a info toast with the provided message.
  • success(message: string);
    • Displays a success toast with the provided message.
  • warning(message: string);
    • Displays a warning toast with the provided message.
  • error(message: string);
    • Displays an error toast with the provided message.

Props for ToastBar Component

  • message: String
    • The message to be displayed in the toast.
  • type: String
    • The type of toast (success, warning, error).
  • theme: String
    • The theme of toast (light-theme, dark-theme).

License

toastbar is licensed under the MIT License