npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-dynamic-snbar

v1.2.0

Published

Responsive React sidebar with role-based navigation support and easy customization.

Readme

SNBar

Demo

SNBar Items Structure

The sidebar navigation items are defined as an array of objects, each representing a menu item or a category with optional nested children. Each object has the following structure:

const sideBarItems = [
  {
    category: "Navigation",       // Category under which the item is grouped
    label: "Dashboard",           // Text label for the navigation item
    path: "/dashboard",           // Route path (optional if there are children)
    icon: <FaHome />,             // icon (use react icons)
    roles: ["Admin"],             // Array of roles allowed to see this item
  },
  {
    category: "Navigation",
    label: "User Management",
    icon: <FaUsers />,
    roles: ["Admin"],
    children: [                   // Optional nested dropdown items
      { 
        label: "All Users", 
        path: "/users", 
        icon: <FaUsers /> 
      },
      { 
        label: "Settings", 
        path: "/settings", 
        icon: <FaCog /> 
      },
    ],
  },
  {
    category: "Help & Support",
    label: "Help Center",
    path: "/help",
    icon: <FaLifeRing />,
    roles: ["Admin", "User"],
  },
  // More items here...
];

Usage of SNBar Component

Use the SNBar sidebar component inside a React Router <BrowserRouter> to enable routing.

import { BrowserRouter , Routes , Route } from "react-router-dom";
import { Sidebar as SNBar } from "react-dynamic-snbar";
import 'react-dynamic-snbar/dist/index.css';
import image1 from "/image1.png"; 

function App() {
const sideBarItems = [
  {
    category: "Navigation",       
    label: "Dashboard",  
    path: "/dashboard", 
    icon: <FaHome />,   
    roles: ["Admin"],  
  },
  //add more items...
  ]

  const [maxWidth , setMaxWidth] = useState<boolean>(true) //Important 
  console.log(maxWidth); 
  
  //All these values can be dynamic
  const title = "SNBar"; 
  const role= "Admin"; 
  const font= "cursive";
  const bg = "white";
  const color = "black";
  const categoryColor = "gray";
  const activeBg = "black";
  const activeColor = "white";
  const toggleBtn = true;    

 
  return (
    <BrowserRouter>
      <SNBar
        navItems={sideBarItems}
        logo={image1}
        title={title} 
        role={role}
        fontFamily={font}
        backgroundColor={bg}
        color={color}
        categoryColor={categoryColor}
        activeBg={activeBg}
        activeColor={activeColor}
        toggleBtn={toggleBtn}
        setMaxWidth={setMaxWidth}
      />
      <Routes>
        <Route path='/' element={<Dashboard />} />
        <Route path='/dashboard' element={<Dashboard />} /> //your pages/routes...
      </Routes> 
    </BrowserRouter>
  );
}

Usage

Sidebar Configuration Props

| Prop | Type | Description | |------------------|-----------------|---------------------------------------------| | navItems | NavItem[] | Array of navigation items with labels, paths, icons, roles, and optional children dropdowns | | logo | string | URL or import path of the logo image | | title | string | Sidebar title text | | role | string | Current user role (e.g., "Admin", "User") | | setMaxWidth | boolean(opt.) | Indicates whether the sidebar is open (true) or closed (false). Useful for adjusting the width of UI components accordingly. | | fontFamily | string (opt.) | Font family for sidebar text | | backgroundColor| string (opt.) | Background color of the sidebar | | color | string (opt.) | Text color | | categoryColor | string (opt.) | Color for category headings | | activeBg | string (opt.) | Background color for active nav item | | activeColor | string (opt.) | Text color for active nav item | | toggleBtn | boolean (opt.)| To hide open/close Sidebar toggleBTN {not for mobile screens.} |

---> Note1 :

If you face difficulty managing the width of UI components when the sidebar opens or closes (especially due to z-index issues), use the setMaxWidth prop. This prop returns true when the sidebar is open and false when it's closed. Based on this state, you can dynamically adjust the size of the UI or its components. Best Practice: Wrap each page or its components inside a single parent container and control the container’s width based on the setMaxWidth state. If you're still facing difficulty adjusting the UI, you can use the toggleBtn prop. Set toggleBtn to false, and the sidebar will remain fixed (i.e., users won’t be able to close it). This can help maintain consistent layout and avoid dynamic width changes.

---> Note2 :

This component is designed specifically for React applications and does not support Next.js out of the box.
It provides easy role-based user access for routing through the role prop, but it does not include built-in protected route functionality. You will need to implement protected routes yourself in your code to control access to certain pages.


Contact

If you have any questions or want to connect, feel free to reach out to me:

Md Fardeen