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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mshafiqyajid/react-sidebar

v0.1.0

Published

Collapsible navigation sidebar with nested items, badges, and icon-only mode.

Downloads

56

Readme

@mshafiqyajid/react-sidebar

Collapsible navigation sidebar with nested items, badges, icon-only mode, and full keyboard navigation.

Full docs →

Install

npm install @mshafiqyajid/react-sidebar

Quick start

import { SidebarStyled } from "@mshafiqyajid/react-sidebar/styled";
import "@mshafiqyajid/react-sidebar/styles.css";

const items = [
  {
    label: "Main",
    items: [
      { id: "dashboard", label: "Dashboard", icon: <DashboardIcon /> },
      {
        id: "projects",
        label: "Projects",
        icon: <FolderIcon />,
        children: [
          { id: "active", label: "Active" },
          { id: "archived", label: "Archived" },
        ],
      },
    ],
  },
];

function App() {
  return (
    <SidebarStyled
      items={items}
      activeId="dashboard"
      onItemClick={(id) => console.log("clicked", id)}
    />
  );
}

Variants

<SidebarStyled items={items} variant="bordered" />
<SidebarStyled items={items} variant="filled" />
<SidebarStyled items={items} variant="floating" />

Controlled collapse

const [collapsed, setCollapsed] = useState(false);

<SidebarStyled
  items={items}
  collapsed={collapsed}
  onCollapse={setCollapsed}
/>

Header and footer slots

<SidebarStyled
  items={items}
  header={<Logo />}
  footer={<UserAvatar />}
/>

Headless hook

import { useSidebar } from "@mshafiqyajid/react-sidebar";

function MyNav({ sections }) {
  const { isCollapsed, toggle, getItemProps, isExpanded, toggleSection } =
    useSidebar({ sections, onItemClick: (id) => navigate(id) });

  return (
    <nav data-collapsed={isCollapsed ? "" : undefined}>
      <button onClick={toggle}>Toggle</button>
      {sections.map((section) =>
        section.items.map((item) => (
          <div key={item.id} {...getItemProps(item)}>
            {item.label}
          </div>
        ))
      )}
    </nav>
  );
}

API

SidebarStyled props

| Prop | Type | Default | Description | |---|---|---|---| | items | SidebarSection[] | — | Required. Navigation sections and items. | | collapsed | boolean | — | Controlled collapsed state. | | defaultCollapsed | boolean | false | Initial uncontrolled collapsed state. | | onCollapse | (collapsed: boolean) => void | — | Fires when collapsed state changes. | | showCollapseButton | boolean | true | Show the collapse/expand toggle button. | | variant | "default" \| "bordered" \| "filled" \| "floating" | "default" | Visual variant. | | size | "sm" \| "md" \| "lg" | "md" | Item size. | | activeId | string | — | ID of the currently active item. | | onItemClick | (id: string, item: SidebarItem) => void | — | Fires when a leaf item is clicked. | | header | ReactNode | — | Slot rendered at the top of the sidebar. | | footer | ReactNode | — | Slot rendered at the bottom of the sidebar. | | className | string | — | Additional CSS class on the root <nav>. | | style | CSSProperties | — | Inline style on the root <nav>. | | ref | Ref<HTMLElement> | — | Forwarded to the <nav> element. |

SidebarSection

interface SidebarSection {
  label?: string;         // Optional section heading
  items: SidebarItem[];
}

SidebarItem

interface SidebarItem {
  id: string;
  label: string;
  icon?: ReactNode;
  href?: string;
  active?: boolean;
  disabled?: boolean;
  badge?: ReactNode;
  children?: SidebarItem[];
}

useSidebar return values

| Name | Type | Description | |---|---|---| | isCollapsed | boolean | Whether the sidebar is currently collapsed. | | toggle | () => void | Toggle collapsed state. | | expandedSections | string[] | IDs of currently expanded nested sections. | | isExpanded | (id: string) => boolean | Check if a nested section is expanded. | | toggleSection | (id: string) => void | Expand/collapse a nested section. | | sidebarProps | object | Spread onto the <nav> element. | | getItemProps | (item: SidebarItem) => object | Spread onto each item element. | | getSectionProps | (sectionId, label?) => object | Spread onto nested <ul> elements. |

Keyboard navigation

| Key | Action | |---|---| | / | Move focus between visible items | | | Expand a collapsed nested section / focus first child | | | Collapse an expanded section / focus parent | | Enter / Space | Activate item or toggle nested section |

CSS variables

| Variable | Default | Description | |---|---|---| | --rsb-bg | #ffffff | Sidebar background | | --rsb-fg | #18181b | Text color | | --rsb-accent | #6366f1 | Accent / active color | | --rsb-width-sm | 200px | Width at size="sm" | | --rsb-width-md | 240px | Width at size="md" | | --rsb-width-lg | 280px | Width at size="lg" | | --rsb-collapsed-width | 56px | Width when collapsed | | --rsb-duration-width | 250ms | Collapse animation duration |

Dark mode is applied via a [data-theme="dark"] ancestor.

License

MIT