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

mui-menubar

v1.1.3

Published

A React MenuBar component using Material-UI.

Downloads

172

Readme

Ⓜ ─ mui-menubar ─ 🍫

Build codecov Code Climate NPM Version TypeScript

A React MenuBar component built with Material-UI (MUI), providing a customizable and accessible menu bar implementation for applications. A menu bar is common in desktop applications and provides quick access to a consistent set of commands (e.g. File, Edit, View).

🚀 Features

  • Cascading menus with unlimited nesting
  • Light and dark theme support
  • Keyboard shortcuts
  • Support for integrating components as a custom menu item
  • Material-UI icons integration

📦 Basic Implementation

Installation

  1. Install the menu bar package
npm install @your-scope/menubar-component
  1. Install peer dependencies (if not already in your project)
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled material-ui-popup-state react-hotkeys-hook

Basic usage example:

import { MenuBar, MenuConfig } from 'mui-menubar';
import { FileCopy, Save } from '@mui/icons-material';

const App = () => {
  const menuConfig = [
    {
      label: "File",
      items: [
        {
          kind: "action",
          label: "New",
          action: () => console.log("New file"),
          icon: <FileCopy />,
          shortcut: "Ctrl+N"
        },
        {
          kind: "action",
          label: "Save",
          action: () => console.log("Save file"),
          icon: <Save />,
          shortcut: "Ctrl+S"
        }
      ]
    }
  ];

  return (
    <MenuBar 
      config={menuConfig}
      colorTheme="light"
      color="transparent"
    />
  );
};

⚙️ API Reference

MenuBar Interface

interface MenuBarProps {
    config?: MenuConfig[]; // Menu structure configuration
    colorTheme?: "light" | "dark"; // Theme selection
    color?: "default" | "primary" | "secondary" | "inherit" | "transparent";
    sx?: SxProps<Theme>; // MUI styling overrides
    disableRipple?: boolean; // Disable click animation
    transitionDuration?: TransitionDuration;
}

📚 Menu Configuration

Menu Item Types

The MenuBar supports four types of menu items:

  1. Action Items (kind: "action"): Clickable menu items that trigger a function
{
    kind: "action",
    label: "Save",
    action: () => void,
    icon?: React.ReactNode, // Optional Material-UI icon
    shortcut?: string, // Keyboard shortcut
    disabled?: boolean, // If true, the menu item will be disabled
}
  1. Divider Items (kind: "divider"): Visual separators between menu items
{
    kind: "divider"
}
  1. Submenu Items (kind: "submenu"): Nested menus that contain additional menu items
{
    kind: "submenu",
    label: "Settings",
    items: MenuItems[], // Nested menu items
    icon?: React.ReactNode
}
  1. Custom Items (kind: "custom"): Custom React components rendered within the menu
{
    kind: "custom",
    component: React.ReactNode // Any custom React component
}

⏩ Advanced Usage Examples

Theme Configuration

<MenuBar
    config={menuConfig}
    colorTheme="dark"
    color="primary"
    sx={{ backgroundColor: '#1a1a1a' }}
/>

Custom Menu with Icons

const menuConfig = [{
    label: "Edit",
    items: [
        {
            kind: "action",
            label: "Undo",
            action: () => handleUndo(),
            icon: <Undo />,
            shortcut: "Ctrl+Z"
        },
        {
            kind: "submenu",
            label: "Advanced",
            icon: <Settings />,
            items: [
                {
                    kind: "action",
                    label: "Custom Action",
                    action: () => handleCustomAction()
                }
            ]
        }
    ]
}];

Custom Component Integration

{
    kind: "custom",
        component: (
            <TableSizeChooser
                maxRows={10}
                maxCols={10}
                onSizeSelect={(rows, cols) => handleSizeSelect(rows, cols)}
            />
        )
}

🚨 Important Notes for Implementation

  1. Icon Integration

    • Requires @mui/icons-material package
    • Icons should be passed as React elements
  2. Keyboard Shortcuts

    • Automatically registered when specified in config
    • Format: "Ctrl+S", "Shift+A", etc.
  3. Styling

    • Uses Material-UI's sx prop for custom styling
    • Supports all Material-UI theme configurations
  4. Performance Considerations

    • Menu items are rendered lazily
    • Use memoization for complex custom components
  5. Accessibility

    • Supports keyboard navigation
    • ARIA attributes automatically handled

🎨 Common Customization Patterns

  1. Custom Transitions

    • Configurable via transitionDuration prop
    • Supports auto, number, or object configuration
  2. Dynamic Menu Items

    • Config can be updated dynamically
    • Useful for context-sensitive menus
  3. Theme Integration

    • Automatically integrates with Material-UI theme
    • Can be overridden with sx prop

🚫 Error Handling

  • Invalid config structures will be safely ignored
  • Disabled items prevent user interaction
  • Type checking ensures proper prop usage

🛠️ Development

Project Structure

mui-menubar/
├── src/
│   ├── components/     # React components
│   ├── types/         # TypeScript type definitions
│   ├── utils/         # Utility functions
│   └── index.ts       # Main entry point
├── stories/          # Storybook stories
├── tests/           # Jest test files
└── dist/           # Compiled output

Scripts

  • npm run build - Build the project
  • npm run test - Run tests
  • npm run test:watch - Run tests in watch mode
  • npm run test:coverage - Generate test coverage report
  • npm run storybook - Start Storybook development server
  • npm run build-storybook - Build Storybook for production

Testing

The project uses Jest for testing. Tests are located in the tests directory. Run tests using:

npm run test

Storybook

Component documentation and examples are available through Storybook. Run:

npm run storybook

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.