v2.15.0

DashboardSidebar

Боковое меню дашборда с изменяемым размером и возможностью сворачивания.

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

Компонент DashboardSidebar показывает боковое меню. Его состояние (размер, свёрнутость и другое) сохраняется по пропсам storage и storage-key компонента DashboardGroup.

Используйте его в слоте по умолчанию компонента DashboardGroup:

layouts/dashboard.vue
<template>
  <B24DashboardGroup>
    <B24DashboardSidebar />

    <slot />
  </B24DashboardGroup>
</template>
С пропсом resizable у компонента нет единого корневого элемента, поэтому при переходах между страницами или если нужен единый корень для раскладки, оберните его в контейнер (например, <div class="flex flex-1">).

Слоты header, default и footer настраивают боковое меню, а слоты body и content — его мобильное меню.

<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'
import SettingsIcon from '@bitrix24/b24icons-vue/outline/SettingsIcon'
import FeedbackIcon from '@bitrix24/b24icons-vue/outline/FeedbackIcon'
import InfoCircleIcon from '@bitrix24/b24icons-vue/outline/InfoCircleIcon'

const items: NavigationMenuItem[][] = [
  [
    {
      label: 'Главная',
      icon: HomeIcon,
      active: true
    },
    {
      label: 'Входящие',
      icon: MailIcon,
      badge: '4'
    },
    {
      label: 'Контакты',
      icon: ContactIcon
    },
    {
      label: 'Настройки',
      icon: SettingsIcon,
      defaultOpen: true,
      children: [
        {
          label: 'Общие'
        },
        {
          label: 'Участники'
        },
        {
          label: 'Уведомления'
        }
      ]
    }
  ],
  [
    {
      label: 'Обратная связь',
      icon: FeedbackIcon,
      to: 'https://github.com/bitrix24/b24ui/issues',
      target: '_blank'
    },
    {
      label: 'Помощь и поддержка',
      icon: InfoCircleIcon,
      to: 'https://github.com/bitrix24/b24ui',
      target: '_blank'
    }
  ]
]
</script>

<template>
  <B24DashboardSidebar
    collapsible
    resizable
    class="border-e-1"
  >
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto shrink-0 text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <template #default="{ collapsed }">
      <B24DashboardSearchButton :collapsed="collapsed" />

      <B24NavigationMenu
        :collapsed="collapsed"
        :items="items[0]"
        orientation="vertical"
      />

      <B24NavigationMenu
        :collapsed="collapsed"
        :items="items[1]"
        orientation="vertical"
        class="mt-auto"
      />
    </template>

    <template #footer="{ collapsed }">
      <B24Button
        :avatar="{
          src: 'https://github.com/bitrix24.png',
          loading: 'lazy' as const
        }"
        :label="collapsed ? undefined : 'Bitrix24'"
        class="w-full"
        :block="collapsed"
      />
    </template>
  </B24DashboardSidebar>
</template>
Чтобы свернуть меню, перетащите его к левому краю экрана.

Изменяемый размер

Пропс resizable делает размер бокового меню изменяемым.

<template>
  <B24DashboardSidebar resizable>
    <Placeholder class="ms-2 h-96" />
  </B24DashboardSidebar>
</template>

Сворачивание

Пропс collapsible позволяет сворачивать боковое меню, когда его перетаскивают к краю экрана.

Если боковое меню не collapsible, компонент DashboardSidebarCollapse ничего не сделает.
<template>
  <B24DashboardSidebar resizable collapsible>
    <Placeholder class="ms-2 h-96" />
  </B24DashboardSidebar>
</template>
Состояние collapsed доступно в слот-пропсах, поэтому содержимое свёрнутого меню можно настроить.

Размер

Пропсы min-size, max-size, default-size и collapsed-size (в px) задают размер бокового меню.

<template>
  <B24DashboardSidebar
    resizable
    collapsible
    :min-size="200"
    :default-size="240"
    :max-size="250"
    :collapsed-size="66"
  >
    <Placeholder class="ms-2 h-96" />
  </B24DashboardSidebar>
</template>
По умолчанию размеры считаются в процентах. Единицу меняет пропс unit компонента DashboardGroup.
По умолчанию collapsed-size равен 0, но у бокового меню есть min-w-16, чтобы оно оставалось видимым.

Сторона

Пропс side меняет сторону бокового меню. По умолчанию left.

<template>
  <B24DashboardSidebar side="right" resizable collapsible>
    <Placeholder class="ms-2 h-96" />
  </B24DashboardSidebar>
</template>

Режим

Пропс mode меняет режим мобильного меню. По умолчанию slideover.

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

Пропс menu настраивает мобильное меню бокового меню и подстраивается под выбранный режим.
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

defineProps<{
  mode: 'drawer' | 'slideover' | 'modal'
}>()

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      :mode="mode"
    >
      <template #header="{ collapsed }">
        <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
        <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>
В этих примерах есть компоненты DashboardGroup, DashboardPanel и DashboardNavbar: они нужны, чтобы показать боковое меню на мобильных устройствах.

Кнопка переключения

Пропс toggle настраивает компонент DashboardSidebarToggle, который показывается на мобильных устройствах.

Кнопку можно настроить любым свойством компонента Button.

<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      open
      :toggle="{
        color: 'air-primary',
        class: 'rounded-full'
      }"
    >
      <template #header>
        <Logo class="h-5 w-auto text-label" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>

Сторона кнопки

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

<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]
</script>

