Components / Core
Snackbar
A single controlled toast (MUI's Snackbar), for when you own the open state. Use useToast() for fire-and-forget messages.
import { Snackbar } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { Button, Snackbar } from "@stylhero/ui";
function SnackbarExample() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Copy link</Button>
<Snackbar open={open} onClose={() => setOpen(false)} message="Link copied" tone="success" />
</>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
message required |
ReactNode |
- | |
onClose required |
() => void |
- | |
open required |
boolean |
- | |
action |
ToastAction |
- | One button, e.g. { label: "Undo", onClick: undo }. Clicking it also dismisses the toast. |
duration |
number |
4000 |
ms; 0 keeps it open |
position |
ToastPosition |
"bottom-center" |
Where it sits on screen. |
tone |
ToastTone |
- |
Types
type ToastAction = { label: ReactNode; onClick: () => void };
type ToastPosition = "bottom-right" | "bottom-center" | "bottom-left" | "top-center";
type ToastTone = "info" | "success" | "danger";
Accessibility
- Announced through a
role="status"live region, without moving focus.
Generated from src/components/Toast.tsx. Something wrong or missing? Open an issue.