v2.1.8
/
  • Get Started
  • Components
  • Composables
  • Typography
  • GitHub
  • Layout
  • App
  • Container
  • Error
  • SidebarLayout
  • Element
  • Advice
  • Alert
  • Avatar
  • AvatarGroup
  • Badge
  • Banner
  • Button
  • Calendar
  • Card
  • Chip
  • Collapsible
  • Countdown
  • FieldGroup
  • Kbd
  • Progress
  • Separator
  • Skeleton
  • Form
  • Checkbox
  • CheckboxGroup
  • ColorPicker
  • FileUpload
  • Form
  • FormField
  • Input
  • InputDate
  • InputMenu
  • InputNumber
  • InputTags
  • InputTime
  • PinInput
  • RadioGroup
  • Range
  • Select
  • SelectMenu
  • Switch
  • Textarea
  • Data
  • Accordion
  • DescriptionList
  • Empty
  • Table
  • TableWrapper
  • Timeline
  • User
  • Navigation
  • Breadcrumb
  • CommandPalette
  • Link
  • NavigationMenu
  • Pagination
  • Stepper
  • Tabs
  • Overlay
  • ContextMenu
  • DropdownMenu
  • Modal
  • Popover
  • Slideover
  • Toast
  • Tooltip
  • Page
  • PageCard
  • PageColumns
  • PageGrid
  • PageLinks
  • PageList
  • Dashboard
  • DashboardGroup
  • DashboardSearch
  • DashboardSearchButton
  • AI Chat
  • soonChatMessage
  • soonChatMessages
  • soonChatPalette
  • soonChatPrompt
  • soonChatPromptSubmit
  • Content
  • ContentSearch
  • ContentSearchButton
  • ContentSurround
  • ContentToc
  • Color Mode
  • ColorModeAvatar
  • ColorModeButton
  • ColorModeImage
  • ColorModeSelect
  • ColorModeSwitch
  • i18n
  • LocaleSelect
  • b24icons
  • b24jssdk
Use our Nuxt starter
v2.1.8
  • Docs
  • Components
  • Composables
  • Typography

Toast

A short message to offer information or feedback to the user.
GitHub
Demo
Nuxt UI
ToastToast

Usage

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

{
  "wait": "Loading client-side content..."
}
Make sure to wrap your app with the App component which uses our Toaster component which uses the ToastProvider component from Reka UI.
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.

{
  "wait": "Loading client-side content..."
}

Description

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

{
  "wait": "Loading client-side content..."
}

Icon

Pass an icon field to the toast.add method to display an Icon.

{
  "wait": "Loading client-side content..."
}

Avatar

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

{
  "wait": "Loading client-side content..."
}

Color

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

{
  "wait": "Loading client-side content..."
}

Close

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

{
  "wait": "Loading client-side content..."
}

Close Icon

Pass a closeIcon field to customize the close button Icon.

{
  "wait": "Loading client-side content..."
}

Actions

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

{
  "wait": "Loading client-side content..."
}

Progress

Pass a progress field to customize or hide the Progress bar (with false value).

The Progress bar inherits the Toast color by default, but you can override it using the progress.color field.
{
  "wait": "Loading client-side content..."
}

Orientation

Pass an orientation field to the toast.add method to change the orientation of the Toast.

{
  "wait": "Loading client-side content..."
}

Examples

Bitrix24 UI provides an App component that wraps your app to provide global configurations.

Change global position

Change the toaster.position prop on the App component to change the position of the toasts.

app.vue
<script setup lang="ts">
const toaster = { position: 'bottom-right' }
</script>

<template>
  <B24App :toaster="toaster">
    <NuxtPage />
  </B24App>
</template>
In this example, we use the AppConfig to configure the position prop of the Toaster component globally.

Change global duration

Change the toaster.duration prop on the App component to change the duration of the toasts.

app.vue
<script setup lang="ts">
const toaster = { duration: 5000 }
</script>

<template>
  <B24App :toaster="toaster">
    <NuxtPage />
  </B24App>
</template>
In this example, we use the AppConfig to configure the duration prop of the Toaster component globally.

Change global max Soon

Change the toaster.max prop on the App component to change the max number of toasts displayed at once.

app.vue
<script setup lang="ts">
const toaster = { max: 3 }
</script>

<template>
  <B24App :toaster="toaster">
    <NuxtPage />
  </B24App>
</template>
In this example, we use the AppConfig to configure the max prop of the Toaster component globally.

Stacked toasts

Set the toaster.expand prop to false on the App component to display stacked toasts (inspired by Sonner).

app.vue
<script setup lang="ts">
const toaster = { expand: true }
</script>

<template>
  <B24App :toaster="toaster">
    <NuxtPage />
  </B24App>
