---
title: "Banner"
description: "Верхний баннер для важных сообщений пользователю."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/banner"
---
# Banner

> Верхний баннер для важных сообщений пользователю.

## Использование

### Заголовок

Пропс `title` показывает заголовок на Banner.

```vue
<template>
  <B24Banner title="Пробный период подписки закончился. Оформите подписку, чтобы продолжить работу со всеми приложениями." />
</template>
```

### Иконка

Пропс `icon` показывает иконку на Banner.

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

<template>
  <B24Banner :icon="RocketIcon" title="Пробный период подписки закончился. Оформите подписку, чтобы продолжить работу со всеми приложениями." />
</template>
```

### Цвет

Пропс `color` меняет цвет Banner.

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

<template>
  <B24Banner color="air-secondary-alert" :icon="RocketIcon" title="Пробный период подписки закончился. Оформите подписку, чтобы продолжить работу со всеми приложениями." />
</template>
```

### Закрытие

Пропс `close` показывает [кнопку](https://b24-ui.bx-shef.by/raw/docs/components/button.md), которой закрывают Banner. По умолчанию — `false`.

> [!TIP]
> По нажатию на кнопку закрытия возникает событие `close`.

```vue [BannerExample.vue]
<script setup lang="ts">
import type { BannerProps } from '@bxshefby/b24ui-nuxt'
import CircleCrossIcon from '@bitrix24/b24icons-vue/outline/CircleCrossIcon'

const { id = 'example' } = defineProps<{
  id?: string
  title?: string
  color?: BannerProps['color']
  closeIcon?: string
}>()

function onClose() {
  localStorage.removeItem(`banner-${id}`)

  setTimeout(() => {
    document.querySelector('html')?.classList.remove('hide-banner')
  }, 1000)
}

onBeforeMount(() => {
  localStorage.removeItem(`banner-${id}`)
})
</script>

<template>
  <B24Banner
    :id="id"
    :title="title || 'Это баннер, который можно закрыть'"
    :color="color"
    class="light"
    :close-icon="closeIcon ? CircleCrossIcon : undefined"
    close
    @close="onClose"
  />
</template>
```

> [!NOTE]
> После закрытия в локальное хранилище записывается `banner-${id}`, чтобы баннер больше не показывался. <br />
> В примере выше это `banner-example`.

> [!CAUTION]
> Чтобы закрытие сохранялось после перезагрузки страницы, укажите пропс `id`. Без явного `id` баннер скрывается только на время текущей сессии и снова появляется после перезагрузки.

### Иконка закрытия

Пропс `close-icon` задаёт [иконку](https://bitrix24.github.io/b24icons/icons/) кнопки закрытия.

```vue [BannerWithTitleExample.vue]
<script setup lang="ts">
import type { BannerProps } from '@bxshefby/b24ui-nuxt'
import CircleCrossIcon from '@bitrix24/b24icons-vue/outline/CircleCrossIcon'

const { id = 'example' } = defineProps<{
  id?: string
  title?: string
  color?: BannerProps['color']
  closeIcon?: string
}>()

function onClose() {
  localStorage.removeItem(`banner-${id}`)

  setTimeout(() => {
    document.querySelector('html')?.classList.remove('hide-banner')
  }, 1000)
}

onBeforeMount(() => {
  localStorage.removeItem(`banner-${id}`)
})
</script>

<template>
  <B24Banner
    :id="id"
    :title="title || 'Пробный период подписки закончился. Оформите подписку, чтобы продолжить пользоваться всеми приложениями.'"
    :color="color"
    class="edge-light"
    :close-icon="CircleCrossIcon"
    close
    @close="onClose"
  />
</template>
```

### Действия

Пропс `actions` добавляет в Banner действия — [кнопки](https://b24-ui.bx-shef.by/raw/docs/components/button.md).

```vue
<script setup lang="ts">
import { CalendarDate } from '@internationalized/date'
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
import type { ButtonProps } from '@bxshefby/b24ui-nuxt'

const actions = ref<ButtonProps[]>([
  {
    label: 'Оформить подписку',
    color: 'air-primary',
    icon: RocketIcon
  },
  {
    label: 'Открыть сканер',
    color: 'air-secondary-accent-2'
  }
])
</script>

<template>
  <B24Banner title="Пробный период подписки закончился. Оформите подписку, чтобы продолжить работу со всеми приложениями." :actions="actions" />
</template>
```

> [!NOTE]
> У кнопок действий по умолчанию `color="air-secondary-no-accen"` и `size="xs"`. Эти значения можно переопределить в каждой кнопке.

### Ссылка

Можно передать любое свойство компонента [`<NuxtLink>`](https://nuxt.com/docs/api/components/nuxt-link): `to`, `target`, `rel` и другие.

```vue
<template>
  <B24Banner to="https://apidocs.bitrix24.com/" target="_blank" title="Изучите REST API Битрикс24" color="air-primary" />
</template>
```

> [!NOTE]
> `NuxtLink` наследует остальные атрибуты, переданные компоненту `Banner`.

## Примеры

### В `app.vue`

Banner можно разместить в `app.vue` или в раскладке:

```vue [app.vue]
<template>
  <B24App>
    <B24Banner
      :icon="Bitrix24Icon"
      title="Explore the Bitrix24 REST API"
      to="https://apidocs.bitrix24.com/"
    />
    <NuxtLayout>
      <NuxtPage />
    </NuxtLayout>
  </B24App>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Banner component
 */
interface BannerProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * A unique id saved to local storage to remember if the banner has been dismissed.
   * Without an explicit id, the banner will not be persisted and will reappear on page reload.
   */
  id?: string | undefined;
  /**
   * The icon displayed next to the title.
   */
  icon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  title?: string | undefined;
  /**
   * Display a list of actions next to the title.
   * `{ color: 'air-secondary-no-accent', size: 'xs' }`
   */
  actions?: ButtonProps[] | undefined;
  to?: string | J | W | undefined;
  target?: null | "_blank" | "_parent" | "_self" | "_top" | string & {} | undefined;
  /**
   * @default 'air-primary-alert'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-tertiary";
  /**
   * Display a close button to dismiss the banner.
   * `{ size: 'md', color: 'air-tertiary-no-accent' }`
   * @default false
   */
  close?: boolean | Omit<ButtonProps, LinkPropsKeys> | undefined;
  /**
   * The icon displayed in the close button.
   * @default icons.close
   */
  closeIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  b24ui?: { root?: SlotClass; container?: SlotClass; left?: SlotClass; center?: SlotClass; right?: SlotClass; icon?: SlotClass; title?: SlotClass; actions?: SlotClass; close?: SlotClass; } | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Banner component
 */
interface BannerSlots {
  leading(): any;
  title(): any;
  actions(): any;
  close(): any;
}
```

### События

```ts
/**
 * Emitted events for the Banner component
 */
interface BannerEmits {
  close: (payload: []) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    banner: {
      slots: {
        root: 'relative z-50 w-full bg-(--b24ui-background) transition-colors',
        container: 'flex items-center justify-between gap-3 h-12',
        left: 'hidden lg:flex-1 lg:flex lg:items-center',
        center: 'flex items-center gap-1.5 min-w-0',
        right: 'lg:flex-1 flex items-center justify-end',
        icon: 'size-5 shrink-0 text-(--b24ui-color) pointer-events-none',
        title: 'text-(length:--ui-font-size-sm)/(--ui-font-line-height-sm) text-(--b24ui-color) font-(--ui-font-weight-medium) truncate',
        actions: 'flex gap-1.5 shrink-0 isolate',
        close: '[--ui-btn-color:var(--b24ui-color)] hover:bg-(--ui-color-base-white-fixed)/10 focus-visible:bg-(--ui-color-base-white-fixed)/10 -me-1.5 lg:me-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-tinted'
          },
          'air-secondary-alert': {
            root: 'style-tinted-alert'
          },
          'air-secondary-accent': {
            root: 'style-outline'
          },
          'air-secondary-accent-1': {
            root: 'style-outline-accent-1'
          },
          'air-secondary-accent-2': {
            root: 'style-outline-accent-2'
          },
          'air-tertiary': {
            root: 'style-outline-no-accent'
          }
        },
        to: {
          true: ''
        }
      },
      compoundVariants: [
        {
          to: true,
          class: {
            root: 'hover:bg-(--b24ui-background)/90'
          }
        }
      ],
      defaultVariants: {
        color: 'air-primary-alert'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
