---
title: "Header"
description: "Шапка, которая подстраивает структуру и содержимое под размер экрана."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/header"
---
# Header

> Шапка, которая подстраивает структуру и содержимое под размер экрана.

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

Компонент Header отрисовывает элемент `<header>`.

> [!TIP]
> See: /docs/getting-started/theme/css-variables/#header
> Высота шапки задаётся CSS-переменной `--b24ui-header-height`.

Слоты `left`, `default` и `right` настраивают шапку, а слоты `body` и `content` — меню шапки.

```vue [HeaderExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Документация',
    to: '/docs/getting-started',
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Компоненты',
    to: '/docs/components',
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    target: '_blank'
  },
  {
    label: 'Релизы',
    to: 'https://github.com/bitrix24/b24ui/releases',
    target: '_blank'
  }
])
</script>

<template>
  <B24Header>
    <template #title>
      <Logo class="h-6 w-auto" />
    </template>

    <B24NavigationMenu :items="items" />

    <template #right>
      <B24ColorModeButton />

      <B24Tooltip text="Открыть на GitHub" :kbds="['meta', 'G']">
        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </B24Tooltip>
    </template>
  </B24Header>
</template>
```

> [!NOTE]
> В этом примере ссылки шапки по центру отрисованы компонентом [NavigationMenu](https://b24-ui.bx-shef.by/raw/docs/components/navigation-menu.md).

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

Пропс `title` меняет заголовок шапки. По умолчанию `Bitrix24 UI`.

```vue
<template>
  <B24Header title="Bitrix24 UI" />
</template>
```

Слот `title` позволяет добавить собственный логотип.

> [!TIP]
> See: #props
> Пропс `title` всё равно стоит указать, чтобы заменить `aria-label` ссылки по умолчанию.

```vue
<template>
  <B24Header>
  <template #title>
    
<Logo class="h-6 w-auto text-label" />

  </template>
</B24Header>
</template>
```

### Ссылка

Пропс `to` меняет ссылку заголовка. По умолчанию `/`.

```vue
<template>
  <B24Header to="/docs/" />
</template>
```

Слот `left` позволяет полностью заменить ссылку.

```vue
<template>
  <B24Header>
  <template #left>
    
<NuxtLink to="/docs"">
  <Logo class="h-6 w-auto text-label" />
</NuxtLink>

  </template>
</B24Header>
</template>
```

### Режим

Пропс `mode` меняет режим меню шапки. По умолчанию `slideover`.

Слот `body` заполняет тело меню (под шапкой), слот `content` — всё меню целиком.

> [!TIP]
> See: #props
> Пропс `menu` настраивает меню шапки; оно подстраивается под выбранный режим.

```vue [HeaderMenuExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'
import Bitrix24Icon from '@bitrix24/b24icons-vue/common-service/Bitrix24Icon'
import PlayLIcon from '@bitrix24/b24icons-vue/outline/PlayLIcon'
import DeveloperResourcesIcon from '@bitrix24/b24icons-vue/outline/DeveloperResourcesIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Документация',
    to: '/docs/getting-started',
    icon: PlayLIcon,
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Компоненты',
    to: '/docs/components',
    icon: DeveloperResourcesIcon,
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    icon: Bitrix24Icon,
    target: '_blank'
  },
  {
    label: 'Релизы',
    to: 'https://github.com/bitrix24/b24ui/releases',
    icon: GitHubIcon,
    target: '_blank'
  }
])
</script>

<template>
  <B24Header>
    <template #title>
      <Logo class="h-6 w-auto text-label" />
    </template>

    <B24NavigationMenu :items="items" />

    <template #right>
      <B24ColorModeButton />

      <B24Tooltip text="Открыть на GitHub" :kbds="['meta', 'G']">
        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </B24Tooltip>
    </template>

    <template #body>
      <B24NavigationMenu :items="items" orientation="vertical" class="-mx-2.5" />
    </template>
  </B24Header>
</template>
```

### Переключатель

Пропс `toggle` настраивает кнопку-переключатель, которая отображается на мобильных.

Можно передать любое свойство компонента [Button](https://b24-ui.bx-shef.by/raw/docs/components/button.md).

```vue [HeaderToggleExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'
import Bitrix24Icon from '@bitrix24/b24icons-vue/common-service/Bitrix24Icon'
import PlayLIcon from '@bitrix24/b24icons-vue/outline/PlayLIcon'
import DeveloperResourcesIcon from '@bitrix24/b24icons-vue/outline/DeveloperResourcesIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Документация',
    to: '/docs/getting-started',
    icon: PlayLIcon,
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Компоненты',
    to: '/docs/components',
    icon: DeveloperResourcesIcon,
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    icon: Bitrix24Icon,
    target: '_blank'
  },
  {
    label: 'Релизы',
    to: 'https://github.com/bitrix24/b24ui/releases',
    icon: GitHubIcon,
    target: '_blank'
  }
])
</script>

<template>
  <B24Header
    :toggle="{
      color: 'air-boost',
      rounded: true
    }"
  >
    <template #title>
      <Logo class="h-6 w-auto text-label" />
    </template>

    <B24NavigationMenu :items="items" />

    <template #right>
      <B24ColorModeButton />

      <B24Tooltip text="Открыть на GitHub" :kbds="['meta', 'G']">
        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </B24Tooltip>
    </template>

    <template #body>
      <B24NavigationMenu :items="items" orientation="vertical" class="-mx-2.5" />
    </template>
  </B24Header>
</template>
```

### Сторона переключателя

Пропс `toggle-side` меняет сторону кнопки-переключателя. По умолчанию `left`.

```vue [HeaderToggleSideExample.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'
import Bitrix24Icon from '@bitrix24/b24icons-vue/common-service/Bitrix24Icon'
import PlayLIcon from '@bitrix24/b24icons-vue/outline/PlayLIcon'
import DeveloperResourcesIcon from '@bitrix24/b24icons-vue/outline/DeveloperResourcesIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Документация',
    to: '/docs/getting-started',
    icon: PlayLIcon,
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Компоненты',
    to: '/docs/components',
    icon: DeveloperResourcesIcon,
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    icon: Bitrix24Icon,
    target: '_blank'
  },
  {
    label: 'Релизы',
    to: 'https://github.com/bitrix24/b24ui/releases',
    icon: GitHubIcon,
    target: '_blank'
  }
])
</script>

<template>
  <B24Header toggle-side="right">
    <template #title>
      <Logo class="h-6 w-auto text-label" />
    </template>

    <B24NavigationMenu :items="items" />

    <template #right>
      <B24ColorModeButton />

      <B24Tooltip text="Открыть на GitHub" :kbds="['meta', 'G']">
        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </B24Tooltip>
    </template>

    <template #body>
      <B24NavigationMenu :items="items" orientation="vertical" class="-mx-2.5" />
    </template>
  </B24Header>
</template>
```

## Примеры

### С анимированным переключателем

Слот `#toggle` заменяет кнопку-переключатель по умолчанию собственной анимированной иконкой-гамбургером на основе [Motion Vue](https://motion.dev/docs/vue/motion-component).

```vue [HeaderToggleAnimatedExample.vue]
<script setup lang="ts">
import type { VariantType } from 'motion-v'
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import { motion } from 'motion-v'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Документация',
    to: '/docs/getting-started',
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Компоненты',
    to: '/docs/components',
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    target: '_blank'
  },
  {
    label: 'Релизы',
    to: 'https://github.com/bitrix24/b24ui/releases',
    target: '_blank'
  }
])

const variants: { [k: string]: VariantType | ((custom: unknown) => VariantType) } = {
  normal: {
    rotate: 0,
    y: 0,
    opacity: 1
  },
  close: (custom: unknown) => {
    const c = custom as number
    return {
      rotate: c === 1 ? 45 : c === 3 ? -45 : 0,
      y: c === 1 ? 6 : c === 3 ? -6 : 0,
      opacity: c === 2 ? 0 : 1,
      transition: {
        type: 'spring',
        stiffness: 260,
        damping: 20
      }
    }
  }
}
</script>

<template>
  <B24Header>
    <template #title>
      <Logo class="h-6 w-auto" />
    </template>

    <B24NavigationMenu :items="items" />

    <template #right>
      <B24ColorModeButton />

      <B24Tooltip text="Открыть на GitHub" :kbds="['meta', 'G']">
        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </B24Tooltip>
    </template>

    <template #toggle="{ open, toggle, b24ui }">
      <B24Button
        size="sm"
        square
        :class="b24ui.toggle({ toggleSide: 'right' })"
        @click="toggle"
      >
        <svg
          xmlns="http://www.w3.org/2000/svg"
          class="size-5"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
        >
          <motion.line
            x1="4"
            y1="6"
            x2="20"
            y2="6"
            :variants="variants"
            :animate="open ? 'close' : 'normal'"
            :custom="1"
            tabindex="-1"
          />
          <motion.line
            x1="4"
            y1="12"
            x2="20"
            y2="12"
            :variants="variants"
            :animate="open ? 'close' : 'normal'"
            :custom="2"
            tabindex="-1"
          />
          <motion.line
            x1="4"
            y1="18"
            x2="20"
            y2="18"
            :variants="variants"
            :animate="open ? 'close' : 'normal'"
            :custom="3"
            tabindex="-1"
          />
        </svg>
      </B24Button>
    </template>

    <template #body>
      <B24NavigationMenu :items="items" orientation="vertical" class="-mx-2.5" />
    </template>
  </B24Header>
</template>
```

### В `app.vue`

Используйте Header в `app.vue` или в раскладке:

```vue [app.vue]
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import GitHubIcon from '@bitrix24/b24icons-vue/social/GitHubIcon'

const route = useRoute()

const items = computed<NavigationMenuItem[]>(() => [
  {
    label: 'Docs',
    to: '/docs/getting-started',
    active: route.path.startsWith('/docs/getting-started')
  },
  {
    label: 'Components',
    to: '/docs/components',
    active: route.path.startsWith('/docs/components')
  },
  {
    label: 'REST API',
    to: 'https://apidocs.bitrix24.com',
    target: '_blank'
  },
  {
    label: 'Releases',
    to: 'https://github.com/bitrix24/b24ui/releases',
    target: '_blank'
  }
])
</script>

<template>
  <B24App>
    <B24Header>
      <template #title>
        <Logo class="h-6 w-auto" />
      </template>

      <B24NavigationMenu :items="items" />

      <template #right>
        <B24ColorModeButton />

        <B24Button
          to="https://github.com/bitrix24/b24ui"
          target="_blank"
          :icon="GitHubIcon"
          aria-label="GitHub"
        />
      </template>

      <template #body>
        <B24NavigationMenu :items="items" orientation="vertical" class="-mx-2.5" />
      </template>
    </B24Header>

    <B24Main>
      <NuxtLayout>
        <NuxtPage />
      </NuxtLayout>
    </B24Main>

    <B24Footer />
  </B24App>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Header component
 */
interface HeaderProps {
  /**
   * The element or component this component should render as.
   * @default 'header'
   */
  as?: any;
  /**
   * @default 'Bitrix24 UI'
   */
  title?: string | undefined;
  /**
   * @default '/'
   */
  to?: string | undefined;
  /**
   * The mode of the header menu.
   * @default 'slideover'
   */
  mode?: T | undefined;
  /**
   * The props for the header menu component.
   */
  menu?: HeaderMenu<T> | undefined;
  /**
   * Customize the toggle button to open the header menu displayed when the `content` slot is used.
   * `{ color: 'air-tertiary', size: 'md' }`
   * @default true
   */
  toggle?: boolean | Omit<ButtonProps, LinkPropsKeys> | undefined;
  /**
   * The side to render the toggle button on.
   * @default 'left'
   */
  toggleSide?: "left" | "right" | undefined;
  /**
   * Automatically close when route changes.
   * @default true
   */
  autoClose?: boolean | undefined;
  b24ui?: { root?: SlotClass; container?: SlotClass; left?: SlotClass; center?: SlotClass; right?: SlotClass; title?: SlotClass; toggle?: SlotClass; content?: SlotClass; overlay?: SlotClass; header?: SlotClass; body?: SlotClass; } | undefined;
  /**
   * @default false
   */
  open?: boolean | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Header component
 */
interface HeaderSlots {
  title(): any;
  left(): any;
  default(): any;
  right(): any;
  toggle(): any;
  top(): any;
  bottom(): any;
  body(): any;
  content(): any;
}
```

### События

```ts
/**
 * Emitted events for the Header component
 */
interface HeaderEmits {
  update:open: (payload: [value: boolean]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    header: {
      slots: {
        root: 'bg-(--ui-color-bg-content-primary)/75 backdrop-blur-sm border-b border-(--ui-color-divider-default) h-(--b24ui-header-height) sticky top-0 z-50',
        container: 'flex items-center justify-between gap-3 h-full',
        left: 'lg:flex-1 flex items-center gap-1.5',
        center: 'hidden lg:flex',
        right: 'flex items-center justify-end lg:flex-1 gap-1.5',
        title: 'shrink-0 font-bold text-xl text-label flex items-end gap-1.5',
        toggle: 'lg:hidden',
        content: 'lg:hidden',
        overlay: 'lg:hidden',
        header: 'px-4 sm:px-6 h-(--b24ui-header-height) shrink-0 flex items-center justify-between gap-3',
        body: 'p-4 sm:p-6 overflow-y-auto'
      },
      variants: {
        toggleSide: {
          left: {
            toggle: '-ms-1.5'
          },
          right: {
            toggle: '-me-1.5'
          }
        }
      }
    }
  }
})
```

## Sitemap

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