Toast
Stacked notifications that dismiss on a timer.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase toast
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase toast
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::toast::{
ToastAction,
ToastClose,
ToastContent,
ToastDescription,
ToastPortal,
ToastProvider,
ToastRoot,
ToastTitle,
ToastViewport,
};
ToastRoot::new()
.child(
ToastAction::new(),
)
.child(
ToastClose::new(),
)
.child(
ToastContent::new(),
)
.child(
ToastDescription::new(),
)
.child(
ToastTitle::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#ToastRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::toast::ToastRoot;
ToastRoot::new()
.swipe_direction(/* directions: impl IntoIterator<Item = ToastSwipeDirection> */)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastRoot with its default configuration. |
.child | pub fn child(mut self, child: impl Into<ToastRootChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.swipe_direction | pub fn swipe_direction(mut self, directions: impl IntoIterator<Item = ToastSwipeDirection>,) -> Self
Permitted swipe-to-dismiss directions; default |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastPortal
Hosts overlay content outside the normal child layout.
use base_gpui::toast::ToastPortal;
ToastPortal::new();
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastPortal with its default configuration. |
.child | pub fn child(mut self, child: impl Into<ToastPortalChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. ToastPortal also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastAction
Public renderable part of the Toast Action component.
use base_gpui::toast::ToastAction;
ToastAction::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastAction with its default configuration. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastActionStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastAction also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastClose
Interactive control that closes the component.
use base_gpui::toast::ToastClose;
ToastClose::new()
.aria_label("label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastClose with its default configuration. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible label for the close button; defaults to "Close". Callers rendering a visible text child that duplicates this label should pass it as |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastCloseStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastClose also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastContent
Contains the component's user-provided content.
use base_gpui::toast::ToastContent;
ToastContent::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastContent with its default configuration. |
.child | pub fn child(mut self, child: impl Into<ToastRootChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastContentStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastContent also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastDescription
Provides supporting descriptive content.
use base_gpui::toast::ToastDescription;
ToastDescription::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastDescription with its default configuration. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastDescriptionStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastDescription also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastProvider
Public renderable part of the Toast Provider component.
use base_gpui::toast::ToastProvider;
ToastProvider::new()
.id("example-id")
.timeout(/* timeout: Duration */)
.limit(0)
.manager(/* manager: ToastManager<P> */);
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastProvider with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<ToastProviderChild<P>>) -> Self
Adds one typed child to this part. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.timeout | pub fn timeout(mut self, timeout: Duration) -> Self
Default auto-dismiss timeout for toasts without their own (5000 ms). |
.limit | pub fn limit(mut self, limit: usize) -> Self
Maximum non-limited toasts (older ones are flagged |
.manager | pub fn manager(mut self, manager: ToastManager<P>) -> Self
Binds an imperative manager created with ToastProvider also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastTitle
Provides the component's visible title.
use base_gpui::toast::ToastTitle;
ToastTitle::new()
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastTitle with its default configuration. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastTitleStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastTitle also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#ToastViewport
Defines the viewport used to lay out or constrain overlay content.
use base_gpui::toast::ToastViewport;
ToastViewport::new()
.id("example-id")
.aria_label("label")
.content_builder(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a ToastViewport with its default configuration. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.aria_label | pub fn aria_label(mut self, label: impl Into<SharedString>) -> Self
Accessible label for the notifications region; defaults to "Notifications" (Base UI viewport |
.content_builder | pub fn content_builder(mut self, builder: impl Fn(&ToastFacts<P>) -> ToastRoot<P> + 'static,) -> Self
The typed per-toast content builder: receives typed toast facts and returns the |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(ToastViewportStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. ToastViewport also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.