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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@suprasmooth/react-nested-dropdown

v0.2.2

Published

A simple react nested dropdown component

Downloads

10

Readme

react-nested-dropdown

License npm bundle size npm

Create advanced nested dropdowns with React and TypeScript.
Customize the look to your own needs using the different component props.

Example (The screenshot shows custom applied styles)

Usage

Install the package using NPM:

npm install @suprasmooth/react-nested-dropdown

Import the package and the styles into your React app.
The styles are scoped and should not be conflicting with your own styles.

import { NestedDropdown } from '@suprasmooth/react-nested-dropdown';

import '@suprasmooth/react-nested-dropdown/dist/style.css';

Properties and Settings

The NestedDropdown component receives a menu prop wich is an array of items typed as MenuItem.

export type MenuItem = {
 key: Key; // used for rendering menu items
 type?: MenuItemType; // see MenuItemType enum for possible values
 prefixedComponent?: JSX.Element | string; // component to include in font of the menu item
 label?: JSX.Element | string; // the label for the menu item itself
 suffixedComponent?: JSX.Element | string; // component to include after the menu item
 className?: string; // add additional classes here
 tooltip?: string; // basic html tooltip for the menu item
 href?: string; // link to an external page
 isDisabled?: boolean; // disable the menu item
 onClick?: () => void; // called when the menu item is clicked
 children?: MenuItem[]; // also known as the submenu items
};

Play with the different properties to get the output you want. There are almost no restrictions.

There is no limit on how many children you can pass to the NestedDropdown component.

Tailwindcss Preflight

You can rename the .env.skel file to control tailwindcss's preflight functionality. This will add css resets to the development process and helps you to avoid unnecessary styles and overrides.

We assume that every developer has some kind of "CSS Reset" in their own project. We try to set as little styles, overrides and classes as possible.

Example

You can pass your own children element to the NestedDropdown component or you can use the NestedDropdownButton component as the dropdown trigger element, as seen in the following example.

import {
    NestedDropdown,
    MenuItemType,
    NestedDropdownStructure,
    NestedDropdownButton
} from '@suprasmooth/react-nested-dropdown';

import '@suprasmooth/react-nested-dropdown/dist/style.css';

const DropdownMenu = return(
    <NestedDropdown
    menu={
     [
      {
       key: '0',
       label: 'Link 1',
       className: 'px-3 py-1',
       suffixedComponent: <span>&nbsp;{'>'}&nbsp;</span>,
       children: [
        {
         key: '0-1',
         label: 'Link 1-1',
         className: 'px-3 py-1',
        },
       ],
      },
      {
       key: '1',
       type: MenuItemType.Separator,
      },
      {
       key: '2',
       label: 'Link 2',
       className: 'px-3 py-1',
       prefixedComponent: <span>Prefix:&nbsp;</span>,
       children: [
        {
         key: '2-0',
         label: 'Link 2-1',
         className: 'px-3 py-1',
        },
        {
         key: '2-1',
         type: MenuItemType.Separator,
        },
        {
         key: '2-2',
         type: MenuItemType.Label,
         label: (
          <span className="font-bold">
           Headline
          </span>
         ),
         className: 'px-3 py-1',
        },
        {
         key: '2-3',
         label: 'Link 2-2',
         className: 'px-3 py-1',
         children: [
          {
           key: '3',
           label: 'Link 3-1',
           className: 'px-3 py-1',
          },
         ],
        },
       ],
      },
     ] as NestedDropdownStructure
    }
   >
    <NestedDropdownButton
     className="px-3 py-1"
     additionalStyles={{ backgroundColor: 'red' }}
    >
     Dropdown
    </NestedDropdownButton>
   </NestedDropdown>
);