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

wc-toast

v1.3.1

Published

Add notifications component easily using wc-toast. Vanilla JavaScript web component notification inspired by react-hot-toast

Downloads

938

Readme

wc-toast

Add notifications component easily using wc-toast. Vanilla JavaScript web component notification inspired by react-hot-toast

Features

  • ✍🏻 Easy to use
  • 🌏 Use anywhere you like - React? Vue? Svelte? Everywhere!
  • 👋🏻 Emoji and SVG Support
  • 🎨 Customizable
  • 🚥 Promise API
  • Accessible - Tested using Windows 10 Narrator
  • 🍃 Lightweight - Only ~3.6KB Minified+Gzipped including styles
  • 💙 Dark Mode

Installation

Add from NPM

npm i wc-toast

or import from CDN

import { toast } from 'https://cdn.skypack.dev/wc-toast';

Demo

Open wc-toast demo on Stackblitz

or just try it on https://abdmmar.github.io/wc-toast

Usage and Example

Basic Usage

  1. Make sure you've add wc-toast to your app through NPM or CDN. See Installation for more details.

  2. Add wc-toast to your app and placed it at the top.

    <body>
       <wc-toast></wc-toast>
       <button class="toast"></button>
    </body>
  3. Start toasting! Call it from anywhere in your app.

    import { toast } from 'wc-toast'
    // or if you use CDN:
    // import { toast } from 'https://cdn.skypack.dev/wc-toast';
    
    document.querySelector('.toast').addEventListener('click', () => {
      toast('Hello world!');
    });

Example

Guide

React TypeScript

If you are using the wc-toast in a React TypeScript project, you'll need to add wc-toast.d.ts type definitions to ensure proper type checking.

// wc-toast.d.ts
import { WCToast, WCToastItem, WCToastIcon, WCToastContent, WCToastCloseButton } from 'wc-toast';

declare global {
  namespace JSX {
    interface IntrinsicElements {
      'wc-toast': React.DetailedHTMLProps<React.HTMLAttributes<WCToast>, WCToast>;
      'wc-toast-item': React.DetailedHTMLProps<React.HTMLAttributes<WCToastItem>, WCToastItem>;
      'wc-toast-icon': React.DetailedHTMLProps<React.HTMLAttributes<WCToastIcon>, WCToastIcon>;
      'wc-toast-content': React.DetailedHTMLProps<
        React.HTMLAttributes<WCToastContent>,
        WCToastContent
      >;
      'wc-toast-close-button': React.DetailedHTMLProps<
        React.HTMLAttributes<WCToastCloseButton>,
        WCToastCloseButton
      >;
    }
  }
}

If you are using Vite, place your wc-toast.d.ts inside src/ folder

Styling

You can customize style of wc-toast-item through custom properties

Default

wc-toast-item
--wc-toast-background: #fff;
--wc-toast-max-width: 350px;
--wc-toast-stroke: #2a2a32;
--wc-toast-color: #000;
--wc-toast-font-family: 'Roboto', sans-serif;
--wc-toast-font-size: 16px;
--wc-toast-border-radius: 8px;
--wc-toast-content-margin: 4px 10px;

API

toast()

toast(
   message: string,
   options: {
      icon: {
        type: 'success' | 'loading' | 'error' | 'custom' | 'svg';
        content: string;
   };
   duration: number | 4000;
   theme: {
      type: 'light' | 'dark' | 'custom';
      style: {
         background: string;
         color: string;
         stroke: string;
      };
   };
})

wc-toast

<wc-toast position="top-left | top-right | top-center | bottom-left | bottom-right | bottom-center">
  <slot></slot>
</wc-toast>

wc-toast-item

<wc-toast-item
  type="success | loading | error | blank | custom"
  theme="light | dark | custom"
  duration="number | 3500 | 6000000"
>
  <slot></slot>
</wc-toast-item>

wc-toast-icon

<wc-toast-icon icon="string" type="success | loading | error | blank | custom">
  <slot name="svg"></slot>
</wc-toast-icon>

wc-toast-content

<wc-toast-content message="string">
  <slot name="message"></slot>
  <slot name="content"></slot>
</wc-toast-content>

wc-toast-close-button

<wc-toast-close-button></wc-toast-close-button>

Contributing

See CONTRIBUTING.md

Credit

Thanks to react-hot-toast for an amazing library and such an inspiration. If you build a React project and need notifications, you should check out this library.

License

MIT License