• Stars
    star
    151
  • Rank 240,863 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add notifications component to your javascript projects easily using wc-toast.

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

More Repositories

1

playground

Building user interface with HTML, CSS, and JavaScript only
JavaScript
6
star
2

cari-karya-seni

Cari seni buat inspirasi. Dibangun menggunakan ReactJS
JavaScript
2
star
3

webpack-vanilla

Webpack 5 Configuration for Vanilla JS
JavaScript
2
star
4

tn-ql

πŸ”΄ Unofficial GraphQL API for Indonesia National Park
TypeScript
2
star
5

kamoes

[WIP] Autocomplete feature to search a word in KBBI using Trie
TypeScript
2
star
6

sistem-pakar

Diagnosa tumor otak menggunakan metode Certainty Factor
JavaScript
2
star
7

integration-test-react

Integration Test in React
TypeScript
2
star
8

kamoes-api

[WIP] Unofficial Kamus Besar Bahasa Indonesia API
TypeScript
1
star
9

museum-macan-scraper

Node.js Scraper for museummacan.org collections
JavaScript
1
star
10

wiki-img-meta

Get Wikipedia Image Metadata
TypeScript
1
star
11

tn

πŸ”΄ Unofficial Indonesia National Parks Website
TypeScript
1
star
12

abdmmar.github.io

Ammar's Portfolio Web
HTML
1
star
13

kumparan-social

Kumparan - Frontend Technical Assessment
JavaScript
1
star
14

pvg-salesdash

Pintar Ventura Group Technical Test - Sales Dashboard. Built using React and Tailwind
JavaScript
1
star
15

galeri-nasional-scraper

koleksi galeri nasional indonesia and scraper
JavaScript
1
star
16

website

<Website/>
JavaScript
1
star
17

akgq

Digital Zine of Akyas and GenQ Special Edition: Islah 21 Reunion
TypeScript
1
star
18

sinema-indonesia

Dicoding Submission for Frontend Fundamental Course. Using ES6, Web Component, NPM, Webpack, and TailwindCSS.
CSS
1
star
19

abdmmar

1
star
20

galnas-api

Indonesia National Gallery API
TypeScript
1
star
21

galnas

Koleksi Galeri Nasional Indonesia
TypeScript
1
star
22

kwarts

[WIP] πŸ’Ž Webpack + Apollo + React + TypeScript + Styled-component starter pack
JavaScript
1
star