Documentation

Toast

A short message that comes and goes: toast() from anywhere, one Toaster per app.

Web + MobileStableRetours

Web et mobile — le même composant pour React et React Native. Stable : son API ne change qu’à une version majeure.

Quand l’utiliser

  • To confirm the result of an action: saved, sent, payment received.
  • For an event the user did not trigger but should know: a new follower, a live auction.
  • With an action (“Retry”, “Undo”) when there is one obvious next step.

Quand ne pas l’utiliser

  • For a message that must stay until the situation changes.À la place : Alert
  • When the user must answer.À la place : Dialog
  • To report a form's errors: show them next to the fields.À la place : Field

Installation

Installer

npm install @krizaka/ui@beta @krizaka/tailwind@beta @krizaka/tokens@beta tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { toast, Toaster } from "@krizaka/ui/toast";

Exemples

Tones

Default, success, warning and error with an action.

Custom

toast.custom: your JSX in the platform's shell.

Props

Mount once, in the root layout. Then call toast(), toast.success/warning/error/info, toast.custom(…).

PropTypeDéfautDescription
closeLabelrequisstring—The accessible name of each toast's close button — passed translated.
labelrequisstring—The accessible name of the notifications region (sonner's containerAriaLabel) — passed translated.
toastOptionsOmit<ToastOptions, "unstyled" | "closeButtonAriaLabel">—Extra options for every toast (duration, a className); the class names are merged with the platform's.

Accessibilité

  • The region is a landmark named by label; toasts are announced politely.
  • Toasts pause while hovered or focused.

Clavier

TouchesAction
F8Moves the focus to the toasts region (sonner's hotkey).
Tab / EnterReach and press a toast's action or close button.

Bonnes pratiques

  • Mount one Toaster in the root layout, with its label and closeLabel translated.
  • A title in a few words, a description only if it adds something.
  • Never put the only way to do something in a toast: it goes away.

Générée depuis le code de @krizaka/ui 2.0.0-beta.6 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page