Toast

Display a toast component.

Usage

      <script lang="ts" setup>
import { useCountdown } from '@vueuse/core'

const countdownSeconds = 5

const { addToast, updateToast } = useToast()

const open = ref(false)

const { remaining, start } = useCountdown(countdownSeconds, {
  onTick() {
    updateToast('bare-metal-create', {
      description: h('div', {
        class: ' font-bold text-white',
        innerHTML: `${remaining.value} secs`,
      }),
    })
  },
})

function handleClick() {
  open.value = false

  start()

  addToast({
    title: 'Dynamic update example',
    id: 'bare-metal-create',
    description: h('div', {
      class: ' font-bold text-white',
      innerHTML: `${remaining.value} secs`,
    }),
    duration: Infinity,
    progress: false,
    close: false,
  })
}
</script>

<template>
  <div>
    <CButton @click="handleClick">
      Add to calendar
    </CButton>
  </div>
</template>

    

Props

Prop Default Type
asany
title string | VNode<RendererNode, RendererElement, { [key: string]: any; }> | (): VNode<RendererNode, RendererElement, { [key: string]: any; }>
description string | VNode<RendererNode, RendererElement, { [key: string]: any; }> | (): VNode<RendererNode, RendererElement, { [key: string]: any; }>
icon string
closetrueboolean | Partial<IconButtonProps>
actions ButtonProps[]
progresstrueboolean
type "foreground" | "background"
Control the sensitivity of the toast for accessibility purposes.For toasts that are the result of a user action, choose foreground. Toasts generated from background tasks should use background.
defaultOpenboolean
The open state of the dialog when it is initially rendered. Use when you do not need to control its open state.
openboolean
The controlled open state of the dialog. Can be bind as v-model:open.
duration number
Time in milliseconds that toast should remain visible for. Overrides value given to ToastProvider.