Sidebar Component
The Sidebar component in React is designed for creating a navigational sidebar with links to different routes. It's suitable for dashboards or applications with multiple navigation paths.
Features
- Togglable sidebar visibility.
- Dynamic rendering of navigation items based on provided routes.
- Highlights the active route.
- Uses Next.js
Linkfor routing.
Props
| Prop | Type | Description |
|---|---|---|
show | boolean | Determines the visibility of the sidebar. |
toggleDrawer | () => void | Function to toggle sidebar visibility. |
DashboardRoutes | DashboardRoute[] | Array of routes to display in the sidebar. |
active | string | ID of the currently active route. |
Types
DashboardRoute
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier for the route. |
label | string | Display name of the route. |
icon | React.ComponentType | Icon component for the route. |
path | string | Path of the route. |
Component
SidebarItem
Renders individual items in the sidebar.
Sidebar
The main component rendering the sidebar with navigational items.
import React from "react";
import classNames from "classnames";
import Link from "next/link";
// ... Component code
export default Sidebar;
Usage
Used in dashboard layouts or applications requiring a sidebar for navigation between different sections or pages.
Styling
Styled using Tailwind CSS, it offers a modern and responsive design. The component's appearance can be customized by altering the Tailwind classes.
Dependencies
- React
^17.0.0or higher - Next.js for routing with
Link - Tailwind CSS for styling
Notes
- Ensure the
DashboardRoutesarray is properly populated with route objects. - Customize the sidebar width and transition effects as per design requirements.
- The
toggleDrawerfunction should manage theshowstate to control the sidebar's visibility.
This documentation provides an overview of the Sidebar component, including its features, props, types, and usage. Adapt the implementation and styling according to your project's needs.