ToastProvider
ToastProvider é dono de uma fila de confirmações curtas e não bloqueantes. Escolha-o quando um descendente precisar anunciar um resultado sem propagar estado de notificação por todos os componentes intermediários; use Toast e ToastStack diretamente quando esse estado de apresentação já for seu.
Exemplos
On this page, notifications appear in normal flow inside their own preview so both independent providers remain readable and their controls stay reachable. This positioning is documentation-only: the copied examples and the library default still use a stack fixed to the bottom-right of the viewport.
Enviar uma confirmação
Envolva a parte da aplicação que precisa de notificações e então chame success em um
descendente. O provider fornece ícone, controle de fechar e pilha fixa para cada toast
enfileirado.
Duração por toast
duration define o padrão do provider, enquanto as opções passadas a toast o sobrescrevem para
uma notificação. Passe 0 para uma notificação que permanece até a pessoa dispensá-la.
Quando usar
Use ToastProvider quando vários descendentes precisarem de uma API imperativa compartilhada de notificações.
Prefira outro componente quando:
- Você já controla a lista de notificações visíveis — use diretamente os componentes de baixo nível Toast e ToastStack.
- A mensagem pertence ao conteúdo da página — use Alert.
- Alguém precisa decidir antes de continuar — use Dialog.
Acessibilidade
- ToastProvider announces info/success through a persistent polite region and danger through a persistent assertive region, both additions-only. Composed rows have no individual role. Never use a toast as the only place for important information.
- Cada toast enfileirado recebe um botão de fechar cujo nome acessível vem de
closeLabel, com padrão "Close notification". Forneça uma cópia localizada quando necessário. - O ToastStack do provider fica fixo no canto inferior direito do viewport. Mantenha mensagens breves e não deixe a pilha substituir um status persistente.
Timing and dismissal
React ToastProvider and the Alpine toast store resolve duration when a notification is queued:
per-toast duration overrides explicit provider/store configuration, which overrides the implicit
tone policy. Info and success default to 8000 ms; danger, including error(), defaults to
persistent. 0 always means persistent. Explicit global 8000 also makes danger expire.
Changing configuration affects new notifications only.
Pointer hover and focus inside a row independently pause its remaining time. The countdown resumes
only after both leave; moving between descendants does not restart it. Give action-bearing React
messages an explicit { duration: 0 }; the provider does not inspect their content.
Dismissing a focused row returns focus to its enqueue-time opener if that element is still eligible. Removed, disabled, hidden or inert openers, and openers inside a toast stack, use the same persistent stack instead. This named region (a landmark) remains focusable and visibly outlined even when empty. Unfocused dismissals do not move focus, and deliberate action focus moves are preserved. The region adds no live announcement; polite and assertive regions announce additions only.
Migration: set duration={4000} on React ToastProvider or assign
Alpine.store('lyraToasts').duration = 4000 to restore the previous default delay for all tones.
Per-toast overrides still take precedence. These timing changes apply to React and Alpine; the
imported Blade API below is unchanged.
API e código
Blade: O snapshot de API lançado do Blade v0.10.0 não tem componente para esta entrada do catálogo.
| Nome | Tipo | Obrigatória | Descrição |
|---|---|---|---|
duration | number | — | Explicit delay for new notifications, overriding tone defaults. Omitted: info/success `8000`, danger `0`. Interaction pauses remaining time; `0` persists. |
'aria-label' | string | — | Accessible name of the owned notification region. Use distinct names for coexisting providers. Default: `"Notifications"`. |
closeLabel | string | — | Accessible name passed to every composed Toast close button. Default: `"Close notification"`. |
children | ReactNode | Obrigatória |
useToast
Retained methods read the latest committed provider configuration. After real provider unmount,
notification methods return numeric ids without adding state or timers, and dismiss does nothing.
During SSR, notification methods return numeric ids without adding state or timers.
A fresh provider starts empty. StrictMode replay preserves remaining time and interaction pauses.
The owned region defaults to the accessible name "Notifications". Set aria-label to localize it
or give coexisting providers distinct names, for example <ToastProvider aria-label="Project notifications">.
The two live examples above use different region names so they remain distinguishable on the same page.
Chame useToast somente abaixo de ToastProvider; fora dele, o hook lança um erro. Ele retorna toast,
success, error e info, e cada um enfileira uma mensagem e retorna um id numérico local ao provider.
Chame dismiss(id) para remover uma notificação antes de seu timer expirar. A duration opcional de uma
chamada sobrescreve o padrão do provider para aquele toast, e 0 desativa seu timer de auto-dismiss.
Métodos da API mantidos depois que o provider desmonta são no-ops seguros: retornam um id, mas não colocam
estado na fila nem deixam um timer.
ToastProvider é estado e temporização React; em HTML puro, use os primitives resultantes. A fila, timers de auto-dismiss e o comportamento de fechar ficam com você:
<div class="lyra-toast-stack">
<div class="lyra-toast" role="status">
<span class="lyra-toast__icon lyra-toast__icon--success" aria-hidden="true">✓</span>
<span>Projeto publicado</span>
<button class="lyra-toast__close" type="button" aria-label="Fechar notificação">×</button>
</div>
</div>