Skip to content
Page

Toast

Short notification triggered from code with toast().

import { Toaster, toast, dismissToast } from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/ToastExample.tsx
import { Button, Stack, Toaster, toast } from "@pelagornis/page/components";
export default function ToastDemo() {
return (
<Stack direction="row" gap="sizeSmall" wrap>
<Button variant="primary" onClick={() => toast("Settings saved", { variant: "success", duration: 3000 })}>
Show success
</Button>
<Button
variant="outline"
onClick={() =>
toast("Upload failed", {
variant: "error",
action: { label: "Retry", onClick: () => toast("Retrying…") },
})
}
>
Show error
</Button>
<Toaster />
</Stack>
);
}

Toast is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import ToastExample from "../../components/ToastExample";
<ToastExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/ToastExample.astro
---
import ToastExample from "../ToastExample";
---
<ToastExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"toast-example": {
render: component("./src/components/markdoc/ToastExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% toast-example /%}

Values the component accepts for each variant prop.

PropValues
variantdefault success error warning

Parts of the component and the data-refineui role each one renders.

PartRole
roottoast
icontoast-icon
itemtoast-item
scale_layertoast-scale-layer
toastertoaster