Skip to content

Toast

Sonner-style toast notifications with countdown bar, stacking, and optional icons.

Demo

Variants

Persistent (no auto-hide)

Installation

vue
<script setup>
import { GTToastContainer, useToast } from '@grundtone/vue';
</script>

In Nuxt, both are auto-imported.

Usage

Setup

Add GTToastContainer once in your app layout:

vue
<template>
  <div>
    <RouterView />
    <GTToastContainer position="bottom-center" />
  </div>
</template>

Show toasts

vue
<script setup>
import { useToast } from '@grundtone/vue';

const toast = useToast();

toast.success('Din ansøgning er afsendt');
toast.error('Der opstod en fejl');
toast.warning('Advarsel', { description: 'Detaljer...' });
toast.info('Ny besked');
toast('Standard besked');
</script>

With icon

vue
toast.success('Gemt', { icon: 'check' });
toast.error('Fejl', { icon: 'close' });

Persistent (no auto-hide)

vue
toast.error('Kritisk fejl', { duration: 0 });

Dismiss programmatically

vue
const id = toast.info('Processing...');
// Later:
toast.dismiss(id);
toast.dismissAll();

useToast API

MethodDescription
toast(message, options?)Default toast
toast.success(message, options?)Success variant
toast.warning(message, options?)Warning variant
toast.error(message, options?)Error variant
toast.info(message, options?)Info variant
toast.dismiss(id)Remove specific toast
toast.dismissAll()Remove all toasts

ToastOptions

OptionTypeDefaultDescription
descriptionstringSecondary text
iconstringIcon name from registry
durationnumber5000ms (0 = persistent)
dismissiblebooleantrueShow close button

GTToastContainer Props

PropTypeDefaultDescription
positionToastPosition'bottom-center'Screen position
visibleToastsnumber3Max visible before stacking
richColorsbooleanfalseFilled variant backgrounds
expandbooleanfalseAlways expanded (no stacking)

Features

  • Stacking: 3D scale effect, expand on hover
  • Countdown bar: Visual timer, pauses on hover/focus
  • Rich colors: Optional filled backgrounds per variant
  • WCAG: Correct aria-live per variant, timing adjustable

See Toast (Design System) for full CSS reference.