<template>
  <B24DashboardGroup>
    <B24DashboardSidebar
      open
      toggle-side="right"
    >
      <template #header>
        <Logo class="h-5 w-auto text-label" />
      </template>

      <B24NavigationMenu
        :items="items"
        orientation="vertical"
      />
    </B24DashboardSidebar>

    <B24DashboardPanel>
      <template #header>
        <B24DashboardNavbar title="Дашборд" class="bg-(--ui-color-design-outline-bg-alt) backdrop-blur-md" />
      </template>
    </B24DashboardPanel>
  </B24DashboardGroup>
</template>

Примеры

Управление состоянием открытия

Состоянием открытия управляют пропс open или директива v-model:open.

В этом примере с помощью defineShortcuts DashboardSidebar открывается и закрывается клавишей O.
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const open = ref(true)

defineShortcuts({
  o: () => open.value = !open.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:open="open"
  >
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const open = ref(true)

defineShortcuts({
  o: () => open.value = !open.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:open="open"
  >
    <template #header="{ collapsed }">
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>

Управление состоянием сворачивания

Состоянием сворачивания управляют пропс collapsed или директива v-model:collapsed.

В этом примере с помощью defineShortcuts DashboardSidebar сворачивается и разворачивается клавишей C.
<script setup lang="ts">
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const collapsed = ref(false)

defineShortcuts({
  c: () => collapsed.value = !collapsed.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:collapsed="collapsed"
    collapsible
    class="border-e-1"
  >
    <template #header>
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :collapsed="collapsed"
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { NavigationMenuItem } from '@bxshefby/b24ui-nuxt'
import B24Icon from '@bitrix24/b24icons-vue/main/B24Icon'
import HomeIcon from '@bitrix24/b24icons-vue/outline/HomeIcon'
import MailIcon from '@bitrix24/b24icons-vue/outline/MailIcon'
import ContactIcon from '@bitrix24/b24icons-vue/outline/ContactIcon'

const items: NavigationMenuItem[] = [
  {
    label: 'Главная',
    icon: HomeIcon,
    active: true
  },
  {
    label: 'Входящие',
    icon: MailIcon
  },
  {
    label: 'Контакты',
    icon: ContactIcon
  }
]

const collapsed = ref(false)

defineShortcuts({
  c: () => collapsed.value = !collapsed.value
})
</script>

<template>
  <B24DashboardSidebar
    v-model:collapsed="collapsed"
    collapsible
    class="border-e-1"
  >
    <template #header>
      <Logo v-if="!collapsed" class="h-5 w-auto text-label" />
      <B24Icon v-else class="size-10 text-[#2fc6f6] mx-auto" />
    </template>

    <B24NavigationMenu
      :collapsed="collapsed"
      :items="items"
      orientation="vertical"
    />
  </B24DashboardSidebar>
</template>

API

Пропсы

Prop Default Type
mode'slideover' T

The mode of the sidebar menu.

menu DashboardSidebarMenu<T>

The props for the sidebar menu component.

toggletrueboolean | Omit<ButtonProps, LinkPropsKeys>

Customize the toggle button to open the sidebar. { color: 'air-tertiary' }

toggleSide'left' "left" | "right"

The side to render the toggle button on.

autoClosetrueboolean

Automatically close when route changes.

iduseId() string

The id of the panel.

side'left' "left" | "right"

The side to render the panel on.

minSize200 number

The minimum size of the panel.

maxSize250 number

The maximum size of the panel.

defaultSize240 number

The default size of the panel.

resizablefalseboolean

Whether to allow the user to resize the panel.

collapsiblefalseboolean

Whether to allow the user to collapse the panel. collapse() and isCollapsed do nothing while this is off.

collapsedSize66 number

The size of the panel when collapsed.

openfalseboolean
collapsedfalseboolean
b24ui { root?: SlotClass; header?: SlotClass; body?: SlotClass; footer?: SlotClass; toggle?: SlotClass; handle?: SlotClass; content?: SlotClass; overlay?: SlotClass; }

Слоты

Slot Type
header{ collapsed: boolean; collapse: (value: boolean) => void; }
default{ collapsed: boolean; collapse: (value: boolean) => void; }
footer{ collapsed: boolean; collapse: (value: boolean) => void; }
toggle{ open: boolean; toggle: () => void; b24ui: object; }
content{ close?: (() => void) | undefined; }
resize-handle{ onMouseDown: (e: MouseEvent) => void; onTouchStart: (e: TouchEvent) => void; onDoubleClick: (e: MouseEvent) => void; b24ui: object; }

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/dashboard-sidebar.ts
export default {
  slots: {
    root: 'relative hidden lg:flex flex-col min-h-svh min-w-16 w-(--width) shrink-0 backdrop-blur-sm bg-(--ui-color-bg-content-primary)/20 light:bg-transparent dark:bg-(--ui-color-bg-content-primary)/70 light:bg-transparent',
    header: 'h-(--b24ui-header-height) shrink-0 flex items-center gap-1.5 ps-4 pe-4',
    body: [
      'flex flex-col gap-4 flex-1 overflow-y-auto py-2 ps-4 pe-4 md:pe-2 scrollbar-thin scrollbar-transparent',
      'light:[--leftmenu-group-stroke:var(--ui-color-base-30)]'
    ],
    footer: 'shrink-0 flex items-center gap-1.5 py-2 ps-4 pe-4 lg:border-t lg:border-(--ui-color-divider-default) light:lg:border-(--ui-color-base-30)',
    toggle: '',
    handle: '',
    content: 'lg:hidden',
    overlay: 'lg:hidden'
  },
  variants: {
    menu: {
      true: {
        header: 'sm:px-6',
        body: 'sm:px-6',
        footer: 'sm:px-6'
      }
    },
    side: {
      left: {
        root: ''
      },
      right: {
        root: ''
      }
    },
    toggleSide: {
      left: {
        toggle: ''
      },
      right: {
        toggle: 'ms-auto'
      }
    }
  }
}