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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@toastly/toastly

v1.1.3

Published

A lightweight React library for **toasts**, **alert modals** and **confirm modals**, triggered from anywhere in your app with a simple imperative API. No hooks or context needed at the call site.

Readme

Toastly

A lightweight React library for toasts, alert modals and confirm modals, triggered from anywhere in your app with a simple imperative API. No hooks or context needed at the call site.

Features

  • Toast notifications with variants (info, success, warning, error)
  • Loading toasts, auto-dismiss and manual dismiss
  • Alert and confirm modals (close with Esc, backdrop click, or buttons)
  • Imperative API: call toastly.add(...) from components, utilities, or outside React
  • Written in TypeScript, fully typed
  • Works with Next.js (client components, "use client")

Installation

npm install @toastly/toastly

react and react-dom are required as peer dependencies.

Setup

Wrap your app with ToastlyProvider. It listens for events and renders toasts and modals.

import { ToastlyProvider } from "@toastly/toastly";

export default function App() {
  return (
    <ToastlyProvider>
      {/* your app */}
    </ToastlyProvider>
  );
}

Next.js (App Router): put the provider in app/layout.tsx. It is already a client component, so it can be imported from a server layout.

Styles are bundled with the package (dist/index.css). If your bundler does not load them automatically, import them manually:

import "@toastly/toastly/index.css";

Usage

import { toastly } from "@toastly/toastly";

Toasts

toastly.add({ message: "Profile saved", variant: "success" });

toastly.add({
  message: "Something went wrong",
  variant: "error",
  autoDismissIn: 5000, // ms
  allowDismiss: true,  // shows a close button
});

Give a toast an id to dismiss it programmatically. A toast with an id that is already displayed is ignored.

toastly.add({ id: "upload", message: "Uploading...", loading: true });

// later
toastly.dismiss("upload");

Alert

toastly.alert({
  message: "Your session is about to expire.",
});

Confirm

toastly.confirm({
  title: "Delete this post?",
  message: "This action cannot be undone.",
  onConfirm: () => deletePost(),
  onCancel: () => console.log("Cancelled"),
});

message accepts any React node:

toastly.confirm({
  message: <p>Delete <b>{post.title}</b>?</p>,
  onConfirm: () => deletePost(post.id),
  onCancel: () => {},
});

API

<ToastlyProvider>

| Prop | Type | Description | | ---------- | ----------------- | ----------------------------------- | | children | React.ReactNode | Your app (required) | | position | ToastlyPosition | Position of the toast stack (default: "bl") | | duration | number \| \${number}`| Default toast duration in milliseconds (default:3000; overridden by autoDismissIn`) |

toastly.add(toast: ToastEvent)

| Option | Type | Description | | --------------- | --------------------------------------------- | -------------------------------------------- | | message | string | Text displayed in the toast (required) | | id | string | Custom identifier, used to dismiss it later | | variant | "info" \| "success" \| "warning" \| "error" | Visual style and icon | | allowDismiss | boolean | Show a button to close the toast manually | | autoDismissIn | number | Duration in milliseconds before auto-closing | | loading | boolean | Display a spinner |

toastly.dismiss(id: string)

Closes the toast with the given id.

toastly.alert(alert: AlertEvent)

| Option | Type | Description | | --------- | ----------------- | -------------------------------------------------------------------- | | message | React.ReactNode | Modal content (a default text is shown if omitted) |

toastly.confirm(confirm: ConfirmEvent)

| Option | Type | Description | | ----------- | ----------------- | -------------------------------------------------- | | title | string | Modal title | | message | React.ReactNode | Modal content (a default text is shown if omitted) | | onConfirm | () => void | Called when the user clicks Ok (required) | | onCancel | () => void | Called when the user clicks Cancel (required) |

Exports

import { ToastlyProvider, AlertModal, ConfirmModal, toastly } from "@toastly/toastly";

import type {
  ToastVariant,
  ToastEvent,
  AlertEvent,
  ConfirmEvent,
} from "@toastly/toastly";

Development

npm install
npm run dev     # run the example app
npm run build   # build the library into dist/

How it works

toastly dispatches CustomEvents on window (toastly:add-alert, toastly:dismiss-alert, toastly:alert, toastly:confirm). ToastlyProvider subscribes to them and renders the UI. This means toastly.* must be called in the browser (event handlers, effects), not during server rendering.

License

MIT