Toaster

One notification stack that collapses to a pill and opens into the Island, with operations, retry and cancel. From npm as @cloudlet/toast, or as a shadcn registry item themed with your tokens.

On this page

Preview

Every notification goes into one stack, newest first, collapsed at rest to a single pill with tails for the ones behind it and a badge with the count. Activating the pill opens the Island: one surface with a slider over every notification, moved by a swipe, the arrow keys or the trackpad, where you read, retry, cancel or close. Escape collapses it with every notification kept.

The controls below move this page's Toaster, and the code under them does the same in your app. The buttons in Examples show their notifications where the controls put it.

Position
Side
Direction
Customize the look
Toaster
<Toaster />

Need a plain toast, without the Island and the motion? Sonner is a great choice.

Installation

Cloudlet installs as one package, @cloudlet/toast, or as the shadcn registry item toaster: a small wrapper you own on top of the same package. The @cloudlet namespace and installing an item by its address are on the kit's Installation.

Add the package. React 18 or 19, nothing else to configure.

Terminal
npm install @cloudlet/toast

Import the styles once, mount one Toaster per controller, call show from anywhere below it.

notifications.tsx
import '@cloudlet/toast/styles.css';
import { CloudletProvider, createCloudlet, Toaster, useCloudlet } from '@cloudlet/toast';

function SaveNotice() {
  const cloudlet = useCloudlet();
  return <button onClick={() => cloudlet.show({ title: 'Saved', kind: 'success' })}>Notify</button>;
}

// The browser application bootstrap creates and owns this controller.
export function Notifications({ controller }: { controller: ReturnType<typeof createCloudlet> }) {
  return <CloudletProvider controller={controller}>
    <SaveNotice />
    <Toaster />
  </CloudletProvider>;
}

Requirements

  • React and React DOM ^18.2.0 || ^19.0.0 are peer dependencies. Use a matching pair: the same version of react and react-dom.
  • ESM only. The package ships ES modules with TypeScript declarations; there is no CommonJS or UMD build. Deep imports into its internals are closed on purpose: everything public comes from @cloudlet/toast.
  • No runtime dependencies. The springs and tweens that move the stack and the Island are Cloudlet's own.
  • No Tailwind or shadcn/ui requirement. The npm package styles itself with plain CSS and custom properties; the shadcn item only bridges them to your tokens.
  • Browsers. Chromium and Edge 111, Firefox 114, Safari and iOS 16.4 or newer. The automated suite runs on current versions, and the minimum versions are checked by hand (What is tested).
  • TypeScript. The declarations work with strict and exactOptionalPropertyTypes; with the latter, leave an optional field out rather than passing undefined.

Import the styles

Cloudlet's CSS is one explicit file. Import it once, where your application imports its global CSS: the client entry of a single-page app, or the root layout of a Next.js App Router project.

app/layout.tsx
import '@cloudlet/toast/styles.css';

In the Next.js Pages Router, global CSS must come from the custom App, so the import goes into pages/_app.tsx. The stylesheet does not need a build plugin; under a strict Content Security Policy keep it external, as described in Content Security Policy.

The shadcn registry item

The toaster item copies two files into your project and adds @cloudlet/toast as a dependency:

  • components/ui/toaster.tsx: a thin "use client" adapter that renders the Provider and the Toaster for a controller you pass in. Every public Toaster option passes through unchanged.
  • components/ui/toaster.css: a theme bridge that maps your shadcn tokens (--popover, --popover-foreground, --muted-foreground, --border, --ring, --accent, --font-sans) to Cloudlet's tokens.

Both files are yours to edit. The notification runtime itself stays in the package: the item copies no controller, renderer or animation code.

The wrapper deliberately does not create a controller: a client component owns it, as notification-owner.tsx in the shadcn tab above does, for the reasons in SSR & Next.js.

A few details of the bridge:

  • The wrapper imports @cloudlet/toast/styles.css and then ./toaster.css; keep that order. In the Pages Router, move both imports into pages/_app.tsx in the same order and remove them from the wrapper.
  • Define light tokens on :root and dark tokens on your .dark root, then pass the matching theme="light" or theme="dark" to the Toaster so the native color-scheme agrees.
  • The tokens must be inherited by the portal container. A wrapper element around your React tree does not theme the default portal on document.body.

Usage

Create one controller where your application starts, and render the Toaster inside its Provider. In the Next.js App Router a client component creates the controller instead: SSR & Next.js has the setup.

main.tsx
import '@cloudlet/toast/styles.css';
import { createRoot } from 'react-dom/client';
import { CloudletProvider, createCloudlet, Toaster } from '@cloudlet/toast';
import { App } from './app';

// Once, when the browser application starts.
const cloudlet = createCloudlet();

createRoot(document.getElementById('root')!).render(
  <CloudletProvider controller={cloudlet}>
    <App />
    <Toaster />
  </CloudletProvider>,
);

Any component under the Provider shows a notification:

app.tsx
import { useCloudlet } from '@cloudlet/toast';

export function App() {
  const cloudlet = useCloudlet();
  return <button onClick={() => cloudlet.show({ title: 'Synced to the cloud', kind: 'success' })}>Sync</button>;
}

