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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pixel-doez-planes/toast

v3.1.0

Published

A modern, feature-rich toast notification library for React with TypeScript support

Downloads

438

Readme

Toast Notifications - Made with Typescript React (.tsx)

A modern, feature-rich toast notification library for React with TypeScript support.

Features

  • 🎨 Multiple toast variants (success, error, warning, info, loading)
  • 📍 6 positioning options (top-left, top-center, top-right, bottom-left, bottom-center, bottom-right)
  • ⚡ Promise-based API for async operations
  • 🎭 Smooth slide and fade animations
  • 🎯 TypeScript-first with full type definitions
  • 🎨 Customizable (icons, duration, className, styles)
  • 🌓 Dark mode support
  • 📦 Tiny bundle size
  • 🚀 Zero dependencies (except React)

Installation

Via npm

npm install @pixel-doez-planes/toast

Via CDN

import { toast, ToastContainer } from 'https://cdn.jsdelivr.net/npm/@pixel-doez-planes/toast/dist/index.esm.js';

Quick Start

import { toast, ToastContainer } from '@pixel-doez-planes/toast';
import '@pixel-doez-planes/toast/dist/style.css';

function App() {
  return (
    <>
      <button onClick={() => toast({ title: 'Hello World!', variant: 'success' })}>
        Show Toast
      </button>
      <ToastContainer />
    </>
  );
}

Usage

Basic Toasts

// Success toast
toast({ 
  title: 'Profile updated successfully!', 
  variant: 'success' 
});

// Error toast
toast({ 
  title: 'Failed to save changes', 
  variant: 'error' 
});

// Warning toast
toast({ 
  title: 'Your session will expire soon', 
  variant: 'warning' 
});

// Info toast
toast({ 
  title: 'New features available', 
  variant: 'info' 
});

// Loading toast
toast({ 
  title: 'Uploading files...', 
  variant: 'loading' 
});

With Descriptions

toast({
  title: 'Upload Complete',
  description: 'Your file has been uploaded successfully.',
  variant: 'success'
});

Promise API

Perfect for async operations like API calls:

const uploadFile = async () => {
  const uploadPromise = fetch('/api/upload', {
    method: 'POST',
    body: formData
  });

  toast({
    title: 'Uploading...',
    variant: 'loading',
    promise: {
      promise: uploadPromise,
      loading: 'Uploading file...',
      success: 'File uploaded successfully!',
      error: 'Upload failed. Please try again.'
    }
  });
};

The toast will automatically:

  • Show loading state while the promise is pending
  • Switch to success when the promise resolves
  • Switch to error if the promise rejects

Custom Options

toast({
  title: 'Custom toast!',
  description: 'With extra customization',
  variant: 'success',
  duration: 5000,
  position: 'top-center',
  icon: '🎉',
  className: 'my-custom-toast',
  style: {
    background: '#333',
    color: '#fff',
  }
});

Dismiss Toasts

import { dismissToast } from '@pixel-doez-planes/toast';

// Get toast ID (await the promise)
const toastId = await toast({ title: 'Processing...', variant: 'loading' });

// Dismiss specific toast
dismissToast(toastId);

// Dismiss all toasts
dismissToast();

API Reference

Toast Function

toast(options: ToastOptions): Promise<string>

Returns a promise that resolves to a unique toast ID that can be used to dismiss it later.

Toast Options

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | title | string | ✅ | - | Main toast message | | description | string | ❌ | - | Optional subtitle/details | | variant | ToastVariant | ❌ | success | Toast type: 'success', 'error', 'warning', 'info', 'loading' | | position | ToastPosition | ❌ | 'bottom-right' | Toast position on screen | | duration | number | ❌ | 4000 | Duration in milliseconds (Infinity = permanent, 0 for loading toasts) | | icon | ReactNode | ❌ | - | Custom icon (emoji, string, or React element) | | className | string | ❌ | - | Additional CSS classes | | style | CSSProperties | ❌ | - | Inline styles | | dismissible | boolean | ❌ | true | Show dismiss button | | promise | PromiseOptions | ❌ | - | Promise handling configuration |

Promise Options

| Option | Type | Description | |--------|------|-------------| | promise | Promise<any> | The promise to track | | loading | string | Message while promise is pending | | success | string | Message when promise resolves | | error | string | Message when promise rejects |

ToastPosition Type

type ToastPosition =
  | 'top-left'
  | 'top-center'
  | 'top-right'
  | 'bottom-left'
  | 'bottom-center'
  | 'bottom-right';

TypeScript

This library is written in TypeScript and includes complete type definitions.

import { 
  toast, 
  ToastOptions, 
  ToastVariant, 
  ToastPosition 
} from '@pixel-doez-planes/toast';

const options: ToastOptions = {
  title: 'Typed toast!',
  description: 'Full IntelliSense support',
  variant: 'success',
  duration: 5000,
  position: 'top-center',
};

toast(options);

Type Definitions

type ToastVariant = 'success' | 'error' | 'warning' | 'info' | 'loading';

type ToastPosition =
  | 'top-left'
  | 'top-center'
  | 'top-right'
  | 'bottom-left'
  | 'bottom-center'
  | 'bottom-right';

interface ToastOptions {
  title: string;
  description?: string;
  variant: ToastVariant;
  position?: ToastPosition;
  duration?: number;
  icon?: ReactNode;
  className?: string;
  style?: React.CSSProperties;
  dismissible?: boolean;
  promise?: {
    promise: Promise<any>;
    loading: string;
    success: string;
    error: string;
  };
}

Other examples (full page examples)

  import { Toast, ToastContainer } from "pixel-doez-planes/toast"
  import { Button } from "btn-path"

  export default function ExampleOne() {
    const form_data = {}
    function submit() {
      toast({
        title: "Your form has been submitted",
        description: "${form_data}",
        variant: "success",
      });
    }
    return (
      <div className="tailwind-css-or-classname">
        <Button onClick={submit()}></Button>
        </div>
    )
  }

  import { Toast, ToastContainer } from "pixel-doez-planes/toast"
  import { Button } from "@/ui/button"
  
  export default function ExamplePromise() {
    const formData = ['formData']
    const uploadFile = async () => {
      const uploadPromise = fetch('api/createUser', {
        method: "POST",
        body: formData
      })
      toast({
        title: 'Uploading...',
        variant: 'loading',
        promise: {
          promise: uploadPromise,
          loading: 'Uploading file...',
          success: 'File uploaded successfully!',
          error: 'Upload failed. Please try again.'
        }
      });
    }
    
    return (
      <div className="tailwindcss-config">
        
        <Button className="submit" onClick={uploadFile()}>
        //Submit
        </Button>
      </div>
    )
  }

License

MIT