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

sonner-stimulus

v0.1.2

Published

An opinionated toast component for Hotwire (Stimulus)

Readme

Sonner Stimulus

An opinionated toast component for Hotwire (Stimulus).

Stimulus controllers for Sonner toast notifications. Built on top of sonner-vanilla.

For complete Rails setup: See the main rails README.

Installation

npm install sonner-stimulus
# or
yarn add sonner-stimulus

This package has sonner-vanilla as a dependency and @hotwired/stimulus as a peer dependency.

Setup

Register Controllers

// app/javascript/controllers/index.js
import { application } from "./application";
import SonnerControllers from "sonner-stimulus";

application.register("toaster", SonnerControllers.toaster);
application.register("toast", SonnerControllers.toast);
application.register("toast-dismiss", SonnerControllers["toast-dismiss"]);

Or import individually:

import { ToasterController, ToastController, ToastDismissController } from "sonner-stimulus";

application.register("toaster", ToasterController);
application.register("toast", ToastController);
application.register("toast-dismiss", ToastDismissController);

Import Styles

@import "sonner-stimulus/styles.css";

Controllers

ToasterController

Creates the toast container. Add once to your layout.

<div data-controller="toaster"
     data-toaster-position-value="bottom-right"
     data-toaster-theme-value="light"
     data-toaster-rich-colors-value="true"
     data-toaster-close-button-value="false"
     data-toaster-expand-value="false"
     data-toaster-duration-value="4000"
     data-toaster-visible-toasts-value="3"
     data-toaster-gap-value="14"
     data-toaster-offset-value="24px">
</div>

Values

| Value | Type | Default | Description | |-------|------|---------|-------------| | position | String | 'bottom-right' | Position: 'top-left', 'top-right', 'top-center', 'bottom-left', 'bottom-right', 'bottom-center' | | theme | String | 'light' | Theme: 'light', 'dark', 'system' | | richColors | Boolean | false | Colorful backgrounds for toast types | | closeButton | Boolean | false | Show close button on toasts | | expand | Boolean | false | Expand toasts by default | | duration | Number | 4000 | Default duration in milliseconds | | visibleToasts | Number | 3 | Maximum visible toasts | | gap | Number | 14 | Gap between toasts in pixels | | offset | String | '24px' | Offset from viewport edge |


ToastController

Displays a toast message. The element removes itself after showing the toast.

<div data-controller="toast"
     data-toast-type-value="success"
     data-toast-message-value="Operation completed!"
     data-toast-description-value="Your changes have been saved.">
</div>

Values

| Value | Type | Required | Default | Description | |-------|------|----------|---------|-------------| | type | String | No | 'default' | Toast type: 'default', 'success', 'error', 'warning', 'info', 'loading' | | message | String | Yes | - | Toast message | | description | String | No | - | Additional description | | duration | Number | No | - | Duration in milliseconds | | dismissible | Boolean | No | true | Can be dismissed by user | | richColors | Boolean | No | - | Override toaster setting | | closeButton | Boolean | No | - | Show close button | | position | String | No | - | Override toaster position | | id | String | No | - | Custom toast ID |


ToastDismissController

Dismisses toasts programmatically.

<!-- Dismiss specific toast -->
<button data-controller="toast-dismiss"
        data-action="click->toast-dismiss#dismiss"
        data-toast-dismiss-id-value="my-toast-id">
  Dismiss
</button>

<!-- Dismiss all toasts -->
<button data-controller="toast-dismiss"
        data-action="click->toast-dismiss#dismissAll">
  Clear All
</button>

Values

| Value | Type | Description | |-------|------|-------------| | id | String | Toast ID to dismiss (for dismiss action) |

Actions

| Action | Description | |--------|-------------| | dismiss | Dismiss toast with specified ID | | dismissAll | Dismiss all toasts |


Using toast() in JavaScript

The toast function is re-exported for use in your own Stimulus controllers:

import { Controller } from "@hotwired/stimulus";
import { toast } from "sonner-stimulus";

export default class extends Controller {
  greet() {
    toast.success("Hello!", { description: "Welcome back." });
  }

  async save() {
    toast.promise(this.saveData(), {
      loading: "Saving...",
      success: "Saved!",
      error: "Failed to save",
    });
  }

  saveData() {
    return fetch("/api/save", { method: "POST" });
  }
}

License

MIT

To Publish

cd rails/packages/stimulus

# Build
npm run build

# Preview what will be published
npm publish --dry-run

# Publish (you'll need to be logged in: npm login)
npm publish