Toasts
Toast stack with pixel type icons and a draining timer bar that pauses on hover or focus; it can be pinned to a viewport corner.
Playground
Change a prop and the component re-renders. Props marked remounts set an initial value, so the component starts over.
<PxToaster max={4} />Installation
pnpm dlx shadcn@latest add @lumesec/px-toasterFirst timeRegister the @lumesec registry once, or install by URL+
Adds @lumesec to your components.json:
pnpm dlx shadcn@latest registry add @lumesec=https://elements.lumesec.ai/r/{name}.jsonOr skip the setup and install by URL:
npx shadcn@latest add https://elements.lumesec.ai/r/px-toaster.jsonUsage
import * as React from "react";
import { PxToaster, type PxToasterHandle } from "@/components/lumesec/px-toaster";
export function Example() {
const toaster = React.useRef<PxToasterHandle>(null);
return (
<>
<button type="button" onClick={() => toaster.current?.show({ title: "Changes saved", type: "success" })}>
Save
</button>
<PxToaster ref={toaster} position="bottom-right" />
</>
);
}Behaviour
Stacked notifications with pixel icons and a draining timer that pauses while you hover. Add position="bottom-right" to pin it to the viewport.
API reference
Props
Also accepts every prop of <div> (React.ComponentProps<"div">), spread onto the root element.
positionType"bottom-right" | "bottom-left" | "top-right"Pins the stack to that viewport corner with position: fixed, up to 360 px wide. Without it the stack stays in the flow.
maxTypenumberDefault4Maximum toasts on screen; showing one more dismisses the oldest.
onShowType(id: number, type: PxToastType) => voidCalled when a toast is added.
onDismissType(id: number) => voidCalled when a toast starts leaving: timer, dismiss button, action button, overflow or dismiss().
Ref
ref receives a PxToasterHandle handle with these methods.
show(toast?: PxToastOptions): numberAdds a toast and returns its id. PxToastOptions is { title?: React.ReactNode; description?: React.ReactNode; type?: "info" | "success" | "warning" | "error"; duration?: number; action?: { label: string; onClick?: () => void } }. type defaults to info and duration to 4500 ms; 0 or less keeps the toast until dismissed. The action button calls onClick and dismisses the toast.
dismiss(id: number): voidStarts the exit of the toast with that id. Unknown or leaving ids are ignored.
Accessibility
- The stack is a
role="region"witharia-label="Notifications"andaria-live="polite". - Each toast has
role="status"; error toasts haverole="alert". - Dismiss buttons are native buttons labelled "Dismiss"; action buttons use the action label.
- Hover or focus inside the stack pauses all timers.
- The type icons and timer bars are drawn on an
aria-hiddencanvas. - Reduced motion: toasts appear and leave without the slide and collapse animations; the timer bars still drain.
Theming
Styled with Tailwind classes on your shadcn theme tokens, so light and dark follow your theme. The accent comes from --lumesec. See Theming.
This component reads --card, --border, --foreground, --muted-foreground, --muted, --lumesec, --lumesec-success, --lumesec-warning and --destructive.
Notes
- Toasts appear only through
show()on the handle;refis the handle, not the DOM element. - Pinning uses
position: fixedon the root, so an ancestor that creates a containing block for fixed-position descendants (for example throughfilterortransform) changes what it is fixed to.
Related
Was this page helpful?