组件

Sonner

Toasts as slips of paper tossed onto the desk. A guest check for success, a pink sticky for errors, yellow for warnings, blue for news; stacked, swipeable, with drawn icons, action buttons, promise toasts and tape or a pin to hold them down. Built on the sonner package: you keep its `toast()` API.

安装

terminal
npx shadcn@latest add @wobko/sonner

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Types

Six kinds of paper: a plain slip, a green guest check for success, a pink sticky for errors, yellow for warnings, blue for news, and a slip with a spinning loader. Each has its own drawn icon and a slightly different tilt.

Promise

toast.promise follows a request: one slip that starts as a loader, then turns into a success (or an error) paper when the promise settles. Pass a function for the message to use the result.

Action and undo

The real pattern: do the thing at once, then offer to take it back. The action is a highlighter-marked button (a Wobko Button also works as the label); the page updates when you press it.

Positions, tape and pin

Six places to stack toasts (slips not on the right are dropped from above instead of tossed from the corner), and two ways to hold them down: masking tape or a push-pin.

Demo

Official `sonner-demo`: one button, one toast with a description and an Undo action. The slip is tossed onto the desk; Undo is a highlighted word, not a filled button. Official code mounts `<Toaster />` once at the app root; here the example mounts its own so it works on its own.

Types

Official `sonner-types`: default, success, info, warning, error and a promise that goes from loading to success after two seconds. Each type is a different stock of paper (guest check, blue, yellow and pink stickies), so meaning never rests on color alone.

API 参考

Toaster

Mount it once near the root of the app. It wraps sonner's Toaster in unstyled mode and gives each toast the paper look with classes on sonner's own elements, so stacking, swiping, timers, hover-to-expand and the aria-live region are all sonner's. Every sonner prop works (`position`, `expand`, `visibleToasts`, `duration`, `gap`, `offset`, `closeButton`, `dir`, `hotkey`, `toastOptions`, `icons`, `id` ...).

属性类型默认值说明
decoration"none" | "tape" | "pin""none"Hold every slip to the page with a strip of masking tape or a push-pin (drawn with CSS on the content box; hidden in calm density).
portalbooleanfalseRender the stack into `document.body`. The stack is `position: fixed`, so an ancestor with `container-type` (Tailwind's `@container`), `transform`, `filter` or `contain: layout` becomes its containing block and pins the toasts to that box instead of the window. Mount `<Toaster />` at the app root and you never need this; pass `portal` when it has to live inside such a wrapper. The stack appears after the first client render, and repeats the InkProvider's density, motion and theme.
theme"light" | "dark" | "system""light"Passed to sonner. There is no next-themes here; Wobko themes come from CSS variables and the InkProvider, so the slips follow them without a prop.
iconsToastIcons-Override the drawn icons: success (circle-check), info, warning (triangle-alert), error (octagon-x), loading (loader-circle, spinning), close.
toastOptionsToastOptions-Sonner's options. `classNames` are merged with ours (yours come last); `unstyled` stays on.

无障碍

  • Sonner renders a polite aria-live region (`aria-label="Notifications alt+T"`); Alt+T focuses it so a keyboard user can reach the toasts, and hovering or focusing pauses the timers. Each type is its own icon shape and paper (guest check, pink, yellow, blue sticky), so color is never the only signal.
  • Action and cancel are real buttons at least 24 px tall; the close button is named "Close toast". Keep toast text short and never put the only copy of an error in a toast that disappears: pair it with an inline message.
  • Swipe to dismiss is a pointer shortcut only (sonner); every toast also closes with its close button, its action, its timer or `toast.dismiss()`.
  • The toss-in uses the theme's `ll-toss` (`ll-drop` when the stack is not on the right) and collapses to nothing with reduced motion. In `calm` density the slips lose their tilt, tape and pin.
  • Toasts are above dialogs and popovers on the z-scale and stay clickable while a modal is open.

源码

CLI 会复制进你项目的文件。

正在加载源码