Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Core

ToastProvider

Wrap your app once (e.g. in app/layout.tsx), then call useToast() anywhere below it, or toast() from outside components.

import { ToastProvider } from "@stylhero/ui";

Example

Code
import { Button, Stack, ToastProvider, useToast } from "@stylhero/ui";

function ToastButtons() {
  const toast = useToast();
  return (
    <Stack direction="row" gap={2} wrap>
      <Button onClick={() => toast("Saved")}>Show a toast</Button>
      <Button variant="secondary" onClick={() => toast({ message: "Build deleted", action: { label: "Undo", onClick: () => toast("Restored") } })}>
        With an action
      </Button>
    </Stack>
  );
}

function ToastProviderExample() {
  // put ToastProvider once near the root of your app
  return (
    <ToastProvider position="bottom-center">
      <ToastButtons />
    </ToastProvider>
  );
}

Props

PropTypeDefaultDescription
children required ReactNode -
position ToastPosition "bottom-right"

Types

type ToastPosition = "bottom-right" | "bottom-center" | "bottom-left" | "top-center";

Accessibility

  • Toasts appear in a labelled region and are announced without moving focus. Actions in a toast are reachable with Tab.

Generated from src/components/Toast.tsx. Something wrong or missing? Open an issue.