Sidebar

A customizable mobile sidebar component with support for headers, content, footers, and triggers.

Menu

© 2023 Company Inc.

Installation

1. Dependencies

npm install clsx tailwind-merge

2. Paste inside @/lib/utils.ts

import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: Parameters<typeof clsx>) {
  return twMerge(clsx(...inputs));
}

3. Copy Sidebar Code

Loading...

Copy Sidebar Code

Sidebar Props

NameTypeRequiredDefaultDescription
childrenReact.ReactNodeYesundefinedContent to be displayed inside the sidebar.
isOpenbooleanYesfalseControls the visibility of the sidebar.
onClose() => voidYesundefinedCallback function triggered when the sidebar is closed.
position"left" | "right"No"left"Position of the sidebar (left or right).
classNamestringNoundefinedAdditional class names for styling the sidebar container.
overlayClassNamestringNoundefinedClass names for styling the overlay.
widthstringNo"w-64"Width of the sidebar.

SidebarHeader Props

NameTypeRequiredDefaultDescription
childrenReact.ReactNodeYesundefinedContent to be displayed in the sidebar header.
classNamestringNoundefinedAdditional class names for styling the header.

SidebarContent Props

NameTypeRequiredDefaultDescription
childrenReact.ReactNodeYesundefinedContent to be displayed in the sidebar body.
classNamestringNoundefinedAdditional class names for styling the content area.

SidebarFooter Props

NameTypeRequiredDefaultDescription
childrenReact.ReactNodeYesundefinedContent to be displayed in the sidebar footer.
classNamestringNoundefinedAdditional class names for styling the footer.

SidebarTrigger Props

NameTypeRequiredDefaultDescription
onClick() => voidYesundefinedCallback function triggered when the trigger is clicked.
classNamestringNoundefinedAdditional class names for styling the trigger button.
aria-labelstringNo"Toggle Menu"Accessible label for the trigger button.

SidebarClose Props

NameTypeRequiredDefaultDescription
onClick() => voidYesundefinedCallback function triggered when the close button is clicked.
classNamestringNoundefinedAdditional class names for styling the close button.
aria-labelstringNo"Close Menu"Accessible label for the close button.