Every call returns a value you can act on rather than a promise that is silently dropped: show tells you whether a record was created, deduplicated or rejected and why, and dismiss and update report a stale handle instead of doing nothing (Show a notification).

Controller, Provider, Toaster

Cloudlet splits into a core that knows nothing about the DOM and a React shell that renders it.

  • createCloudlet() returns a controller: the owner of notifications, their time, operations and announcements. Creating it allocates no timers and touches no DOM.
  • CloudletProvider hands the controller to a React tree. It does not render anything itself.
  • useCloudlet() returns the controller to any component under the Provider, so a save button can call show without prop drilling.
  • Toaster renders the stack and the Island for the controller it finds in context, in a portal after mount. Unmounting it pauses visible time and keeps every record; mounting it again resumes the same queue.

What stays with your application

Cloudlet owns the stack, its time and its accessibility. A few things stay yours by design:

  • The controller's lifetime. One controller per browser session or server request, disposed only when it ends: see One controller per session or request and When to dispose.
  • Important data. A notification is a notice, not a record: anything the user must not lose also lives in your main interface.
  • Words. Every label, announcement and fallback message is a string or a formatter you can replace (Labels & announcements), so the Toaster speaks your product's language.
  • Styling. Cloudlet ships CSS tokens for colour, radius and spacing and adds your class names per part (Styling); it does not require Tailwind or shadcn/ui.

Examples

Kinds

Five kinds of weather. Success and info drift off after six seconds; the rest stay until you close them. More in Notifications & time.

Snippets assume const cloudlet = useCloudlet(); — the buttons call them on this page’s own Toaster.

success
cloudlet.show({ title: 'Synced to the cloud', kind: 'success' });

Content

A title, a line of description, rich text or an icon of your own. More in Notifications & time.

title-only
cloudlet.show({ title: 'A small cloud drifted by' });

Actions

A command, a real link, and a command that fails once and offers a retry. More in Operations & cancellation.

action-command
cloudlet.show({
  title: 'Photo moved to the archive',
  action: {
    kind: 'command',
    label: 'Undo',
    run: () => {
      cloudlet.show({ title: 'Photo is back in the sky', kind: 'success' });
    },
  },
});

Forms

A field right in the Island: a quick reply, a note with a check, and a send that fails once. More in Forms.

form-reply
cloudlet.show({
  title: 'A cloud asks where to drift',
  action: {
    kind: 'form',
    label: 'Send',
    fields: [{ name: 'place', kind: 'text', label: 'Where to', required: true }],
    run: ({ values }) => {
      cloudlet.show({ title: `Drifting to ${values.place}`, kind: 'success' });
    },
  },
});

Promises

track() follows an operation from pending to its result; update() changes a card in place. More in Operations & cancellation.

track-resolve
cloudlet.track(new Promise((resolve) => setTimeout(resolve, 1500)), {
  pending: { title: 'Condensing water vapour…' },
  success: { title: 'A fresh cloud formed' },
  error: { title: 'The cloud evaporated' },
});

Attention

Whether a notification opens the Island on its own: auto, open or stack. More in Notifications & time.

attention-auto
cloudlet.show({
  title: 'Wind is picking up',
  description: { kind: 'text', text: 'Gusts up to 40 km/h this afternoon.' },
  attention: 'auto',
});

Stack

Newest on top, one pill at rest. Push it past 100 and the badge counts what was missed. More in Notifications & time.

burst
for (const name of ['Cumulus', 'Stratus', 'Cirrus', 'Nimbus', 'Altocumulus']) {
  cloudlet.show({ title: `${name} drifted by` });
}

Agent

An agent in your app can read the stack and act on it through the agent bridge, experimental for now. The adapter ships in the package as @cloudlet/toast/agent; connect the controller with one line:

toaster-agent.tsx
'use client';

import { createAgent } from '@cloudlet/agent';
import { useCloudlet } from '@cloudlet/toast';
import { toasterAgent } from '@cloudlet/toast/agent';
import { useEffect } from 'react';

const agent = createAgent();

export function ConnectToasterAgent() {
  const cloudlet = useCloudlet();
  useEffect(() => agent.connect(toasterAgent(cloudlet)), [cloudlet]);
  return null;
}

The snapshot then holds the Toaster (open, close, clear, acknowledge) and each notification (dismiss, show, press, fill, submit, cancel, retry, by state). Pressing an action and submitting a form need a person unless the action says otherwise with its agent marker: 'allow' lets an agent press it, 'deny' never. A step that needs a person opens the Island on its notification for them. Links are never opened, and what a person typed never reaches the agent. Every event and CloseNotice names who caused it in source. Records, verbs and messages: toasterAgent.

API Reference

ExportWhat it isReference
createCloudletCreates a controller, the object that owns every notification, its time and its operations.createCloudlet
CloudletProviderHands a controller to a React tree; renders nothing itself.Toaster props
useCloudletReturns the controller of the nearest Provider.Toaster props
ToasterRenders the stack and the Island of that controller, in a portal after mount.Toaster props

The controller's methods are on Controller, the other public types on Types.