Sidebar
Боковое меню приложения собирается из разделов с пунктами-ссылками, шапка и подвал остаются на месте, пока середина прокручивается.
Состав: CloseButton, IconButton, Slideout, Tooltip.
Импорт
ts
import { SidebarProvider, Sidebar, SidebarHeader, SidebarTitle, SidebarTrigger, SidebarContent, SidebarSection, SidebarHeading, SidebarSectionAction, SidebarItem, SidebarItemAction, SidebarItemSkeleton, SidebarGroup, SidebarDivider, SidebarFooter, SidebarCard, SidebarCardHeading, SidebarCardTitle, SidebarCardDescription, SidebarCardActions, SidebarCardClose, SidebarRail, SidebarInset, useSidebar } from '@prosper/ui'Анатомия
vue
<SidebarProvider>
<Sidebar>
<SidebarHeader>
<SidebarTitle />
<SidebarTrigger />
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarHeading />
<SidebarSectionAction />
<SidebarItem>
<template #action>
<SidebarItemAction />
</template>
</SidebarItem>
<SidebarItemSkeleton />
<SidebarGroup>
<SidebarItem />
</SidebarGroup>
</SidebarSection>
<SidebarDivider />
</SidebarContent>
<SidebarFooter>
<SidebarCard>
<SidebarCardHeading>
<SidebarCardTitle />
<SidebarCardDescription />
</SidebarCardHeading>
<SidebarCardActions />
<SidebarCardClose />
</SidebarCard>
</SidebarFooter>
<SidebarRail />
</Sidebar>
<SidebarInset />
</SidebarProvider>Примеры
По умолчанию
Три раздела с подзаголовками в колонке высотой 560, середина прокручивается.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarHeading,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import {
BarChart01,
CheckDone01,
Folder,
HomeLine,
LayersThree01,
LifeBuoy01,
Settings01,
Users01,
} from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: по умолчанию">
<SidebarHeader>
<a href="#" class="logo">
<LayersThree01 />
Prosper
</a>
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarHeading>Общее</SidebarHeading>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
<SidebarItem href="#">
<template #leading><CheckDone01 /></template>
Задачи
</SidebarItem>
<SidebarItem href="#">
<template #leading><BarChart01 /></template>
Отчёты
</SidebarItem>
</SidebarSection>
<SidebarSection>
<SidebarHeading>Команда</SidebarHeading>
<SidebarItem href="#">
<template #leading><Users01 /></template>
Пользователи
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
</SidebarSection>
<SidebarSection>
<SidebarHeading>Архив</SidebarHeading>
<SidebarItem href="#">
<template #leading><Folder /></template>
Закрытые проекты
</SidebarItem>
<SidebarItem href="#">
<template #leading><BarChart01 /></template>
Прошлые отчёты
</SidebarItem>
<SidebarItem href="#">
<template #leading><CheckDone01 /></template>
Выполненные задачи
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>
<style scoped>
.logo {
display: inline-flex;
align-items: center;
gap: var(--prosper-spacing-md);
color: var(--prosper-color-text-primary);
font-weight: var(--prosper-font-weight-semibold);
text-decoration: none;
}
</style>Варианты
variant="panel" рисует границу в конце колонки вместо карточки.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarHeading,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { Folder, HomeLine, Settings01 } from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 35rem">
<Sidebar variant="panel" aria-label="Пример меню: панель">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarHeading>Общее</SidebarHeading>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Колонка внутри страницы
variant="inset" оставляет колонку белой и без рамки, а SidebarInset рисует содержимое страницы поверхностью на сером фоне с рамкой сверху и в начале.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarInset,
SidebarItem,
SidebarProvider,
SidebarSection,
SidebarTrigger,
} from '@prosper/ui'
import { BarChart01, HomeLine, Users01 } from '@prosper/ui/icons'
</script>
<template>
<SidebarProvider :mobile="false" :shortcut="false">
<div
style="
display: flex;
block-size: 30rem;
background-color: var(--prosper-color-bg-secondary);
"
>
<Sidebar variant="inset" aria-label="Пример меню: внутренняя колонка">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><BarChart01 /></template>
Продажи
</SidebarItem>
<SidebarItem href="#">
<template #leading><Users01 /></template>
Клиенты
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
<SidebarInset as="div">
<div
style="
display: flex;
align-items: center;
gap: var(--prosper-spacing-lg);
padding: var(--prosper-spacing-2xl);
"
>
<SidebarTrigger />
<p>Обзор продаж за месяц</p>
</div>
</SidebarInset>
</div>
</SidebarProvider>
</template>Размеры
size меняет высоту пункта, а variant="outline" обводит его рамкой и тенью.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
</script>
<template>
<div style="block-size: 20rem">
<Sidebar aria-label="Пример меню: размеры">
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" size="sm">Небольшой пункт</SidebarItem>
<SidebarItem href="#">Обычный пункт</SidebarItem>
<SidebarItem href="#" size="lg">Крупный пункт</SidebarItem>
<SidebarItem href="#" variant="outline" current>
Пункт с обводкой
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Разделители
SidebarDivider между разделами без подзаголовков.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarDivider,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import {
BarChart01,
CheckDone01,
Folder,
HomeLine,
LifeBuoy01,
Settings01,
} from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: разделители">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
</SidebarSection>
<SidebarDivider />
<SidebarSection>
<SidebarItem href="#">
<template #leading><CheckDone01 /></template>
Задачи
</SidebarItem>
<SidebarItem href="#">
<template #leading><BarChart01 /></template>
Отчёты
</SidebarItem>
</SidebarSection>
<SidebarDivider />
<SidebarSection>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Значки и счётчики
Badge в слоте trailing пункта и группы.
vue
<script setup lang="ts">
import {
Badge,
Sidebar,
SidebarContent,
SidebarGroup,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { CheckDone01, Folder, HomeLine, Users01 } from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: значки и счётчики">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><CheckDone01 /></template>
Задачи
<template #trailing>
<Badge size="sm" color="brand">12</Badge>
</template>
</SidebarItem>
<SidebarGroup>
<template #leading><Folder /></template>
<template #label>Проекты</template>
<template #trailing>
<Badge size="sm">3</Badge>
</template>
<SidebarItem href="#">Активные</SidebarItem>
<SidebarItem href="#">Архив</SidebarItem>
</SidebarGroup>
<SidebarItem href="#">
<template #leading><Users01 /></template>
Пользователи
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Загрузка
Пока раздел грузится, SidebarItemSkeleton занимает место пунктов и скрыт от скринридера.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeading,
SidebarItemSkeleton,
SidebarSection,
} from '@prosper/ui'
</script>
<template>
<div style="block-size: 20rem">
<Sidebar aria-label="Пример меню: загрузка">
<SidebarContent>
<SidebarSection aria-busy="true">
<SidebarHeading>Проекты</SidebarHeading>
<SidebarItemSkeleton />
<SidebarItemSkeleton />
<SidebarItemSkeleton />
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Действия
SidebarItemAction в слоте action открывает меню по наведению, а SidebarSectionAction стоит в строке подзаголовка.
vue
<script setup lang="ts">
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
Sidebar,
SidebarContent,
SidebarHeading,
SidebarItem,
SidebarItemAction,
SidebarSection,
SidebarSectionAction,
} from '@prosper/ui'
import { DotsVertical, Plus } from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 20rem">
<Sidebar aria-label="Пример меню: действия">
<SidebarContent>
<SidebarSection>
<SidebarHeading>Проекты</SidebarHeading>
<SidebarSectionAction label="Добавить проект">
<Plus />
</SidebarSectionAction>
<SidebarItem href="#" current>
Сайт
<template #action>
<DropdownMenu>
<DropdownMenuTrigger as-child>
<SidebarItemAction label="Действия с проектом" reveal="hover">
<DotsVertical />
</SidebarItemAction>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>Переименовать</DropdownMenuItem>
<DropdownMenuItem>Архивировать</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</template>
</SidebarItem>
<SidebarItem href="#">Приложение</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Группа
Группы с v-model:open, раскрытая в начале и закрытая с текущим пунктом внутри; группа «Проекты» держит вложенную группу.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { BarChart01, Folder, HomeLine, Users01 } from '@prosper/ui/icons'
import { ref } from 'vue'
const projectsOpen = ref(true)
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: группа">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#">
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarGroup v-model:open="projectsOpen">
<template #leading><Folder /></template>
<template #label>Проекты</template>
<SidebarItem href="#" current>Активные</SidebarItem>
<SidebarItem href="#">Черновики</SidebarItem>
<SidebarItem href="#">Архив</SidebarItem>
<SidebarGroup default-open>
<template #label>Клиенты</template>
<SidebarItem href="#">Иван Петров</SidebarItem>
<SidebarItem href="#">Мария Сидорова</SidebarItem>
</SidebarGroup>
</SidebarGroup>
<SidebarGroup default-open>
<template #leading><BarChart01 /></template>
<template #label>Отчёты</template>
<SidebarItem href="#">Продажи</SidebarItem>
<SidebarItem href="#">Расходы</SidebarItem>
</SidebarGroup>
<SidebarGroup>
<template #leading><Users01 /></template>
<template #label>Команда</template>
<SidebarItem href="#" current>Участники</SidebarItem>
<SidebarItem href="#">Роли</SidebarItem>
</SidebarGroup>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Как ссылка
as принимает компонент ссылки роутера.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { Folder, HomeLine, Settings01 } from '@prosper/ui/icons'
import { defineComponent, h } from 'vue'
const RouterLink = defineComponent({
props: { to: { type: String, required: true } },
setup:
(props, { slots }) =>
() =>
h('a', { href: `#${props.to}` }, slots.default?.()),
})
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: ссылки роутера">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem :as="RouterLink" to="/" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem :as="RouterLink" to="/projects">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
<SidebarItem :as="RouterLink" to="/settings">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Поиск в шапке
InputGroup с иконкой поиска и подсказкой Kbd под логотипом.
vue
<script setup lang="ts">
import {
InputGroup,
InputGroupAddon,
InputGroupInput,
Kbd,
Sidebar,
SidebarContent,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { Folder, HomeLine, SearchLg, Settings01 } from '@prosper/ui/icons'
import { ref } from 'vue'
const query = ref('')
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: поиск">
<SidebarHeader>
Prosper
<InputGroup size="sm">
<InputGroupAddon><SearchLg /></InputGroupAddon>
<InputGroupInput
v-model="query"
type="search"
aria-label="Поиск"
placeholder="Поиск"
/>
<InputGroupAddon variant="inline" align="end">
<Kbd aria-hidden="true">⌘K</Kbd>
</InputGroupAddon>
</InputGroup>
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Аккаунт в подвале
Пункты, AvatarLabelGroup и IconButton с DropdownMenu в SidebarFooter.
vue
<script setup lang="ts">
import {
Avatar,
AvatarFallback,
AvatarLabelGroup,
AvatarLabelGroupDescription,
AvatarLabelGroupName,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
IconButton,
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import {
DotsVertical,
Folder,
HomeLine,
LifeBuoy01,
Settings01,
} from '@prosper/ui/icons'
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: аккаунт">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarFooter>
<SidebarSection>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--prosper-spacing-lg);
"
>
<AvatarLabelGroup size="md">
<Avatar><AvatarFallback>ОР</AvatarFallback></Avatar>
<AvatarLabelGroupName>Олег Рыбаков</AvatarLabelGroupName>
<AvatarLabelGroupDescription>
oleg@example.com
</AvatarLabelGroupDescription>
</AvatarLabelGroup>
<DropdownMenu>
<DropdownMenuTrigger as-child>
<IconButton variant="tertiary" aria-label="Меню аккаунта">
<DotsVertical />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>Профиль</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>Выйти</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</SidebarFooter>
</Sidebar>
</div>
</template>Промокарточка
SidebarCard в подвале держит заголовок, ProgressBar и действия, а по нажатию SidebarCardClose приложение скрывает карточку и переводит фокус на ссылку подвала.
vue
<script setup lang="ts">
import { nextTick, ref, useTemplateRef } from 'vue'
import {
Button,
ProgressBar,
Sidebar,
SidebarCard,
SidebarCardActions,
SidebarCardClose,
SidebarCardDescription,
SidebarCardHeading,
SidebarCardTitle,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { HomeLine, LifeBuoy01 } from '@prosper/ui/icons'
const shown = ref(true)
const footer = useTemplateRef<HTMLElement>('footer')
const dismiss = async (): Promise<void> => {
shown.value = false
await nextTick()
footer.value?.querySelector('a')?.focus()
}
</script>
<template>
<div style="block-size: 35rem">
<Sidebar aria-label="Пример меню: промокарточка">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarFooter>
<div ref="footer">
<SidebarSection>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
</SidebarSection>
</div>
<SidebarCard v-if="shown">
<SidebarCardHeading>
<SidebarCardTitle>Занятое место</SidebarCardTitle>
<SidebarCardDescription>
Команда заняла 80% хранилища, освободите место или улучшите тариф.
</SidebarCardDescription>
</SidebarCardHeading>
<ProgressBar :value="80" aria-label="Занятое место" />
<SidebarCardActions>
<Button variant="link-gray" size="sm" @click="dismiss">
Скрыть
</Button>
<Button variant="link-color" size="sm">Улучшить тариф</Button>
</SidebarCardActions>
<SidebarCardClose @click="dismiss" />
</SidebarCard>
</SidebarFooter>
</Sidebar>
</div>
</template>Полоса и вторая колонка
Для полосы slim вынесите вложенные пункты групп во вторую колонку secondary и отметьте активный раздел через current="section".
vue
<script setup lang="ts">
import {
Avatar,
AvatarFallback,
AvatarLabelGroup,
AvatarLabelGroupDescription,
AvatarLabelGroupName,
Badge,
IconButton,
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarItem,
SidebarSection,
SidebarTitle,
} from '@prosper/ui'
import {
BarChartSquare02,
Bell01,
ClockRewind,
DotsVertical,
HomeLine,
LayersThree01,
LifeBuoy01,
PieChart03,
Settings01,
Star01,
Users01,
} from '@prosper/ui/icons'
const sections = [
{ label: 'Обзор', icon: BarChartSquare02 },
{ label: 'Уведомления', icon: Bell01, count: 10 },
{ label: 'Аналитика', icon: PieChart03 },
{ label: 'Сохранённые отчёты', icon: Star01 },
{ label: 'История сделок', icon: ClockRewind, current: true },
{ label: 'Отчёты пользователей', icon: Users01 },
]
</script>
<template>
<div style="display: flex; block-size: 40rem">
<Sidebar variant="slim" aria-label="Пример меню: полоса">
<SidebarHeader><LayersThree01 /></SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#">
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#" current="section">
<template #leading><BarChartSquare02 /></template>
Панель
</SidebarItem>
<SidebarItem href="#">
<template #leading><Users01 /></template>
Пользователи
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarFooter>
<SidebarSection>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
<Avatar><AvatarFallback>ОР</AvatarFallback></Avatar>
</SidebarFooter>
</Sidebar>
<Sidebar variant="secondary" aria-labelledby="slim-demo-title">
<SidebarHeader>
<SidebarTitle id="slim-demo-title">Панель</SidebarTitle>
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem
v-for="section in sections"
:key="section.label"
href="#"
:current="section.current"
>
<template #leading><component :is="section.icon" /></template>
{{ section.label }}
<template v-if="section.count" #trailing>
<Badge size="sm">{{ section.count }}</Badge>
</template>
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarFooter>
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--prosper-spacing-lg);
"
>
<AvatarLabelGroup size="md">
<Avatar><AvatarFallback>ОР</AvatarFallback></Avatar>
<AvatarLabelGroupName>Олег Рыбаков</AvatarLabelGroupName>
<AvatarLabelGroupDescription>
oleg@example.com
</AvatarLabelGroupDescription>
</AvatarLabelGroup>
<IconButton variant="tertiary" aria-label="Меню аккаунта">
<DotsVertical />
</IconButton>
</div>
</SidebarFooter>
</Sidebar>
</div>
</template>Колонка в конце
side="end" ставит колонку у конца страницы, а граница и подсказки идут с той же стороны.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarItem,
SidebarSection,
} from '@prosper/ui'
import { Settings01 } from '@prosper/ui/icons'
</script>
<template>
<div style="display: flex; justify-content: flex-end; block-size: 20rem">
<Sidebar side="end" variant="panel" aria-label="Пример меню: в конце">
<SidebarHeader>Prosper</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>Главная</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</div>
</template>Сворачивание
SidebarTrigger сворачивает panel или card до полосы значков, а нажатие на группу в свёрнутом меню разворачивает колонку и открывает список группы.
vue
<script setup lang="ts">
import { ref } from 'vue'
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarHeader,
SidebarItem,
SidebarProvider,
SidebarSection,
SidebarTrigger,
} from '@prosper/ui'
import {
BarChartSquare02,
HomeLine,
LayersThree01,
LifeBuoy01,
Settings01,
Users01,
} from '@prosper/ui/icons'
const open = ref(true)
</script>
<template>
<SidebarProvider v-model:open="open" :mobile="false" :shortcut="false">
<div style="display: flex; block-size: 35rem">
<Sidebar variant="panel" aria-label="Пример меню: сворачивание">
<SidebarHeader>
<div class="top" :class="{ rail: !open }">
<a href="#" class="logo" aria-label="Prosper">
<LayersThree01 />
<span v-if="open">Prosper</span>
</a>
<SidebarTrigger />
</div>
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#">
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarGroup default-open>
<template #leading><BarChartSquare02 /></template>
<template #label>Панель</template>
<SidebarItem href="#" current>Заказы</SidebarItem>
<SidebarItem href="#">Сделки</SidebarItem>
</SidebarGroup>
<SidebarItem href="#">
<template #leading><Users01 /></template>
Пользователи
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarFooter>
<SidebarSection>
<SidebarItem href="#">
<template #leading><LifeBuoy01 /></template>
Поддержка
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarFooter>
</Sidebar>
</div>
</SidebarProvider>
</template>
<style scoped>
.top {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--prosper-spacing-md);
}
.rail {
flex-direction: column;
}
.logo {
display: inline-flex;
align-items: center;
gap: var(--prosper-spacing-md);
color: var(--prosper-color-text-primary);
font-weight: var(--prosper-font-weight-semibold);
text-decoration: none;
}
</style>Скрытие за край
collapsible="offcanvas" прячет колонку целиком, а SidebarRail на её краю сворачивает меню кликом.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarItem,
SidebarProvider,
SidebarRail,
SidebarSection,
SidebarTrigger,
} from '@prosper/ui'
import { HomeLine, Folder } from '@prosper/ui/icons'
</script>
<template>
<SidebarProvider :shortcut="false">
<div
style="
display: flex;
align-items: flex-start;
gap: var(--prosper-spacing-lg);
block-size: 20rem;
"
>
<Sidebar
variant="panel"
collapsible="offcanvas"
aria-label="Пример меню: скрытие"
>
<SidebarHeader><strong>Prosper</strong></SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
</SidebarSection>
</SidebarContent>
<SidebarRail />
</Sidebar>
<SidebarTrigger />
</div>
</SidebarProvider>
</template>Управление из кода
useSidebar отдаёт состояние своей кнопке внутри SidebarProvider, а toggle переключает меню.
vue
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import {
Button,
Sidebar,
SidebarContent,
SidebarItem,
SidebarProvider,
SidebarSection,
useSidebar,
} from '@prosper/ui'
import { HomeLine } from '@prosper/ui/icons'
const SidebarToggle = defineComponent({
setup() {
const sidebar = useSidebar()
return () =>
h(
Button,
{ variant: 'secondary', onClick: () => sidebar?.toggle() },
() =>
`Меню: ${sidebar?.state.value === 'expanded' ? 'развёрнуто' : 'свёрнуто'}`,
)
},
})
</script>
<template>
<SidebarProvider>
<div
style="
display: flex;
align-items: flex-start;
gap: var(--prosper-spacing-lg);
block-size: 20rem;
"
>
<Sidebar variant="panel" aria-label="Пример меню: хук">
<SidebarContent>
<SidebarSection>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
<SidebarToggle />
</div>
</SidebarProvider>
</template>Узкий экран
mobile у SidebarProvider задаёт мобильный вид в рамке, а SidebarTrigger открывает шторку с кнопкой закрытия за краем.
vue
<script setup lang="ts">
import {
Sidebar,
SidebarContent,
SidebarHeader,
SidebarHeading,
SidebarItem,
SidebarProvider,
SidebarSection,
SidebarTrigger,
} from '@prosper/ui'
import { Folder, HomeLine, LayersThree01, Settings01 } from '@prosper/ui/icons'
</script>
<template>
<SidebarProvider mobile :shortcut="false">
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
block-size: 3.5rem;
padding-inline: var(--prosper-spacing-lg);
"
>
<strong>Prosper</strong>
<SidebarTrigger />
</div>
<Sidebar variant="panel" aria-label="Пример меню: узкий экран">
<SidebarHeader style="padding: 1rem 1rem 1.25rem">
<a href="#" aria-label="Prosper"><LayersThree01 /></a>
</SidebarHeader>
<SidebarContent>
<SidebarSection>
<SidebarHeading>Общее</SidebarHeading>
<SidebarItem href="#" current>
<template #leading><HomeLine /></template>
Главная
</SidebarItem>
<SidebarItem href="#">
<template #leading><Folder /></template>
Проекты
</SidebarItem>
<SidebarItem href="#">
<template #leading><Settings01 /></template>
Настройки
</SidebarItem>
</SidebarSection>
</SidebarContent>
</Sidebar>
</SidebarProvider>
</template>API
SidebarProvider
Состояние сворачивания: оборачивает раскладку, где Sidebar вида card или panel и кнопка SidebarTrigger, и не рисует своего элемента.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
open | boolean | — | Меню развёрнуто; при v-model:open состоянием владеет потребитель. |
defaultOpen | boolean | true | Развёрнуто ли меню при первом показе, когда open не задан. |
openMobile | boolean | — | Мобильная шторка открыта; при v-model:openMobile состоянием владеет потребитель, а её содержимое создаётся заново при каждом открытии, поэтому открытость SidebarGroup внутри держите через v-model:open. |
defaultOpenMobile | boolean | false | Открыта ли мобильная шторка при первом показе, когда openMobile не задан. |
mobile | boolean | — | Мобильный вид: без значения следует за окном ниже 48rem, true или false задают его принудительно; кнопка SidebarTrigger внутри Sidebar в нём скрыта в шторке, её выносят из Sidebar. |
shortcut | string | false | 'b' | Клавиша, которая вместе с Ctrl или Cmd переключает меню: 'b' по умолчанию, false выключает сочетание. |
События
| Имя | Тип | Описание |
|---|---|---|
update:open | (value: boolean) => void | Меню просит свернуться или развернуться: кнопка SidebarTrigger или щелчок по группе в свёрнутой полосе. |
update:openMobile | (value: boolean) => void | Мобильная шторка просит открыться или закрыться: кнопка SidebarTrigger на мобильном виде. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Раскладка с Sidebar, кнопкой SidebarTrigger и содержимым страницы. |
Sidebar
Корень бокового меню: nav с именем «Основная навигация» высотой контейнера, ширину задаёт variant, шапка вверху, подвал внизу, середина прокручивается.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
variant | 'card' | 'panel' | 'slim' | 'secondary' | 'inset' | 'card' | Вид колонки: card карточка с рамкой, радиусом и тенью, panel граница у содержимого, slim полоса значков с подписями в подсказках, secondary вторая колонка с границей, inset колонка без рамки рядом с SidebarInset. |
side | 'start' | 'end' | 'start' | Сторона страницы: start у начала (по умолчанию) или end у конца, с неё идут граница, подсказки и мобильная шторка. |
collapsible | 'icon' | 'offcanvas' | 'none' | 'icon' | Сворачивание: icon сжимается до полосы значков, offcanvas прячется целиком, none не сворачивается; при none кнопка SidebarTrigger на компьютере только меняет open без сворачивания; slim и secondary не сворачиваются. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Части меню: SidebarHeader, SidebarContent и SidebarFooter. |
SidebarHeader
Шапка меню: колонка с отступом 20 для логотипа и поиска.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Логотип высотой 24 px (SVG с цветом currentColor меняет цвет вместе с темой), поиск и другое содержимое шапки. |
SidebarTitle
Заголовок второй колонки: полужирный текст 14/20 цвета бренда над пунктами, который может называть меню через aria-labelledby.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
as | string | 'h2' | Элемент заголовка, по умолчанию h2. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Текст заголовка. |
SidebarTrigger
Кнопка сворачивания: IconButton со значком панели переключает состояние SidebarProvider и сообщает его через aria-expanded; при collapsible="none" меняет open без сворачивания; в мобильном виде внутри Sidebar она скрыта в шторке, поэтому её выносят из Sidebar.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
label | string | 'Боковое меню' | Доступное имя кнопки, по умолчанию «Боковое меню». |
SidebarContent
Середина меню: занимает свободную высоту и прокручивается, шапка и подвал остаются на месте.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Разделы SidebarSection и разделители SidebarDivider. |
SidebarSection
Раздел меню: список ul, который называет подзаголовок SidebarHeading, если он есть.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Подзаголовок SidebarHeading и пункты SidebarItem. |
SidebarHeading
Подзаголовок раздела: заглавные буквы по стилю, текст остаётся как задан, скринридер читает его как имя списка.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Текст подзаголовка. |
SidebarSectionAction
Кнопка действия раздела: IconButton вида tertiary размера xs в конце строки подзаголовка.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
label | string | — | Доступное имя кнопки, а без него и без aria-label разработчик получает предупреждение. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Иконка кнопки. |
SidebarItem
Пункт меню: элемент списка со ссылкой, атрибуты и класс пункта попадают на ссылку.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
as | string | Component | 'a' | Элемент или компонент ссылки, например RouterLink: to и другие его атрибуты передаются как у обычной ссылки. |
current | boolean | 'section' | false | Текущий пункт: true ставит aria-current="page", 'section' ставит aria-current="true" разделу текущей страницы, а без него остаётся aria-current самой ссылки, например от роутера. |
size | 'sm' | 'md' | 'lg' | 'md' | Высота строки: sm 32 px, md 36 px (строка 38 px с отступами), lg 48 px для двух строк текста; в slim и в свёрнутом меню не действует. |
variant | 'default' | 'outline' | 'default' | Вид строки: default без рамки или outline с рамкой 1 px и тенью; в slim и в свёрнутом меню не действует. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Подпись пункта, в виде slim — простой текст, который виден в подсказке. |
leading | {} | Иконка кита перед подписью, в виде slim обязательна. |
trailing | {} | Содержимое в конце строки, например Badge или иконка внешней ссылки, в виде slim не рисуется. |
action | {} | Кнопка действия SidebarItemAction у конца строки, рядом со ссылкой; в свёрнутом меню и в slim не рисуется. |
SidebarItemAction
Кнопка действия пункта: IconButton вида tertiary размера xs у конца строки, на неё уходят click и остальные атрибуты.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
label | string | — | Доступное имя кнопки, а без него и без aria-label разработчик получает предупреждение. |
reveal | 'always' | 'hover' | 'always' | Когда видна кнопка: always всегда, hover при наведении на пункт, фокусе внутри или открытом меню кнопки. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Иконка кнопки. |
SidebarItemSkeleton
Строка-заглушка пункта на время загрузки: значок и полоса, которые скрыты от скринридера и пульсируют.
Пропсов, событий и слотов нет.
SidebarGroup
Раскрывающаяся группа: элемент списка с кнопкой, которая показывает и прячет вложенный список пунктов.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
open | boolean | — | Группа раскрыта; при v-model:open состоянием владеет потребитель. |
defaultOpen | boolean | false | Группа раскрыта в начале, пока состоянием владеет сам компонент. |
События
| Имя | Тип | Описание |
|---|---|---|
update:open | (value: boolean) => void | Группа просит раскрыться или свернуться: щелчок, Enter или Пробел на кнопке. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
label | {} | Подпись кнопки группы. |
leading | {} | Иконка кита перед подписью. |
trailing | {} | Содержимое в конце строки перед шевроном, например Badge. |
default | {} | Вложенные пункты SidebarItem. |
SidebarDivider
Разделитель между разделами: линия на всю ширину, скрытая от скринридера.
Пропсов, событий и слотов нет.
SidebarFooter
Подвал меню: колонка с промежутком 12 для пунктов и карточки аккаунта.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Раздел SidebarSection с пунктами и карточка аккаунта. |
SidebarCard
Промокарточка в подвале меню: колонка с отступами 16, промежутком 16 и скруглением 12, содержимое которой собирает приложение.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
as | string | 'div' | Элемент корня, по умолчанию div. |
variant | 'fill' | 'outline' | 'fill' | Вид: fill на серой поверхности без рамки или outline на поверхности страницы с рамкой. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Части карточки, прогресс, значок и другие компоненты кита. |
SidebarCardHeading
Колонка заголовка и описания карточки с промежутком 4 px.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | SidebarCardTitle и SidebarCardDescription. |
SidebarCardTitle
Заголовок карточки: полужирный текст 14/20, который не заходит под крестик.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
as | string | 'p' | Элемент заголовка, по умолчанию p, чтобы карточка не попадала в оглавление страницы. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Текст заголовка. |
SidebarCardDescription
Описание карточки: абзац 14/20 приглушённого цвета.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Текст описания. |
SidebarCardActions
Ряд кнопок карточки с промежутком 12 px, который переносится.
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Кнопки карточки. |
SidebarCardClose
Крестик в верхнем углу карточки: кнопка CloseButton размера sm, прямой потомок SidebarCard, на которую уходят click и остальные атрибуты, а убирает карточку приложение.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
label | string | — | Доступное имя кнопки, а без него и без aria-label кнопка называется «Скрыть». |
SidebarRail
Полоска на краю колонки для сворачивания: кнопка без текста, которая переключает меню, её имя «Свернуть меню», в свёрнутом меню «Развернуть меню».
Пропсов, событий и слотов нет.
SidebarInset
Основное содержимое страницы рядом с колонкой inset: скруглённая поверхность с рамкой у начала и сверху, main по умолчанию.
Props
| Имя | Тип | По умолчанию | Описание |
|---|---|---|---|
as | string | 'main' | Элемент части, по умолчанию main, чтобы содержимое страницы было основным регионом. |
Слоты
| Имя | Тип | Описание |
|---|---|---|
default | {} | Содержимое страницы. |
Доступность
| Клавиша | Действие |
|---|---|
| Tab | Переводит фокус на следующий пункт или группу |
| Enter | Открывает ссылку, раскрывает или сворачивает группу |
| Пробел | Раскрывает или сворачивает группу |
| Ctrl+B, Cmd+B | Сворачивает или разворачивает меню, клавишу задаёт shortcut провайдера |
- Корень это
navс именем «Основная навигация»,aria-labelилиaria-labelledbyпотребителя заменяет имя, мобильная шторка это диалог «Меню» с кнопкой «Закрыть меню», а полоскаSidebarRailне входит в порядок Tab. - Раздел это список с именем от подзаголовка через
aria-labelledby, подзаголовок и строкиSidebarItemSkeletonскрыты от скринридера, а кнопка группы держитaria-expandedиaria-controlsна вложенный список. - Текущая страница отмечена
aria-current="page", а её раздел сcurrent="section"—aria-current="true", и оба в режиме принудительных цветов отличаются заливкой системного цвета. - Промокарточка это блок без роли, её заголовок по умолчанию абзац и не попадает в оглавление страницы, а крестик это кнопка с именем «Скрыть», на которую уходят
clickи остальные атрибуты. - Подпись служит именем и видна в подсказке при наведении и фокусе у пунктов в
slimи у пунктов и групп в свёрнутом меню, а кнопка действия называется черезlabelи в полосе не рисуется. - В режиме разработки предупреждают пункт без подписи и без
aria-label, кнопку действия без имени, вторую колонку безaria-labelилиaria-labelledby, а такжеSidebarItemиSidebarGroupвне списка, которые тогда ничего не рисуют.
Настройка
| Переменная | Назначение |
|---|---|
--prosper-sidebar-width | Ширина меню в видах card, panel и inset |
--prosper-sidebar-width-icon | Ширина полосы slim и свёрнутого меню |
--prosper-sidebar-inset-radius | Радиус угла SidebarInset у меню, по умолчанию 0 |