Synertech Web/ui v0.57.5 Site Storybook

Documentation / Layout

Sidebar

Client@synertech/uiOpen in Storybook

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.

Open in a tab
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>
  );
}

Submenus

SidebarSubMenu expands its entries; when collapsed, the sidebar reopens on click to show them.

Open in a tab
import { useState, type ReactNode } from "react";
import { Sidebar, SidebarContent, SidebarItem, SidebarSubMenu } 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" />
);

export function SubMenus() {
  const [current, setCurrent] = useState("Clients");

  return (
    <Frame>
      <Sidebar variant="floating" expandedWidth={240}>
        <SidebarContent>
          <SidebarItem
            icon={<HomeIcon />}
            label="Accueil"
            onClick={() => setCurrent("Accueil")}
            active={current === "Accueil"}
          />
          <SidebarSubMenu icon={<FolderIcon />} label="Ventes" defaultOpen>
            {["Clients", "Devis", "Factures"].map((page) => (
              <SidebarItem
                key={page}
                label={page}
                active={current === page}
                onClick={() => setCurrent(page)}
              />
            ))}
          </SidebarSubMenu>
        </SidebarContent>
      </Sidebar>
      <main className="flex-1 p-6">Page : {current}</main>
    </Frame>
  );
}

Controlled collapsing

collapsed and onCollapsedChange let the application drive and remember the state; collapsedWidth sets the reduced width.

Open in a tab
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.

Open in a tab
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.

Open in a tab
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

ComponentClient
import { Sidebar } from "@synertech/ui";

Props — SidebarProps

PropTypeDefaultDescription

SidebarContent

ComponentClient
import { SidebarContent } from "@synertech/ui";

Props — SidebarContentProps

PropTypeDefaultDescription
children• ReactNode —
className string —

Additional class names

SidebarFooter

ComponentClient
import { SidebarFooter } from "@synertech/ui";

Props — SidebarFooterProps

PropTypeDefaultDescription
children• ReactNode —
className string —

Additional class names

SidebarGroup

ComponentClient
import { SidebarGroup } from "@synertech/ui";

Props — SidebarGroupProps

PropTypeDefaultDescription
children• ReactNode —
className string —

Additional class names

label string —

Group label (hidden when collapsed)

SidebarHeader

ComponentClient
import { SidebarHeader } from "@synertech/ui";

Props — SidebarHeaderProps

PropTypeDefaultDescription
children• ReactNode —
className string —

Additional class names

SidebarItem

ComponentClient
import { SidebarItem } from "@synertech/ui";

Props — SidebarItemProps

PropTypeDefaultDescription
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 linkComponent of the sidebar or of UILabelsProvider, an <a> without one. Any other address than an http:, https:, mailto:, tel: or relative one (javascript:…) leaves it a button, and the console says so once.

icon ReactNode —

Icon element (always visible)

onClick (event: MouseEvent<HTMLElement>) => void —

Called on a click, with its event: event.preventDefault() keeps a link from being followed. The mobile drawer closes all the same.

tooltip string —

Tooltip text (shown in collapsed mode, defaults to label)

SidebarSubMenu

ComponentClient
import { SidebarSubMenu } from "@synertech/ui";

Props — SidebarSubMenuProps

PropTypeDefaultDescription
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

SidebarToggle

ComponentClient
import { SidebarToggle } from "@synertech/ui";

Props — SidebarToggleProps

PropTypeDefaultDescription
className string —

Additional class names

Hooks

useSidebar

HookClient

Hook to access sidebar state from outside the component tree

import { useSidebar } from "@synertech/ui";
useSidebar(): SidebarContextValue

Types

type SidebarPosition = "left" | "right"
type SidebarVariant = "default" | "bordered" | "floating"