shadcn.io is not affiliated with official shadcn/ui
Sonner examples · Standard
Warning Toast Sonner for React
A button that shows a warning toast with the warning icon.
A warning toast flags something that isn't an error yet but needs attention soon. The button calls toast.warning, and Toaster adds its warning icon. Use it for an expiring session, a nearly full quota or unsaved changes.
Preview
Installation
FAQ
How does this demo show a warning?
The button calls toast.warning with "Your session will expire soon". That sets the type to warning. Toaster draws a TriangleAlertIcon with className="size-4" and aria-hidden.
Which options does this call pass?
Only the message. There is no description, duration, action, or dismissible on this call. The notice is that one sentence.
How do I say when the session expires?
Pass description as the second argument, for the line under the title. This demo keeps the timing inside the title string and does not pass description.
How do I show this as an error instead?
Call toast.error with the message. That swaps in Toaster's OctagonXIcon. This file uses toast.warning, so the icon is the triangle.
Related
- Default Toast SonnerA button that shows a plain toast with
- Error Toast SonnerA button that shows an error toast with
- Info Toast SonnerA button that shows an info toast with
- Toast with Cancel Button SonnerA toast with a Cancel button that closes
- Standard with Title AlertA neutral alert with only a title, for a
- Non-Dismissible Toast SonnerA toast that can't be swiped away and