</template>
You can hover over the toasts to expand them. This will also pause the timer of the toasts.
{
  "wait": "Loading client-side content..."
}
In this example, we use the AppConfig to configure the expand prop of the Toaster component globally.

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; }>
iconIconComponent
avatar AvatarProps
  • as?: any

    The element or component this component should render as. Defaults to 'span'.

  • src?: string
  • alt?: string
  • icon?: IconComponent

    Display an icon on the left side.

  • text?: string
  • size?: "xl" | "md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "2xl" | "3xl"

    Defaults to 'md'.

  • chip?: boolean | ChipProps
  • class?: any
  • style?: any
  • b24ui?: { root?: ClassNameValue; image?: ClassNameValue; fallback?: ClassNameValue; icon?: ClassNameValue; }
  • loading?: "lazy" | "eager"
  • referrerpolicy?: HTMLAttributeReferrerPolicy
  • crossorigin?: "" | "anonymous" | "use-credentials"
  • decoding?: "async" | "auto" | "sync"
  • height?: Numberish
  • sizes?: string
  • srcset?: string
  • usemap?: string
  • width?: Numberish
color'air-secondary-no-accent'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary"
orientation'vertical' "vertical" | "horizontal"

The orientation between the content and the actions

closetrueboolean | Partial<ButtonProps>

Display a close button to dismiss the toast. { size: 'sm', color: 'air-tertiary' }

closeIconicons.closeIconComponent

The icon displayed in the close button.

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: 'sm' }
  • label?: string
  • color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "link"

    Defaults to 'air-secondary-no-accent'.

  • "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "activeColor?: air-secondary" | "link"
  • depth?: "light" | "normal" | "dark"

    Defaults to 'normal'.

  • activeDepth?: "light" | "normal" | "dark"
  • size?: "xl" | "md" | "xs" | "sm" | "lg" | "xss"

    Defaults to 'md'.

  • rounded?: boolean

    Rounds the corners of the button Defaults to false.

  • block?: boolean

    Render the button full width Defaults to false.

  • loadingAuto?: boolean

    Set loading state automatically based on the @click promise state Defaults to false.

  • normalCase?: boolean

    Disable uppercase label Defaults to true.

  • useWait?: boolean

    Shows LoaderWaitIcon in loading mode Defaults to false.

  • useClock?: boolean

    Shows LoaderClockIcon icon in loading mode Defaults to false.

  • useDropdown?: boolean

    Shows icons.ChevronDownSIcon on the right side Defaults to false.

  • class?: any
  • b24ui?: { base?: ClassNameValue; baseLoading?: ClassNameValue; baseLoadingWaitIcon?: ClassNameValue; baseLoadingClockIcon?: ClassNameValue; baseLoadingSpinnerIcon?: ClassNameValue; baseLine?: ClassNameValue; label?: ClassNameValue; labelInner?: ClassNameValue; leadingIcon?: ClassNameValue; leadingAvatar?: ClassNameValue; leadingAvatarSize?: ClassNameValue; trailingIcon?: ClassNameValue; safeList?: ClassNameValue; }
  • icon?: IconComponent

    Display an icon on the left side.

  • avatar?: AvatarProps

    Display an avatar on the left side.

  • loading?: boolean

    When true, the loading icon will be displayed.

  • type?: "reset" | "submit" | "button"

    The type of the button when not a link. Defaults to 'button'.

  • as?: any

    The element or component this component should render as when not a link. Defaults to 'button'.

  • to?: string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric

    Route Location the link should navigate to when clicked on.

  • autofocus?: Booleanish
  • disabled?: boolean
  • name?: string
  • download?: any
  • hreflang?: string
  • media?: string
  • ping?: string
  • target?: (string & {}) | "_blank" | "_parent" | "_self" | "_top" | null

    Where to display the linked URL, as the name for a browsing context.

  • referrerpolicy?: HTMLAttributeReferrerPolicy
  • active?: boolean

    Force the link to be active independent of the current route.

  • isAction?: boolean

    When true, uses special underlined styling.

  • trailingSlash?: "append" | "remove"

    An option to either add or remove trailing slashes in the href for this specific link. Overrides the global trailingSlash option if provided.

progresstrueboolean | Pick<ProgressProps, "color" | "b24ui">

Display a progress bar showing the toast's remaining duration. { size: 'sm' }

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.

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.

b24ui { root?: ClassNameValue; wrapper?: ClassNameValue; title?: ClassNameValue; description?: ClassNameValue; icon?: ClassNameValue; avatar?: ClassNameValue; avatarSize?: ClassNameValue; actions?: ClassNameValue; progress?: ClassNameValue; close?: ClassNameValue; }

Slots

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

Emits

Event Type
pause[]
escapeKeyDown[event: KeyboardEvent]
resume[]
swipeStart[event: SwipeEvent]
swipeMove[event: SwipeEvent]
swipeCancel[event: SwipeEvent]
swipeEnd[event: SwipeEvent]
update:open[value: boolean]

Expose

When accessing the component via a template ref, you can use the following:

NameType
heightRef<number>

Theme

