Toast
A short notice that closes on its own, such as "Gracias por tu valoración".
toast shows MediCore's Toast with the console's types and Sonner's stack:
three types, a timer that pauses while you read, a close button and a stack
of cards in the corner that fans out on hover.
It ships from @mediquo/ui as a function plus the <mq-toaster> element that
holds the stack, and @mediquo/elements/toast re-exports it, so SDK screens
and the portal share one toast.
Keep it for what is low-risk and done: a toast goes away on its own and is easy to miss. Something the patient must not miss, such as a cancelled appointment or a failed payment, belongs on the screen or in a dialog.
Install
// The function, plus <mq-toaster>, registered on import
import { toast } from "@mediquo/ui/components/toast";// React, only to place the toaster yourself
import { Toaster } from "@mediquo/ui/react/toast";Usage
Call it from anywhere. The first call creates an <mq-toaster>, inside
mq-theme-provider when there is one so it inherits the SDK theme's fonts and
safe-area insets, otherwise in <body>.
toast.success(msg("Gracias por tu valoración"), { closeLabel: msg("Cerrar") });
toast.error(msg("No se ha podido enviar el cuestionario"), {
closeLabel: msg("Cerrar"),
});
toast.info(msg("Sin conexión. Reintentando…"), { duration: 0 });| Option | Default | What it does |
|---|---|---|
duration | 5000 | Milliseconds before it closes on its own. 0 keeps it until closed. |
closeLabel | "Close" | Accessible name of the close button. Pass it translated. |
position | "bottom-left" | Moves the toaster, so every toast in it. |
To choose where the toaster lives, or its position, mount one yourself:
toast always uses the last <mq-toaster> put in the page.
<mq-toaster position="top-right"></mq-toaster>Types
The console's types with MediCore's look: a dark card, white text, and an icon chosen by the type, never by the screen.
| Type | Background | Icon | Announced |
|---|---|---|---|
success | #1B7A3D (MediCore green) | check-circle | politely (role="status") |
error | #B30135 (red.700) | alert-circle | at once (role="alert") |
info | #191731 (grey.900) | info-circle | politely (role="status") |
There is no warning type, on purpose: a warning that matters must not vanish on its own, so it goes in a banner that stays.
Behaviour
Stacked like Sonner, shadcn's toasts:
- A stack of cards. The newest toast sits in front, on the edge it is anchored to. Each one behind it peeks out 14px further and is 5% smaller, as tall as the front one and with its text hidden. Three show; older ones wait out of sight behind and come forward as the front ones go.
- Fanned out on hover or focus. With the mouse over the stack, or focus in it, every toast moves to its own height, 14px apart. Moving away folds them back. On touch screens, which have no hover, a tap on the stack fans it out and a tap anywhere else folds it back. Fanned out, a toast that would not fit on the screen stays behind with the oldest.
- Auto-close after 5 s, the console's default. Every timer pauses while the stack is fanned out, pressed or the page is hidden, and picks up where it left.
- Close button on every toast, and swipe to dismiss: drag a toast
towards the edges it sits on (down or sideways to the left for
bottom-left) 45px, or flick it. It follows the finger and fades as it goes; let go short of that and it eases back. The rest of the stack stays put while it is dragged. A touch that starts on a toast drags it instead of scrolling the page; anywhere else the page scrolls as usual. Toasts never take focus. - Position: bottom left, 24px from the edges, 360px wide. On phones (under 768px) the full width minus 16px a side, 72px from the bottom so it clears the chat launcher.
- On top of everything: the toaster is a popover in the top layer, shown again on every toast so it lands above a dialog opened since.
Animation
Every movement uses one strong ease-out, cubic-bezier(0.23, 1, 0.32, 1):
it starts quickly and settles slowly, with no overshoot.
| Phase | Duration | What moves |
|---|---|---|
| Enter | 500ms | Slides in from the edge, fades in and comes closer (scale 0.9 to 1). |
| Stack | 500ms | The others step back into the stack, or fan out and fold back, heights too. |
| Exit | 300ms | Slides back to the edge, fades out and moves away (scale to 0.9). |
| Back exit | 300ms | A card behind the front one recedes a step further into the stack, fading. |
| Swipe out | 300ms | Carries on in the direction of the swipe, fading and moving away. |
| Snap back | 300ms | A swipe let go too short returns to its place. |
A toast that leaves stays in the page until its exit ends, while the rest
move into place, so nothing jumps. With prefers-reduced-motion: reduce
toasts appear and go at once and the stack changes without moving.
Accessibility
- Each message is a live region:
role="status"(polite) for success and info,role="alert"(assertive) for errors. The close button sits outside it, so it is not read with the message. - The close button is named by
closeLabel,"Close"by default — pass it translated, or a Spanish screen reader reads it in English. - Focus in the stack fans it out and pauses it, so a keyboard user sees every toast and a screen-reader user has time to reach them.
- White text measures 17.4:1 on info, 5.39:1 on success and 7.06:1 on error.
- While a modal dialog is open the page behind it is inert, the toaster included: the toast shows above the dialog but cannot be hovered or closed until the dialog closes, and a screen reader may not announce it. Close the dialog before showing the toast that reports its outcome.
Styling
The --toast-* tokens are exported from @mediquo/ui/tokens (as
components.toast) and defined in tokens.css; the component falls back to
the same values without the stylesheet.
mq-toaster {
--toast-width: 22.5rem;
--toast-radius: 0.5rem;
--toast-shadow: 0px 8px 16px -2px rgb(10 10 34 / 0.08);
--toast-gap: 0.875rem;
--toast-inset: 1.5rem;
--toast-inset-mobile: 1rem;
--toast-inset-bottom-mobile: 4.5rem;
--toast-info-bg: #191731;
--toast-success-bg: #1b7a3d;
--toast-error-bg: #b30135;
--toast-enter-duration: 500ms;
--toast-exit-duration: 300ms;
--toast-easing: cubic-bezier(0.23, 1, 0.32, 1);
}part is exposed for stack, toast and close.
From @mediquo/elements
@mediquo/elements/toast re-exports all of this. It keeps toast.warning,
which now shows an info toast, and registerToastContainer, which does
nothing any more. MqToastContainer from
@mediquo/elements/react/mq-toast-container renders an <mq-toaster>.