Documentation / Layout
Sidebar
An application’s collapsible navigation sidebar, composed of sub-components: SidebarHeader, SidebarContent, SidebarGroup (a titled section), SidebarItem (a link or a button), SidebarSubMenu (an expandable entry), SidebarFooter and SidebarToggle. default, bordered and floating variants, on the left or the right.
Collapsed, it keeps only the icons, and each label moves into a tooltip on hover. The collapsed state is controlled or not (defaultCollapsed). Below mobileBreakpoint (768 px by default), it becomes a modal drawer with the full dialog accessibility contract; when closed, it is inert and leaves the tab order. The component is marked "use client".
The sub-components and the useSidebar() hook read the sidebar’s context: they must be rendered inside <Sidebar>.
Examples
Basic usage
A header with the collapse button, groups of entries and a footer.
import { type ReactNode } from "react";
import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader, SidebarItem, SidebarToggle } from "@synertech/ui";
const Frame = ({ children }: { children: ReactNode }) => (
<div className="flex h-96 border border-gray-200 dark:border-gray-700">{children}</div>
);
const Icon = ({ d }: { d: string }) => (
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d={d} />
</svg>
);
const HomeIcon = () => <Icon d="M3 12l9-9 9 9M5 10v10h14V10" />;
const FolderIcon = () => (
<Icon d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
);
const ChartIcon = () => <Icon d="M4 20V10M10 20V4M16 20v-6M22 20H2" />;
export function Basic() {
return (
<Frame>
<Sidebar variant="bordered">
<SidebarHeader>
<span className="flex-1 font-bold">Synertech</span>
<SidebarToggle />
</SidebarHeader>
<SidebarContent>
<SidebarGroup label="Général">
<SidebarItem icon={<HomeIcon />} label="Accueil" href="/" active />
<SidebarItem icon={<FolderIcon />} label="Projets" href="/projets" badge={4} />
<SidebarItem icon={<ChartIcon />} label="Rapports" href="/rapports" disabled />
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<span className="text-xs text-gray-500">Version 2.4</span>
</SidebarFooter>
</Sidebar>
<main className="flex-1 p-6">Contenu de la page</main>
</Frame>
);
}Controlled collapsing
collapsed and onCollapsedChange let the application drive and remember the state; collapsedWidth sets the reduced width.
import { useState, type ReactNode } from "react";
import { Button, Sidebar, SidebarContent, SidebarGroup, SidebarItem } from "@synertech/ui";
const Frame = ({ children }: { children: ReactNode }) => (
<div className="flex h-96 border border-gray-200 dark:border-gray-700">{children}</div>
);
const Icon = ({ d }: { d: string }) => (
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d={d} />
</svg>
);
const HomeIcon = () => <Icon d="M3 12l9-9 9 9M5 10v10h14V10" />;
const ChartIcon = () => <Icon d="M4 20V10M10 20V4M16 20v-6M22 20H2" />;
export function Controlled() {
const [collapsed, setCollapsed] = useState(true);
return (
<div className="space-y-3">
<Button size="sm" onClick={() => setCollapsed(!collapsed)}>
{collapsed ? "Déplier" : "Replier"} la barre
</Button>
<Frame>
<Sidebar collapsed={collapsed} onCollapsedChange={setCollapsed} collapsedWidth={72}>
<SidebarContent>
<SidebarGroup label="Navigation">
<SidebarItem icon={<HomeIcon />} label="Accueil" active />
<SidebarItem
icon={<ChartIcon />}
label="Statistiques"
tooltip="Statistiques du mois"
/>
</SidebarGroup>
</SidebarContent>
</Sidebar>
</Frame>
</div>
);
}Mobile drawer
Below the breakpoint, the button that opens the sidebar lives outside it: control mobileOpen from the page’s header bar.
import { useState } from "react";
import { Button, Sidebar, SidebarContent, SidebarHeader, SidebarItem } from "@synertech/ui";
const Icon = ({ d }: { d: string }) => (
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d={d} />
</svg>
);
const HomeIcon = () => <Icon d="M3 12l9-9 9 9M5 10v10h14V10" />;
const FolderIcon = () => (
<Icon d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z" />
);
export function Mobile() {
const [mobileOpen, setMobileOpen] = useState(false);
return (
<div>
<Button size="sm" className="md:hidden" onClick={() => setMobileOpen(true)}>
Menu
</Button>
<Sidebar
mobileOpen={mobileOpen}
onMobileOpenChange={setMobileOpen}
aria-label="Navigation principale"
>
<SidebarHeader>
<span className="font-bold">Synertech</span>
</SidebarHeader>
<SidebarContent>
<SidebarItem icon={<HomeIcon />} label="Accueil" href="/" />
<SidebarItem icon={<FolderIcon />} label="Projets" href="/projets" />
</SidebarContent>
</Sidebar>
</div>
);
}Reading the state with useSidebar
A component rendered inside the sidebar adapts its display to the collapsed state.
import { type ReactNode } from "react";
import { Avatar, Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarItem, SidebarToggle, useSidebar } from "@synertech/ui";
const Frame = ({ children }: { children: ReactNode }) => (
<div className="flex h-96 border border-gray-200 dark:border-gray-700">{children}</div>
);
const Icon = ({ d }: { d: string }) => (
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" d={d} />
</svg>
);
const HomeIcon = () => <Icon d="M3 12l9-9 9 9M5 10v10h14V10" />;
function UserCard() {
const { collapsed } = useSidebar();
return (
<div className="flex items-center gap-3">
<Avatar fallback="CM" size="sm" />
{!collapsed && <span className="truncate text-sm">Claire Martin</span>}
</div>
);
}
export function WithHook() {
return (
<Frame>
<main className="flex-1 p-6">Contenu de la page</main>
<Sidebar position="right" variant="bordered" defaultCollapsed>
<SidebarHeader>
<SidebarToggle />
</SidebarHeader>
<SidebarContent>
<SidebarItem icon={<HomeIcon />} label="Accueil" />
</SidebarContent>
<SidebarFooter>
<UserCard />
</SidebarFooter>
</Sidebar>
</Frame>
);
}API reference
Components
import { Sidebar } from "@synertech/ui";Props — SidebarProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
aria-label |
string |
— | Accessible name of the mobile drawer. Defaults to the |
className |
string |
— | Additional class names |
closeLabel |
string |
— | Accessible name of the mobile close button. Defaults to the |
collapsed |
boolean |
— | Controlled collapsed state |
collapsedWidth |
number |
64 |
Width when collapsed (px) |
defaultCollapsed |
boolean |
false |
Default collapsed state (uncontrolled) |
expandedWidth |
number |
260 |
Width when expanded (px) |
initialFocus |
DialogInitialFocus |
— | Element focused when the mobile drawer opens. Default |
linkComponent |
UILinkComponent |
— | The link of the application's router ( |
lockScroll |
boolean |
true |
Prevent the page behind the mobile drawer from scrolling. Default |
mobileBreakpoint |
number |
768 |
Breakpoint for mobile drawer mode (px) |
mobileOpen |
boolean |
— | Controlled mobile open state |
onCollapsedChange |
(collapsed: boolean) => void |
— | Collapse change callback |
onMobileOpenChange |
(open: boolean) => void |
— | Mobile open change callback |
position |
SidebarPosition |
"left" |
Sidebar position |
returnFocus |
DialogReturnFocus |
— | Element focused when the mobile drawer closes. Default |
trapFocus |
boolean |
true |
Keep Tab / Shift+Tab inside the mobile drawer. Default |
variant |
SidebarVariant |
"default" |
Visual variant |
import { SidebarContent } from "@synertech/ui";Props — SidebarContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | Additional class names |
import { SidebarFooter } from "@synertech/ui";Props — SidebarFooterProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | Additional class names |
import { SidebarGroup } from "@synertech/ui";Props — SidebarGroupProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | Additional class names |
label |
string |
— | Group label (hidden when collapsed) |
import { SidebarHeader } from "@synertech/ui";Props — SidebarHeaderProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | Additional class names |
import { SidebarItem } from "@synertech/ui";Props — SidebarItemProps
| Prop | Type | Default | Description |
|---|---|---|---|
label• |
string |
— | Item label |
active |
boolean |
false |
Active/selected state |
badge |
ReactNode |
— | Badge content (number, string, or ReactNode) |
badgeColor |
string |
"bg-synertech-primary-600 text-synertech-on-primary" |
Badge color |
className |
string |
— | Additional class names |
disabled |
boolean |
false |
Disabled state |
href |
string |
— | Where the item leads, rendered as a link: the |
icon |
ReactNode |
— | Icon element (always visible) |
onClick |
(event: MouseEvent<HTMLElement>) => void |
— | Called on a click, with its event: |
tooltip |
string |
— | Tooltip text (shown in collapsed mode, defaults to label) |
import { SidebarSubMenu } from "@synertech/ui";Props — SidebarSubMenuProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
label• |
string |
— | Submenu label |
badge |
ReactNode |
— | Badge on the submenu trigger |
className |
string |
— | Additional class names |
defaultOpen |
boolean |
false |
Default open state |
icon |
ReactNode |
— | Icon for the submenu trigger |
import { SidebarToggle } from "@synertech/ui";Props — SidebarToggleProps
| Prop | Type | Default | Description |
|---|---|---|---|
className |
string |
— | Additional class names |
Hooks
Hook to access sidebar state from outside the component tree
import { useSidebar } from "@synertech/ui";useSidebar(): SidebarContextValueTypes
SidebarPosition
Typetype SidebarPosition = "left" | "right"SidebarVariant
Typetype SidebarVariant = "default" | "bordered" | "floating"