Toast ​
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.
<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
<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
<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
<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
<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
<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
<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
<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
<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. |
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 | (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 | |
avatar | AvatarProps | |
color | "default" | "danger" | "success" | "warning" | "primary" | "secondary" | "collab" | "ai" | |
orientation | "vertical" | "vertical" | "horizontal" |
actions | ButtonProps[] 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"} | |
close | true | boolean | Partial<ButtonProps> Display a close button to dismiss the toast.
`{ size: 'md', color: 'neutral', variant: 'link' }`{lang="ts-type"} |
closeIcon | icons.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. |
b24ui | Partial<{ 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`. | |
duration | number Time in milliseconds that toast should remain visible for. Overrides value
given to `ToastProvider`. | |
defaultOpen | boolean The open state of the dialog when it is initially rendered. Use when you do not need to control its open state. | |
open | boolean 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 |
---|