Toast
Provider
To use the toast module, you need to set up the ToastProvider first. Simply place it within the ThemeProvider – its position doesn't matter, and it will function as expected.
<script setup>
import { ThemeProvider, ToastProvider } from '@typlog/ui'
</script>
<template>
<ThemeProvider>
<ToastProvider />
</ThemeProvider>
</template>Isolated applications and SSR
The exported toast function and a provider without a manager prop use a shared default queue. This preserves the convenient setup for a single client-side application.
For server-side rendering or pages containing multiple Vue applications, create one manager for each app or request. Pass it to the provider and use the manager's toast function so messages cannot leak between queues:
<script setup>
import { createToastManager, ToastProvider } from '@typlog/ui'
const toastManager = createToastManager()
const toast = toastManager.toast
</script>
<template>
<ToastProvider :manager="toastManager" />
<button @click="toast.success('Saved')">Save</button>
</template>In an SSR application, create the manager inside the per-request app factory, not at module scope.
Responsive layout
Toast messages use a full-width layout with a var(--space-4) gutter on both sides when the viewport is narrower than 640px by default. The top or bottom position is preserved, while the desktop left, center, or right alignment is replaced by the shared mobile layout. When swipeDirection is omitted, top toasts swipe up and bottom toasts swipe down on narrow viewports; an explicit direction always takes precedence.
Set breakpoint to change the viewport width at which this behavior starts:
<ToastProvider :breakpoint="768" />Position
You can customize the position of toast messages using the position prop on ToastProvider. By default, toasts appear in the bottom-right corner.
Size
You can customize the size of toast messages using one of the three available size options.