Skip to content

Toast ​

A short message to offer information or feedback to the user.

Usage ​

Use the useToast composable to display a toast in your application.

WARNING

Be certain to wrap your app with the App component, which integrates our Toaster component, leveraging the ToastProvider from Reka UI.

TIP

You can check the App component toaster prop to see how to configure the Toaster globally.

Title ​

Pass a title field to the toast.add method to display a title.

vue
<script setup lang="ts">
export interface ExampleProps {
  title?: string
}

const props = withDefaults(defineProps<ExampleProps>(), {
  title: 'Some title'
})

const toast = useToast()

function showToast() {
  toast.add(props)
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Description ​

Pass a description field to the toast.add method to display a description.

Details
vue
<script setup lang="ts">
export interface ExampleProps {
  title?: string
  description?: string
}

const props = withDefaults(defineProps<ExampleProps>(), {
  title: 'Some title',
  description: 'Some description'
})

const toast = useToast()

function showToast() {
  toast.add(props)
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Icon ​

Pass an icon field to the toast.add method to display an @bitrix24/b24icons.

Details
vue
<script setup lang="ts">
import CopilotAiIcon from '@bitrix24/b24icons-vue/main/CopilotAiIcon'

const toast = useToast()

function showToast() {
  toast.add({
    title: 'The calculation of indicators has been completed',
    description: 'Is there anything else you need help with?',
    icon: CopilotAiIcon
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Avatar ​

Pass an avatar field to the toast.add method to display an Avatar.

Details
vue
<script setup lang="ts">
const toast = useToast()

function showToast() {
  toast.add({
    title: 'The calculation of indicators has been completed',
    description: 'Is there anything else you need help with?',
    avatar: {
      src: '/b24ui/avatar/assistant.png'
    }
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Color ​

Pass a color field to the toast.add method to change the color of the Toast.

Details
vue
<script setup lang="ts">
import AlarmIcon from '@bitrix24/b24icons-vue/main/AlarmIcon'
import type { ToastProps } from '@bitrix24/b24ui-nuxt'

const props = defineProps<{
  color: ToastProps['color']
}>()

const toast = useToast()

function showToast() {
  toast.add({
    title: 'The calculation of indicators has been completed',
    description: 'Is there anything else you need help with?',
    icon: AlarmIcon,
    color: props.color
  })
}
</script>

<template>
  <B24Button
    label="Show toast"
    :color="color"
    @click="showToast"
  />
</template>

Close ​

Pass a close field to customize or hide the close button (with false value).

Details
vue
<script setup lang="ts">
import CopilotAiIcon from '@bitrix24/b24icons-vue/main/CopilotAiIcon'

const toast = useToast()

function showToast() {
  toast.add({
    title: 'The calculation of indicators has been completed',
    description: 'Is there anything else you need help with?',
    icon: CopilotAiIcon,
    close: {
      color: 'ai',
      depth: 'dark',
      class: 'rounded-full'
    }
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Close Icon ​

Pass a closeIcon field to customize the close button @bitrix24/b24icons.

Details
vue
<script setup lang="ts">
import CopilotAiIcon from '@bitrix24/b24icons-vue/main/CopilotAiIcon'
import ArrowToTheRightIcon from '@bitrix24/b24icons-vue/actions/ArrowToTheRightIcon'

const toast = useToast()

function showToast() {
  toast.add({
    title: 'The calculation of indicators has been completed',
    description: 'Is there anything else you need help with?',
    icon: CopilotAiIcon,
    closeIcon: ArrowToTheRightIcon
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Actions ​

Pass an actions field to add some Button actions to the Toast.

Details
vue
<script setup lang="ts">
import Refresh9Icon from '@bitrix24/b24icons-vue/crm/Refresh9Icon'

export interface ExampleProps {
  title?: string
  description?: string
}

const props = withDefaults(defineProps<ExampleProps>(), {
  title: 'Some title',
  description: 'Some description'
})

const toast = useToast()

function showToast() {
  toast.add({
    ...props,
    avatar: {
      src: '/b24ui/avatar/employee.png'
    },
    actions: [{
      icon: Refresh9Icon,
      label: 'Retry',
      color: 'primary',
      onClick: (e) => {
        e?.stopPropagation()
      }
    }]
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

Orientation ​

Use the orientation prop to change the orientation of the Toast.

Details
vue
<script setup lang="ts">
import type { ToastProps } from '@bitrix24/b24ui-nuxt'
import Refresh9Icon from '@bitrix24/b24icons-vue/crm/Refresh9Icon'

export interface ExampleProps {
  orientation: ToastProps['orientation']
  title?: string
  description?: string
}

const props = withDefaults(defineProps<ExampleProps>(), {
  orientation: 'horizontal' as const,
  title: 'Some title',
  description: 'Some description'
})

const toast = useToast()

function showToast() {
  toast.add({
    ...props,
    avatar: {
      src: '/b24ui/avatar/employee.png'
    },
    actions: [{
      icon: Refresh9Icon,
      label: 'Retry',
      color: 'primary',
      onClick: (e) => {
        e?.stopPropagation()
      }
    }]
  })
}
</script>

<template>
  <B24Button label="Show toast" color="primary" @click="showToast" />
</template>

API ​

Props ​

Prop Default Type
as'li'any
The element or component this component should render as.
titlestring | VNode<RendererNode, RendererElement, { [key: string]: any; }> | (): VNode<RendererNode, RendererElement, { [key: string]: any; }>
descriptionstring | VNode<RendererNode, RendererElement, { [key: string]: any; }> | (): VNode<RendererNode, RendererElement, { [key: string]: any; }>
icon(props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Data; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed) => void; }, "expose">): any
avatarAvatarProps
color"default" | "danger" | "success" | "warning" | "primary" | "secondary" | "collab" | "ai"
orientation"vertical""vertical" | "horizontal"
actionsButtonProps[]
Display a list of actions: - under the title and description when orientation is `vertical` - next to the close button when orientation is `horizontal` `{ size: 'xs' }`{lang="ts-type"}
closetrueboolean | Partial<ButtonProps>
Display a close button to dismiss the toast. `{ size: 'md', color: 'neutral', variant: 'link' }`{lang="ts-type"}
closeIconicons.close(props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Data; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed) => void; }, "expose">): any
The icon displayed in the close button.
b24uiPartial<{ root: string; wrapper: string; title: string; description: string; icon: string; avatar: string; avatarSize: string; actions: string; progress: string; close: string; }>
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`.
durationnumber
Time in milliseconds that toast should remain visible for. Overrides value given to `ToastProvider`.
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`.

Slots ​

Slot Type
leading{}
title{}
description{}
actions{}
close{ b24ui: any; }

Emits ​

Event Type

Released under the MIT License.