Skip to content

Toasts

Toast component provides lightweight notifications displayed in the corner of the page. It supports a functional API (toast.success(), toast.error(), etc.) without requiring template declarations.

Note

Before using Toasts, you must place <TToastContainer /> in your app entry (e.g., App.vue). This component uses <Teleport to="body"> and accepts placement and teleportTo props.

Functional API

Import the toast object and call methods directly — no template needed.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'

toast.success('Operation completed!')
toast.error('An error occurred.')
toast.warning('Low disk space.')
toast.info('New update available.')
</script>

<template>
  <button class="btn btn-success" @click="toast.success('Success')">Success</button>
  <button class="btn btn-danger" @click="toast.error('Error')">Error</button>
  <button class="btn btn-warning" @click="toast.warning('Warning')">Warning</button>
  <button class="btn btn-info" @click="toast.info('Info')">Info</button>
</template>

Custom Toast

Use toast.show() to customize title, color, icon, and auto-close duration.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'

toast.show('This is a custom notification', {
  title: 'Notification Title',
  color: 'primary',
  duration: 3000, // auto-close after 3 seconds
})
</script>

<template>
  <button class="btn btn-primary" @click="toast.show('Message', { title: 'Title', duration: 3000 })">
    Show Custom Toast
  </button>
</template>

Persistent Toast

Set duration: 0 to keep the toast visible until the user manually closes it.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'

toast.show('This toast will not auto-dismiss', {
  title: 'Persistent',
  duration: 0, // never auto-close
})
</script>

Toast with Icon

Pass an icon component from @tabler/icons-vue via the icon option.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'
import { IconCheck } from '@tabler/icons-vue'

toast.show('Operation completed', {
  title: 'Result',
  color: 'success',
  icon: IconCheck,
})
</script>

Clear All Toasts

Call toast.clear() to immediately remove all active toasts.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'

// Show multiple toasts
toast.success('Toast 1')
toast.info('Toast 2')
toast.warning('Toast 3')

// Clear all at once
toast.clear()
</script>

Bare Style

Toasts without a title or avatar automatically render in "bare" style: no toast-header, close button floating in the top-right corner of the body.

vue
<button class="btn btn-outline-dark" @click="toast.show('A simple toast without header bar.')">
  Show Bare Toast
</button>

Important Style

Enable the important option to render toasts with a solid color background and white text, matching the Alert component's "Important" style. Ideal for critical system notifications.

Show Code
vue

<script setup lang="ts">
import {toast} from '@gulcc/tabler-vue'

// Important info
toast.show('Scheduled maintenance tonight at 02:00, expected to last 2 hours.', {
  title: 'Maintenance Notice',
  color: 'info',
  duration: 0,
  important: true,
  icon: IconInfoCircle,
})

// Important error
toast.show('Database connection failed. Some features are unavailable!', {
  title: 'Critical Error',
  color: 'danger',
  duration: 0,
  important: true,
  icon: IconAlertCircle,
})

// Important success (using shortcut method)
toast.success('System upgrade completed. All services are back to normal.', {
  important: true,
  duration: 0,
})
</script>

Hover Pause

When the mouse enters a toast, the auto-close timer pauses; when the mouse leaves, the timer resumes. This gives users enough time to read the content.

vue
<button class="btn btn-primary" @click="toast.success('Hover to pause the timer.', { duration: 3000 })">
  Show Test Toast (3s)
</button>

Placement

Use setToastPlacement() to set the global default position, or pass placement in toast.show() options to override individual toasts.

Show Code
vue
<script setup lang="ts">
import { toast, setToastPlacement } from '@gulcc/tabler-vue'

// Global setting
setToastPlacement('bottom-right')

// Per-toast override
toast.info('This toast appears at top-left', { placement: 'top-left' })
toast.info('This toast appears at bottom-right', { placement: 'bottom-right' })
</script>

Chat-style Toasts

Use avatar, sender, and timestamp options to create chat-message style toasts. When avatar is set, the toast header automatically switches to an avatar + sender + timestamp layout.

Show Code
vue
<script setup lang="ts">
import { toast } from '@gulcc/tabler-vue'

// Simple chat — with avatar, sender, timestamp
toast.show('Hello, world! This is a toast message.', {
  avatar: '/public/avatar.png',
  sender: 'Mallory Hulme',
  timestamp: '11 mins ago',
  duration: 0,
})

// Cookie notice — using bodyHtml to render action buttons
toast.show('', {
  avatar: '/public/avatar.png',
  sender: 'Mallory Hulme',
  timestamp: '11 mins ago',
  duration: 0,
  bodyHtml: 'Our site uses cookies. By continuing to use our site, you agree to our Cookie Policy.<div class="mt-2 pt-2 border-top"><a href="#" class="btn btn-primary btn-sm">I understand</a></div>',
})
</script>

API

toast Object Methods

MethodParametersReturnsDescription
toast.show()(message: string, options?: ToastOptions)stringShow a custom toast, returns the toast ID
toast.success()(message: string, options?: ToastOptions)stringShow a success toast (green)
toast.error()(message: string, options?: ToastOptions)stringShow an error toast (red)
toast.warning()(message: string, options?: ToastOptions)stringShow a warning toast (yellow)
toast.info()(message: string, options?: ToastOptions)stringShow an info toast (blue)
toast.remove()(id: string)voidRemove a toast by ID
toast.clear()voidClear all toasts

ToastOptions

PropertyTypeDefaultDescription
titlestringToast title
colorTablerColorSemantic colorColor variant, e.g. 'success', 'danger'
iconComponentIcon component (from @tabler/icons-vue)
durationnumber5000Auto-close delay (ms). 0 disables auto-close
placementToastPlacement'top-right'Toast placement, overrides the global default
closablebooleantrueShow close button
avatarstringAvatar image URL (switches to chat-style header)
senderstringSender name (chat-style header)
timestampstringTimestamp text (chat-style header)
bodyHtmlstringBody HTML content (rendered via v-html)
importantbooleanfalseImportant style (solid background + white text)

TToastContainer Props

PropertyTypeDefaultDescription
placementToastPlacement'top-right'Container placement
teleportTostring'body'Teleport target selector

ToastPlacement Type

ValueDescription
'top-right'Top-right corner (default)
'top-left'Top-left corner
'bottom-right'Bottom-right corner
'bottom-left'Bottom-left corner
'top-center'Centered at top
'bottom-center'Centered at bottom