Skip to main content

Sidebar

The Sidebar component is a responsive navigation container that adapts between desktop and mobile layouts. It is composed of smaller modular components (SidebarDesktop, SidebarMobile, SidebarBase, SidebarItem) and can be customized with logos, items, and variants.

import { Sidebar } from "tawuniya/components";

Getting Started​

⚠️ This component requires wrapping your app with MainProvider

import { MainProvider } from "tawuniya";

export default function AppLayout({ children }) {
return <MainProvider>{children}</MainProvider>;
}

👉 View in Storybook


Props​

PropTypeDefaultDescription
itemsSidebarItem[][]List of navigation items.
logo{ expanded?: ReactNode; collapsed?: ReactNode }-Logo displayed in expanded/collapsed state.
itemVariantsPartial<ButtonProps>-Variants applied to all sidebar items.
activeVariantsPartial<Pick<ButtonProps, "variant" | "className">>-Variants applied to active sidebar items.
breakpointnumber-Screen width breakpoint to switch to mobile mode.
linkComponentReact.ElementType"a"Custom link component (e.g., NextLink).
defaultCollapsedboolean-Initial collapsed state (desktop only).
footerReactNode-Footer content to be displayed.
headerReactNode-Header content to be displayed.
showFooterWhenCollapsedbooleanfalseWhether to show footer when collapsed.
showHeaderWhenCollapsedbooleanfalseWhether to show header when collapsed.
classNamestring-Class name for the sidebar.
privilegesstring[]-Privileges to filter items.

Each sidebar item is defined as:

interface SidebarItem {
id: string;
href: string;
label: string;
icon: IconName | string;
isLocatedAtEnd?: boolean; // item displayed at the bottom
active?: boolean;
}

Usage​

Basic Example​

<Sidebar
defaultCollapsed={false}
items={[
{
id: "1",
href: "/dashboard",
label: "Dashboard",
icon: "home",
active: true,
},
{ id: "2", href: "/settings", label: "Settings", icon: "settings" },
{ id: "3", href: "/logout", label: "Logout", icon: "log-out", isLocatedAtEnd: true },
]}
/>
<Sidebar
logo={{
expanded: <img src="/logo-full.svg" alt="Logo" />,
collapsed: <img src="/logo-small.svg" alt="Logo" />,
}}
items={menuItems}
/>

With Custom Variants​

<Sidebar
items={menuItems}
itemVariants={{
size: "lg",
variant: "smooth",
}}
/>
import Link from "next/link";

export function Example() {
return (
<Sidebar
linkComponent={Link}
items={[{ id: "1", href: "/profile", label: "Profile", icon: "user" }]}
/>
);
}
import { Link } from "react-router-dom";

export function Example() {
return (
<Sidebar
linkComponent={Link}
items={[{ id: "1", href: "/profile", label: "Profile", icon: "user" }]}
/>
);
}

With Privileges​

<Sidebar
items={[
{
id: "1",
href: "/dashboard",
label: "Dashboard",
icon: "home",
active: true,
allowedPrivileges: ["pr-1"],
},
{
id: "2",
href: "/settings",
label: "Settings",
icon: "settings",
allowedPrivileges: ["pr-2"],
},
{ id: "3", href: "/logout", label: "Logout", icon: "log-out", isLocatedAtEnd: true },
]}
privileges={["pr-1", "pr-2"]}
/>
<Sidebar items={menuItems} header={<h2>Header</h2>} footer={<h2>Footer</h2>} />

Features​

  • Responsive: Switches between desktop sidebar and mobile drawer (Sheet).
  • Collapsible: Supports collapsed and expanded states on desktop.
  • Customizable Logo: Change logo for collapsed/expanded states.
  • Flexible Items: Supports top and end items ( isLocatedAtEnd).
  • RTL Support: Works with Arabic/English layouts.
  • Context-Driven: Uses MainContext for state management (open/collapsed).

Notes​

  • When collapsed, items show only icons with tooltips.
  • When isMobile, the sidebar becomes a drawer (Sheet) with full-width items.
  • End items ( isLocatedAtEnd=true) are rendered at the bottom (e.g., Logout button).
  • Works seamlessly with RTL (useLanguage hook) → automatically switches side.