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-app-menu

v1.0.11

Published

a tiny react component to build desktop like menu with keyboard navigation and hotkeys support

Downloads

1,045

Readme

react-app-menu

A simple desktop like menu bar with hotkey and keyboard navigation

BuildStatus Dependencies CodeCoverage Maintainability

Introduction

React App Menu is a simple React component that renders navigation menu similar to desktop applications with support for hotkeys and keyboard navigation. It aims to do most things through css alone and relies on javascript only when absolutely necessary. This makes the code extremely small (< 20kb) and together with the css, the whole library is less than 25 kb without any compression

Installation

npm install react-app-menu

Demo

react-app-menu-demo

Browser Support

This component relies on the css pseudo selector focus-within to open menus. This should work on Chrome and Firefox out of the box. For browsers that don't support the focus-within pseduo selector (notably IE and version of Edge prior to Edge 79), you will need to include a small polyfill focus-within-polyfill. The demo above is using Edge with the polyfill

To use the polyfill, you can either

  1. Include the following script tag <script src='https://unpkg.com/focus-within-polyfill/dist/focus-within-polyfill.js'></script>
  2. Install and import the focus-within-polyfill

This polyfill will only kick in for browsers that don't support the focus-within polyfill and adds a listener for blur and focus events and adds a .focus-within class as necessary.

Usage

Simply import MenuBar and Menu and start composing your menu. A css is also provided in dist/styles/react-app-menu.css. Be sure to import the css

Customizing the themes

In order to customize the look of the menu, certain css variables are provided that you can override on your menu

| Prop | Description | | ---------------- | --------------------- | --reactAppMenu-color-bg | Background color of menu --reactAppMenu-color-text | Text color of menu --reactAppMenu-color-bg-hover | Background color of menu when hovered --reactAppMenu-color-text-hover | Text color of menu when hovered --reactAppMenu-color-bg-focus | Background color of menu when clicked /focussed --reactAppMenu-color-text-focus | Text color of menu when clicked /focussed --reactAppMenu-color-border | Border color of menu --reactAppMenu-color-border-separator | Color for menu separator --reactAppMenu-border-radius | Border radius of menu --reactAppMenu-shadow | Shadow for the menu --reactAppMenu-label-submenu | Height of submenu items --reactAppMenu-label-root | Height of root menu item

Example

import React, {useState} from 'react';
import {Keys, Menu, MenuBar, Separator} from 'react-app-menu';
import {AiFillFolderOpen, FaPencilAlt, FaRegFile, FiBook, GoSearch, MdSettings} from "react-icons/all";
import 'react-app-menu/dist/styles/react-app-menu.css'

export const MenuBarDemo: React.FC = () => {
    let [showToolbar, setShowToolbar] = useState(true);
    let [showTooltip, setShowTooltip] = useState(false);

    const handleMenuSelect = (menuId: string): void => {
        switch (menuId) {
            case 'toolbar':
                return setShowToolbar(!showToolbar);
            case 'toolTips':
                return setShowTooltip(!showTooltip);
            default:
                console.log(`menu selected ${menuId}`)
        }
    };

    const onFolderSelect = (): void => {
        console.log('Folder selected');
    };

    return (<div style={{background: '#FBFBFB', borderBottom: '1px solid rgb(218, 220, 224)'}}>
        <MenuBar onSelect={handleMenuSelect}>
            <Menu label='File' focusKey={"F"}>
                <Menu label='New'>
                    <Menu menuId='NewNotebook' label='Notebook' icon={<FiBook/>}/>
                    <Menu menuId="NewNote" label='Note' icon={<FaRegFile/>} hotKeys={Keys.ctrlAlt('N')}/>
                    <Separator/>
                    <Menu label="Folder" icon={<AiFillFolderOpen/>} hotKeys={Keys.ctrlAlt("F")}
                          onSelect={onFolderSelect}/>
                </Menu>
                <Menu label='Settings' icon={<MdSettings/>} hotKeys={Keys.altShift("S")}/>
            </Menu>
            <Menu label='Edit' focusKey='E'>
                <Menu menuId='search' label='Search' icon={<GoSearch/>} hotKeys={Keys.ctrlShift('F')}/>
                <Menu menuId='undo' label='Undo' hotKeys={Keys.ctrl('Z')}/>
                <Menu menuId='rename' label='Rename' icon={<FaPencilAlt/>} hotKeys={Keys.shift('F6')}/>
            </Menu>
            <Menu label='View' focusKey='V'>
                <Menu menuId='toolbar' label='Toolbars' checked={showToolbar} hotKeys={Keys.ctrlAlt("T")}/>
                <Menu menuId='statusBar' label='StatusBar'/>
                <Menu menuId='toolTips' label='Tooltips' checked={showTooltip} hotKeys={Keys.ctrlAltShift("T")}/>
            </Menu>
        </MenuBar>
    </div>);
};

Props

MenuBar

Menubar should be the container of all menus. It provides some options that are common to all menus. It is also responsible for registering keyboard event handlers for navigation and hotkeys

| Prop | type | Required | DefaultValue | Description | | ---------------- | --------------------- | :------: | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | onSelect | (menuId:string)=>void | | | A function that is called with the menuId of the menu that was clicked. This function is only called when the menu does not have its own handler | | expandIcon | string / ReactNode | | ⮞ | The icon to be displayed to indicate that a menu has submenus | | checkedIcon | string/ ReactNode | | ✔ | The icon to be displayed on a menu that has checked=true | | enableHotKeys | boolean | | true | Set it to false if you don't require hotkeys functionality | | openMenusOnHover | boolean | | false | Set it to true to open menus by hovering over them | | className | string | | | Extra css class to add to the markup for menubar | | |

Menu

| Prop | type | Required | DefaultValue | Description | | -------- | --------------------- | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | menuId | string | | | An identifier that uniquely identifies the menu. If a menu does not have its own select handler, then the select handler of the parent menuBar is called with the menuId | | label | string / ReactNode | true | | The text label for the menu | | icon | string / ReactNode | | | The icon to be displayed on a menu | | onSelect | ()=>void | | | A callback function to be called when this menu is clicked or its associated hotkey is pressedIf not provided, clicks are delegated to MenuBar onSelect | | hotKeys | Array\\<string\\> | | | Hotkeys are used to trigger the action for the menu. Hotkeys should be an array of form \['Ctrl','Alt','F'\]. You can use the Keys helper to generate this, for eg Keys.ctrlAlt('F') | | focusKey | string | | | Only applicable for root menus. The key which when pressed with Alt will trigger open the menu, eg if File menu has focus key F, pressing Alt F will open the File menu | | checked | boolean | | | A menu that has checked true will display a checkedIcon | | show | boolean | | true | Set to false to hide this menu | | disabled | boolean | | false | Set to true to disable this menu |