Skip to main content

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 Link for routing.

Props

PropTypeDescription
showbooleanDetermines the visibility of the sidebar.
toggleDrawer() => voidFunction to toggle sidebar visibility.
DashboardRoutesDashboardRoute[]Array of routes to display in the sidebar.
activestringID of the currently active route.

Types

DashboardRoute

PropertyTypeDescription
idstringUnique identifier for the route.
labelstringDisplay name of the route.
iconReact.ComponentTypeIcon component for the route.
pathstringPath of the route.

Component

SidebarItem

Renders individual items in the 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.0 or higher
  • Next.js for routing with Link
  • Tailwind CSS for styling

Notes

  • Ensure the DashboardRoutes array is properly populated with route objects.
  • Customize the sidebar width and transition effects as per design requirements.
  • The toggleDrawer function should manage the show state 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.