app.config.ts
export default defineAppConfig({
  b24ui: {
    toast: {
      slots: {
        root: 'dark relative group overflow-hidden rounded-[26px] py-3.5 ps-6 pe-4 flex items-center gap-2.5 focus-visible:outline-(length:--ui-design-outline-stroke-weight) focus-visible:outline-offset-2 focus-visible:outline-(--ui-color-design-outline-content-divider) font-[family-name:var(--ui-font-family-primary)] bg-(--ui-color-bg-content-primary)/80 text-(--ui-color-design-plain-na-focused-content) text-(length:--ui-font-size-sm) font-(--ui-font-weight-normal)',
        wrapper: 'w-0 flex-1 flex flex-col',
        title: 'font-(--ui-font-weight-medium)',
        description: '',
        icon: 'shrink-0 size-6 text-(--b24ui-border-color)',
        avatar: 'shrink-0',
        avatarSize: 'xl',
        actions: 'flex gap-1.5 shrink-0',
        progress: 'absolute inset-x-0 bottom-0',
        close: 'p-0'
      },
      variants: {
        color: {
          'air-primary': {
            root: 'style-filled'
          },
          'air-primary-success': {
            root: 'style-filled-success'
          },
          'air-primary-alert': {
            root: 'style-filled-alert'
          },
          'air-primary-copilot': {
            root: 'style-filled-copilot'
          },
          'air-primary-warning': {
            root: 'style-filled-warning'
          },
          'air-secondary': {
            root: 'style-filled-inverted'
          },
          default: {
            root: 'old-style-default'
          },
          danger: {
            root: 'old-style-danger'
          },
          success: {
            root: 'old-style-success'
          },
          warning: {
            root: 'old-style-warning'
          },
          primary: {
            root: 'old-style-primary'
          },
          secondary: {
            root: 'old-style-secondary'
          },
          collab: {
            root: 'old-style-collab'
          },
          ai: {
            root: 'old-style-ai'
          }
        },
        orientation: {
          horizontal: {
            root: 'items-center',
            actions: 'items-center'
          },
          vertical: {
            root: 'items-center',
            actions: 'items-start mt-1'
          }
        },
        title: {
          true: {
            description: 'mt-1'
          }
        }
      },
      defaultVariants: {
        color: 'air-secondary'
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from '@bitrix24/b24ui-nuxt/vite'

export default defineConfig({
  plugins: [
    vue(),
    bitrix24UIPluginVite({
      b24ui: {
        toast: {
          slots: {
            root: 'dark relative group overflow-hidden rounded-[26px] py-3.5 ps-6 pe-4 flex items-center gap-2.5 focus-visible:outline-(length:--ui-design-outline-stroke-weight) focus-visible:outline-offset-2 focus-visible:outline-(--ui-color-design-outline-content-divider) font-[family-name:var(--ui-font-family-primary)] bg-(--ui-color-bg-content-primary)/80 text-(--ui-color-design-plain-na-focused-content) text-(length:--ui-font-size-sm) font-(--ui-font-weight-normal)',
            wrapper: 'w-0 flex-1 flex flex-col',
            title: 'font-(--ui-font-weight-medium)',
            description: '',
            icon: 'shrink-0 size-6 text-(--b24ui-border-color)',
            avatar: 'shrink-0',
            avatarSize: 'xl',
            actions: 'flex gap-1.5 shrink-0',
            progress: 'absolute inset-x-0 bottom-0',
            close: 'p-0'
          },
          variants: {
            color: {
              'air-primary': {
                root: 'style-filled'
              },
              'air-primary-success': {
                root: 'style-filled-success'
              },
              'air-primary-alert': {
                root: 'style-filled-alert'
              },
              'air-primary-copilot': {
                root: 'style-filled-copilot'
              },
              'air-primary-warning': {
                root: 'style-filled-warning'
              },
              'air-secondary': {
                root: 'style-filled-inverted'
              },
              default: {
                root: 'old-style-default'
              },
              danger: {
                root: 'old-style-danger'
              },
              success: {
                root: 'old-style-success'
              },
              warning: {
                root: 'old-style-warning'
              },
              primary: {
                root: 'old-style-primary'
              },
              secondary: {
                root: 'old-style-secondary'
              },
              collab: {
                root: 'old-style-collab'
              },
              ai: {
                root: 'old-style-ai'
              }
            },
            orientation: {
              horizontal: {
                root: 'items-center',
                actions: 'items-center'
              },
              vertical: {
                root: 'items-center',
                actions: 'items-start mt-1'
              }
            },
            title: {
              true: {
                description: 'mt-1'
              }
            }
          },
          defaultVariants: {
            color: 'air-secondary'
          }
        }
      }
    })
  ]
})

Slideover

A dialog that slides in from any side of the screen.

Tooltip

A small window that shows details when you move your mouse over an item.

On this page

  • Usage
    • Title
    • Description
    • Icon
    • Avatar
    • Color
    • Close
    • Close Icon
    • Actions
    • Progress
    • Orientation
  • Examples
    • Change global position
    • Change global duration
    • Change global max
    • Stacked toasts
  • API
    • Props
    • Slots
    • Emits
    • Expose
  • Theme
Releases
Published under MIT License.

Copyright © 2024-present Bitrix24