Skip to content
Klarhimmel UI

Toast

npx shadcn add @klarhimmel/toast @klarhimmel/button

Examples

  • Basic

  • Tones

  • Action

DetailsAbout, usage, props and more

A short message that appears at the bottom, from anywhere in the app, and leaves by itself.

When to use

  • Use for

    Confirming what already happened: saved, copied, removed with Undo.

  • Not for

    Errors or choices that need action. Use a Banner or a Dialog.

  • Pairs with

    Button, a list with Undo.

Preview

Each toast leaves on its own, and stays while you point at it or focus it.

toast.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Button } from '@/components/klarhimmel/ui/button';
import { Toaster, toast } from '@/components/klarhimmel/ui/toast';

export default function Example() {
  return (
    <Theme theme="brand">
      <Toaster />
      <Button onClick={() => toast('Changes saved')}>Save</Button>
      <Button
        variant="secondary"
        onClick={() => toast('Room removed', { action: { label: 'Undo', onClick: () => console.log('restore') } })}
      >
        Remove room
      </Button>
    </Theme>
  );
}

Import

Import

import { Toaster, toast, dismissToast, clearToasts } from '@/components/klarhimmel/ui/toast';
Files
toast.tsx, button.tsx, in components/klarhimmel/ui/. With it: editing, theme, utils. npm: lucide-react, radix-ui.
Render in
Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
Limit
Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.

Props

PropTypeDefaultDescription
labelstring'Notifications'
dismissLabelstring'Dismiss'

Accessibility

KeyDoes
TabMoves to a toast's action and its close button
Enter / SpaceRuns the action or dismisses
EscapeDismisses the toast that has focus

A toast stays while it is hovered or focused. Danger toasts are announced at once; the others politely.

Accessibility