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

react-animated-menu

v1.0.0

Published

A React component that handles all logic for managing visual state for menus and lists.

Downloads

3

Readme

Introduction

You want to build a sidebar for your app's dashboard — maybe create a table of contents for your documentation page. When you click on a link in the sidebar you want to expand the contents.

You also want to use a simple plug and play API that controls the opening/closing of menus items, lets you control the ease and duration of the menu animation, and allows you flexibility to build your UI however you'd like.

This approach

react-animated-menu manages all menu state and user interactions for you so you can simply focus on building your UI.

It uses a single compound component paired with a render prop to provide maximum flexibility, exposing only props that are valuable for you.

NOTE: This solution transforms the menu's height property. Typically we should be animating CSS transforms; however, in this particular case, using plain Javascript to transition height is a lot simpler.

Installation

Install this module as a dependency using npm or yarn

npm install --save react-animated-menu

or

yarn add -D react-animated-menu

Usage

There are 2 components that this module provides - simply use them like this:

import DynamicMenu, { MenuItem } from 'react-animated-menu'

export default function Menu() {
  return (
    <aside>
      {/* Wrap the menu in a Higher Ordered Component */}
      <DynamicMenu
        initialOpenIndex={0}
        easeDuration={150}
        numberOfMenusThatCanBeOpenedAtOnce={1}
      >
      
        {/* Each menu toggler and the menu list content must be wrapped by a MenuItem
            render prop - and spreading the prop getters to their respective sections. */}
        <MenuItem>
          {({ isOpen, getToggleProps, getMenuProps, getLinkProps }) => (
            <>
              <button {...getToggleProps()} isOpen={isOpen}>
                Dashboard
              </button>
              <ul {...getMenuProps()}>
                {dashboardPaths.map(p => (
                  <li key={p.route}>
                    <Link to={`/${p.route}/`} {...getLinkProps()}>
                      {p.name}
                    </Link>
                  </li>
                ))}
              </ul>              
            </>
          )}
        </MenuItem>
        
        {/* Same as above MenuItem! */}
        <MenuItem>
          {({ isOpen, getToggleProps, getMenuProps, getLinkProps }) => (
            <>
              <button {...getToggleProps()} isOpen={isOpen}>
                Settings
              </button>
              <ul {...getMenuProps()}>
                {settingPaths.map(p => (
                  <li key={p.route}>
                    <Link to={`/${p.route}/`} {...getLinkProps()}>
                      {p.name}
                    </Link>
                  </li>
                ))}
              </ul>              
            </>
          )}
        </MenuItem>
      </DynamicMenu>
    </aside>
  )
}

Basic Props

children

The nested child elements.

initialOpenIndex

number | number[] - defaults to -1 (all menu items closed)

The initial MenuItem that should be open.

numberOfMenusThatCanBeOpenedAtOnce

number - defaults to 1

The number of menus that can be opened at once. 😀

easeFn

(t: number) => number

An easing function - see https://gist.github.com/gre/1650294 for a list of options.

easeDuration

number - defaults to 150 (ms)

Duration of the menu transition.

License

MIT