Skip to main content
Version: 1.0.3

Sidebar

The Sidebar component is a versatile and animated navigation element that provides an elegant way to organize navigation links and actions in your application. It supports multiple positions, variants, and animations built with Framer Motion.

Demo Window

Installation

ignix add component sidebar

Usage

Basic Usage

The Sidebar must always be wrapped inside a SidebarProvider to manage its open/close state.

import { Sidebar, SidebarProvider } from '@ignix-ui/sidebar';
import { HomeIcon, GearIcon, PersonIcon, EnvelopeClosedIcon, QuestionMarkCircledIcon } from '@radix-ui/react-icons';

function BasicSidebar() {
const links = [
{ label: 'Home', href: '/', icon: HomeIcon },
{ label: 'Profile', href: '/profile', icon: PersonIcon },
{ label: 'Settings', href: '/settings', icon: GearIcon },
{ label: 'Contact', href: '/contact', icon: EnvelopeClosedIcon },
];

return (
<SidebarProvider>
<Sidebar
links={links}
brandName="My App"
/>
</SidebarProvider>
);
}

Customization

import { Sidebar, SidebarProvider } from '@ignix-ui/sidebar';
import { HomeIcon, GearIcon} from '@radix-ui/react-icons';

function CustomStyledSidebar() {
const links = [
{ label: 'Home', href: '/', icon: HomeIcon },
{ label: 'Settings', href: '/settings', icon: GearIcon },
];

return (
<SidebarProvider>
<Sidebar
links={links}
brandName="Custom Links"
className="[&_a]:hover:bg-blue-500 [&_a]:transition-colors"
/>
</SidebarProvider>
);
}

Responsive Sidebar

Create a responsive sidebar that adapts to different screen sizes:

import { Sidebar, SidebarProvider } from '@ignix-ui/sidebar';
import { useState, useEffect } from 'react';

function ResponsiveSidebar() {
const [isOpen, setIsOpen] = useState(true);

useEffect(() => {
const handleResize = () => {
setIsOpen(window.innerWidth > 768);
};

window.addEventListener('resize', handleResize);
handleResize();

return () => window.removeEventListener('resize', handleResize);
}, []);

return (
<SidebarProvider>
<Sidebar
links={links}
isOpen={isOpen}
onClose={() => setIsOpen(false)}
className="md:relative absolute"
/>
</SidebarProvider>
);
}

Props

PropTypeDefaultDescription
links{ label: string; href: string; icon: React.ElementType }[]requiredArray of navigation items displayed in the sidebar
brandNamestring"Brand"Text displayed in the sidebar header
position'left' | 'right' | 'bottomLeft' | 'bottomRight''left'Determines where the sidebar appears on the screen
mobileBreakPointnumber768Width breakpoint for mobile devices
variant'default' | 'dark' | 'light' | 'glass' | 'gradient''default'Visual style of the sidebar
direction'vertical' | 'horizontal''vertical'Layout direction of the navigation links
classNamestringundefinedAdditional Tailwind classes applied to the sidebar container
All HTMLDivElement propsReact.HTMLAttributes<HTMLDivElement>-Supports all standard div attributes (e.g., style, id, onClick)