Toast
Show a short-lived status message in the viewport.
Toast
Usage
import { Button } from "@bedform/ui/button";
import { Toast } from "@bedform/ui/toast";
import { useState } from "react";
export function SaveWorld() {
const [saved, setSaved] = useState(false);
return (
<>
<Button type="button" onClick={() => setSaved(true)}>
Save
</Button>
<Toast
open={saved}
onOpenChange={(event) => setSaved(event.detail)}
aria-label="World saved"
>
Saved
</Toast>
</>
);
}Open and close
Toast is closed by default. Use defaultOpen for an initial open state, or open to control it. A Toast closes itself when its duration ends, so pass onOpenChange with open and copy event.detail back into your state; otherwise the next open={true} does not reopen it.
The ref points to the Toast element, which is a Popover, so showPopover() and hidePopover() also open and close it.
Duration and position
duration defaults to 3000 ms. Set it to 0 to keep the Toast open until it is closed. Hovering the Toast or moving focus inside it pauses the remaining time. The default position is bottom-center; use top-start, top-center, top-end, bottom-start, or bottom-end for another viewport corner or edge.
<Toast defaultOpen duration={5000} position="top-end" aria-label="Settings saved">
Saved
</Toast>Color
Toast uses the same background variants as Tag: neutral, secondary, primary, informative, notice, warning, and realms-informative. It also accepts className and --ore-toast-* variables.
Events
oreui:openchange fires when the Popover state changes, whether the application or the timer changed it. onOpenChange receives it, and its detail is the new boolean state.
API
Toast renders a div, accepts every div attribute, and forwards its ref to the div.
| Prop | Type | Default |
|---|---|---|
defaultOpen | boolean | false |
duration | number | 3000 |
onOpenChange | (event: CustomEvent<boolean>) => void | — |
open | boolean | — |
position | "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end" | "bottom-center" |
variant | "neutral" | "secondary" | "primary" | "informative" | "notice" | "warning" | "realms-informative" | "neutral" |
The Toast has no public child classes. Use className for layout and --ore-toast-* variables for component details.
CSS variables
| Variable | Purpose |
|---|---|
--ore-toast-unit | Base size unit |
--ore-toast-inset | Distance from the viewport edge |
--ore-toast-background | Toast background color |
--ore-toast-foreground | Toast text color |
--ore-toast-border | Toast border color |
--ore-toast-shadow | Toast shadow color |
Accessibility
Toast uses role="status", aria-live="polite", and aria-atomic="true" so short status messages do not interrupt the current task. Always provide an accessible name with aria-label or aria-labelledby. Keep the message concise and do not use Toast for actions that require a user decision.