Synertech Web/ui v0.57.5 Site Storybook

Documentation / Feedback & overlays

Toast

Client@synertech/uiOpen in Storybook

The notification message itself: a title, a text, a default icon per type (success, error, warning, info, neutral), three visual variants (soft by default, solid, outlined), a close button and an action slot. It carries role="alert".

Toast draws one message where it is rendered: duration calls onClose once the delay has passed (the countdown stops under the pointer and the focus), position fixes it to a corner of the screen. It does not stack and does not remove itself: removing it in onClose is up to you. For notifications pushed from anywhere, stacked and announced by one live region, mount a Toaster and call toast().

Examples

Basic usage

title and description (or children); closable={false} removes the cross.

Open in a tab
import { Toast } from "@synertech/ui";

export function Basic() {
  return (
    <Toast
      title="Modifications enregistrées"
      description="Votre profil a été mis à jour."
      type="success"
      closable={false}
    />
  );
}

Types and variants

type picks the colour and the default icon, variant the strength of the background.

Open in a tab
import { Toast } from "@synertech/ui";

export function TypesAndVariants() {
  return (
    <div className="grid gap-3">
      <Toast type="info" title="Nouvelle version disponible" closable={false} />
      <Toast type="success" variant="solid" title="Paiement reçu" closable={false} />
      <Toast type="warning" variant="outlined" title="Stockage à 90 %" closable={false} />
      <Toast
        type="error"
        variant="solid"
        title="Échec de l’envoi"
        description="Vérifiez votre connexion."
        closable={false}
      />
    </div>
  );
}

Action and custom icon

action holds a button (Undo, Retry…); icon replaces the type’s icon.

Open in a tab
import { Button, Toast } from "@synertech/ui";

const TrashIcon = () => (
  <svg
    className="h-5 w-5"
    fill="none"
    viewBox="0 0 24 24"
    stroke="currentColor"
    strokeWidth={2}
    aria-hidden="true"
  >
    <path strokeLinecap="round" strokeLinejoin="round" d="M6 7h12M9 7V4h6v3m-8 0 1 13h8l1-13" />
  </svg>
);

export function WithAction() {
  return (
    <Toast
      title="Fichier supprimé"
      description="rapport-mars.pdf a été placé dans la corbeille."
      icon={<TrashIcon />}
      onClose={() => console.log("Fermé")}
      action={
        <Button size="sm" onClick={() => console.log("Restauré")}>
          Annuler
        </Button>
      }
    />
  );
}

Auto-dismiss

duration calls onClose after 4 seconds; the cross closes it sooner.

Open in a tab
import { useState } from "react";
import { Button, Toast } from "@synertech/ui";

export function AutoDismiss() {
  const [visible, setVisible] = useState(false);

  return (
    <div className="space-y-3">
      <Button onClick={() => setVisible(true)}>Copier le lien</Button>
      {visible && (
        <Toast
          type="success"
          title="Lien copié dans le presse-papiers"
          duration={4000}
          onClose={() => setVisible(false)}
        />
      )}
    </div>
  );
}

API reference

Components

Toast

ComponentClient
import { Toast } from "@synertech/ui";

Props — ToastProps

PropTypeDefaultDescription
action ReactNode —
children ReactNode —
closable boolean true
closeLabel string —

Accessible name of the close button. Defaults to the toastClose label.

description ReactNode —
duration number —

Milliseconds after which onClose is called. The countdown stops while the pointer is over the toast or the focus is in it, and starts over when they leave: a message must not vanish from under whoever is reading it. Left out or 0, the toast stays until it is closed. The toast does not remove itself — onClose is what does.

icon ReactNode —
onClose () => void —
position ToastPosition —

Fixes the toast to that corner of the viewport, above dialogs and menus. Left out, the toast stays where it is rendered. One toast per corner: several with the same position are drawn on top of one another, and stacking them is a container of the application's own, around toasts left unpositioned.

title ReactNode —
type ToastType "default"
variant ToastVariant "soft"

+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).

Types

type ToastPosition = | "top-left"
  | "top-center"
  | "top-right"
  | "bottom-left"
  | "bottom-center"
  | "bottom-right"
type ToastType = "success" | "error" | "warning" | "info" | "default"
type ToastVariant = "solid" | "outlined" | "soft"