Toast & Notification Queue
Use the global useToast() composable or standalone KToast component to display notifications, feedback messages, and multi-position toast stacks.
Global Toast Composable (useToast)
TypeScript
const toast = useToast()
toast.success('Changes saved successfully!')
toast.info('New message arrived in inbox')
toast.warning('Your storage is at 85% capacity')
toast.error('Failed to sync changes with server')
toast.primary('System upgrade is scheduled for midnight')
Placement & Multi-Position Stacks
Trigger notifications in any screen anchor:
TypeScript
const toast = useToast()
toast.info('Top Left Alert', { position: 'top-left' })
toast.info('Top Center Alert', { position: 'top-center' })
toast.info('Top Right Alert', { position: 'top-right' })
toast.info('Bottom Left Alert', { position: 'bottom-left' })
toast.info('Bottom Center Alert', { position: 'bottom-center' })
toast.info('Bottom Right Alert', { position: 'bottom-right' })
Queue Stacking & Smooth Animations
TypeScript
const toast = useToast()
// Spawn multiple toasts to observe stack layout and smooth reordering
toast.info('First queued notification', { duration: 5000 })
toast.warning('Second queued notification', { duration: 6000 })
toast.success('Third queued notification', { duration: 7000 })
// Or clear all active toasts at once
toast.clear()
Pause on Hover
TypeScript
const toast = useToast()
// Hovering the toast automatically freezes the countdown timer
toast.info('Hover over me to pause the countdown timer!', {
duration: 4000,
pauseOnHover: true
})
Standalone Component Usage (v-model)
TypeScript
KButton(@click="showBasic = true") Show Basic Toast KToast(v-model="showBasic" text="This is a basic standalone toast message") KButton(@click="showTeleport = true") Show Teleported Standalone KToast(v-model="showTeleport" text="I am teleported to body directly!" :teleport="true" type="success")
Rich HTML & Actionable Content (Slots)
Standalone KToast supports custom HTML, badges, links, and action buttons via the default slot:
TypeScript
KButton(@click="showRich = true" type="primary") Show Rich HTML Toast KToast(v-model="showRich" :teleport="true" type="primary" :timeout="8000" title="Deployment Complete") .rich-toast-content .rich-toast-row span.rich-badge PROD span Build #428 deployed to Frankfurt region. .rich-toast-actions NuxtLink.rich-link(to="/components/button") View Release Notes → button.rich-action-btn(@click="onUndoClick") Rollback
useToast() Composable Methods
Programmatic methods provided by const toast = useToast().
| Method | Arguments | Returns | Description |
|---|---|---|---|
| success(message, options?) | message: string, options?: Partial<KToastOptions> | string | number | Display a success notification. |
| error(message, options?) | message: string, options?: Partial<KToastOptions> | string | number | Display an error notification. |
| warning(message, options?) | message: string, options?: Partial<KToastOptions> | string | number | Display a warning notification. |
| info(message, options?) | message: string, options?: Partial<KToastOptions> | string | number | Display an informative notification. |
| primary(message, options?) | message: string, options?: Partial<KToastOptions> | string | number | Display a primary brand notification. |
| show(messageOrOptions, options?) | string | KToastOptions, options?: Partial<KToastOptions> | string | number | Core method to display any toast with full options. |
| dismiss(id) | id: string | number | void | Immediately dismiss a specific toast. |
| clear(position?) | position?: KToastPosition | void | Clear all active toasts or only those at a specific position. |
KToastOptions
Configuration passed to useToast methods.
| Property | Type | Default | Description |
|---|---|---|---|
| text | string | '' | Body text of the notification. |
| title | string | undefined | Optional bold title displayed above the text. |
| type | KToastType | 'info' | Variant: 'primary', 'success', 'warning', 'danger', 'info', 'error', 'default'. |
| duration | number | 3000 | Auto-dismiss timeout in milliseconds (0 for persistent). |
| position | KToastPosition | 'top-right' | Placement: 'top-right', 'top-left', 'top-center', 'bottom-right', 'bottom-left', 'bottom-center'. |
| pauseOnHover | boolean | true | Freezes the auto-dismiss timer while user hovers the toast. |
| onClose | () => void | undefined | Callback executed when the toast is dismissed. |
Standalone KToast Attributes
Configure the standalone KToast component.
| Name | Type | Default | Description |
|---|---|---|---|
| v-model | boolean | false | Controls visibility of the toast. |
| text | string | '' | The message content to display. |
| title | string | '' | Optional title displayed above the content. |
| timeout | number | 3000 | Auto-hide delay in milliseconds (0 to disable). |
| teleport | boolean | false | Teleport to document body (fixed positioning). |
| type | string | 'info' | Variant: 'primary', 'success', 'warning', 'danger', 'info', 'error', 'default'. |
| pauseOnHover | boolean | true | Freezes countdown while the mouse is hovering the toast. |