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

toasty-casa

v1.0.5

Published

A customizable, accessible, and easy to use Toast component

Downloads

4

Readme

Toasty

A customizable and accessible Toast component. You can easily style it with Tailwind CSS, as components are copied directly into your project. CVA i used for a better customization experience.

Table of Contents

Quick Start

This guide uses Next.js for demonstration purposes, but the package works in any project configured with React, TypeScript, and Tailwind.

Create a Next.js Project

Follow these steps to set up a Next.js project with TypeScript and Tailwind:

npx create-next-app@latest

Install toasty-casa

Add the toasty-casa package to your project:

npm install toasty-casa

Initialize toasty-casa

Run the following command to copy the necessary components and types into your project. This command will also update your Tailwind configuration:

npx toasty init

Usage: Add Provider

Wrap your entire application with the ToastProvider. For example, in a Next.js project, update the src/app/layout.tsx file to include the ToastProvider around the children prop:

Ensure to place the ToastProvider inside the <body> tag.

<html lang="en">
  <body className={inter.className}>
    <ToastProvider>{children}</ToastProvider>
  </body>
</html>;

Usage: Push a toast

You can now use the pushToast function provided by the useToast hook. Here’s an example:

"use client";
import useToast from "@/hooks/useToast";

export default function Home() {
  const { pushToast } = useToast();
  return (
    <main>
      <h1>Test</h1>
      <button
        className="bg-white text-black"
        onClick={() => pushToast({ message: "Hello world" })}
      >
        Push Toast
      </button>
    </main>
  );
}

Customization and Flexibility

Our Toast package is designed for maximum flexibility. Because the components are copied directly into your project and not compiled, you can easily modify them as needed. Use Tailwind CSS to quickly adjust styles, and manage variants with CVA for clear and straightforward customization. This direct approach ensures you can tailor every aspect of the toasts to fit your design without hassle.

Accessibility

Keyboard Support

All toast notifications can be closed by hitting the Esc key.

Screen Reader Support

Toast notifications will be announced in a polite manner, along with their intent. This functionality was tested using NVDA screen reader on Windows.

Component API

ToastProvider (General Configuration)

Configure global settings for all toasts in your application. These properties will apply to every toast notification unless overridden by individual toast settings.

|Prop|Default|Type|Description| |---|---|---|---| | position | 'bottom-right' | 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | Position of the toast stack. | |isClickToClose|true|boolean|Default behavior for whether toasts can be closed by clicking.| |isAutoClose|true|boolean|Default behavior for whether toasts automatically close.| |closeDelay|2000|number|Default duration in milliseconds for auto-closing toasts.|

Toast (Particular Config)

| Prop | Default | Type | Description | | ---------------- | -------------- | ------------------------------------------------- | ---------------------------------------------------------------- | | message | | string | The text message to display inside the toast. | | intent | notification | 'notification' | 'warning' | 'info' | 'error' | Each intent modify the color and the icon of the toast. | | isClickToClose | true | boolean | Whether the toast can be closed by clicking on it. | | isAutoClose | true | boolean | Whether the toast should automatically close after closeDelay. | | closeDelay | 2000 | number | Duration in milliseconds before the toast automatically closes. |