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

@treditpackage/toast

v1.0.2

Published

**Headless-ish toast system for React** with a context-based API, a flexible viewport component, and configurable styling via CSS variables.

Readme

@treditpackage/toast

Headless-ish toast system for React with a context-based API, a flexible viewport component, and configurable styling via CSS variables.

  • Framework: React (TypeScript-ready)
  • Peer deps: react >=17, react-dom >=17

Installation

npm install @treditpackage/toast
# or
yarn add @treditpackage/toast
# or
pnpm add @treditpackage/toast

Basic usage

  1. Wrap your app with ToastProvider.
  2. Render ToastViewport once (usually near the root).
  3. Use the useToast hook to show toasts.
// src/main.tsx or src/App.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import { ToastProvider, ToastViewport } from '@treditpackage/toast';
import '@treditpackage/toast/toast.css';

import { App } from './App';

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <ToastProvider>
      <App />
      {/* Place once, typically at root */}
      <ToastViewport />
    </ToastProvider>
  </React.StrictMode>,
);

Then in any component inside the provider:

import { useToast } from '@treditpackage/toast';

export function Example() {
  const { showToast } = useToast();

  const handleClick = () => {
    showToast({
      title: 'Saved successfully',
      message: 'Your changes have been stored.',
      variant: 'success',
      placement: 'top-right',
    });
  };

  return <button onClick={handleClick}>Show toast</button>;
}

Importing styles

The package ships with a default stylesheet. Import it once in your app entry (or any global styles file):

import '@treditpackage/toast/toast.css';

You can override the default theme using CSS variables in your own stylesheet:

:root {
  --color-toast-success-bg: #022c22;
  --color-toast-success-border: #16a34a;
  --color-toast-success-text: #ecfdf5;
  --color-toast-success-icon: #4ade80;

  --color-toast-info-bg: #020617;
  --color-toast-info-border: #0ea5e9;
  --color-toast-info-text: #e5f4ff;
  --color-toast-info-icon: #38bdf8;

  /* ...warning, error, question variables... */
}

API

ToastProvider

import { ToastProvider } from '@treditpackage/toast';

<ToastProvider>
  {/* your app */}
</ToastProvider>;

Wrap your React tree with ToastProvider to make the toast context available. Required for useToast and ToastViewport to work.

useToast

import { useToast } from '@treditpackage/toast';

const { showToast, dismissToast, clearToasts } = useToast();
  • showToast(input: ShowToastInput): string: create a new toast and returns its id.
  • dismissToast(id: string, reason?, exitAnimation?): programmatically dismiss a toast.
  • clearToasts(): remove all toasts.

ShowToastInput (all fields are optional and strongly typed):

  • title?: string: toast title (required at runtime unless you set defaults via ToastViewport).
  • message?: string: body text.
  • variant?: 'info' | 'success' | 'warning' | 'error' | 'question'.
  • placement?: 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center'.
  • durationMs?: number: auto-dismiss timeout in ms (default ~3600ms).
  • dismissible?: boolean: whether close button / click-to-dismiss is enabled.
  • poppable?: boolean: whether clicking the toast should “pop” it.
  • stackInsert?: 'front' | 'end': where new toasts appear in the stack.
  • appearDelayMs?: number: delay for entrance animation.
  • animation_appear?: boolean, animation_cascade?: boolean, exitAnimation?: 'fade' | 'pop'.
  • Sizing & shape: width, minHeight, padding, shape ('rounded' | 'square' | 'pill'), borderRadius, titleFontSize, bodyFontSize.
  • Actions: actions?: ToastAction[] (see below).
  • Colors: colorOverrides?: ToastColorOverrides to override palette per-toast.
  • Callbacks: onClick?(toast), onAction?(actionId, toast).

Example with actions:

showToast({
  title: 'Update available',
  message: 'Reload to get the latest version.',
  variant: 'info',
  actions: [
    {
      id: 'reload',
      label: 'Reload',
      tone: 'primary',
      onPress: () => window.location.reload(),
    },
  ],
});

ToastViewport

import { ToastViewport } from '@treditpackage/toast';

function Root() {
  return (
    <ToastProvider>
      <App />
      <ToastViewport />
    </ToastProvider>
  );
}

Primary responsibilities:

  • Renders all active toasts using the internal layout and animations.
  • Allows you to set default values for toasts shown via showToast while this viewport is mounted.
  • Controls placement offsets, max width, z-index, and box-shadow.

Props:

  • topOffset?: number | string (default 96)
  • rightOffset?: number | string (default 20)
  • bottomOffset?: number | string (default 20)
  • leftOffset?: number | string (default 20)
  • maxStackWidth?: number | string (default 420)
  • zIndex?: number (default 2000)
  • placement?: ToastPlacement: force a single placement; otherwise all placements are used.
  • type?: ToastVariant: default variant for toasts created while this viewport is mounted.
  • title?: string, message?: string, durationMs?: number: default values for toasts.
  • shadow?: string: custom box-shadow for each toast card.

Example setting defaults per viewport:

<ToastViewport
  placement="bottom-center"
  type="success"
  durationMs={4000}
/>

Any showToast call made while this viewport is mounted will use those defaults unless overridden in the call.

TypeScript support

The package is written in TypeScript and ships with type declarations. All exported types (such as ToastVariant, ToastPlacement, ShowToastInput, ToastAction, etc.) are available:

import type { ShowToastInput, ToastVariant } from '@treditpackage/toast';

Summary

  • Install @treditpackage/toast and import @treditpackage/toast/toast.css once.
  • Wrap your app with ToastProvider.
  • Render a single ToastViewport (configure placement/offsets via props).
  • Call useToast().showToast(...) anywhere inside the provider to display toasts.