mui-menubar v1.1.3
ā ā mui-menubar ā š«
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
- Install the menu bar package
npm install @your-scope/menubar-component
- 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:
- 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
}
- Divider Items (
kind: "divider"
): Visual separators between menu items
{
kind: "divider"
}
- Submenu Items (
kind: "submenu"
): Nested menus that contain additional menu items
{
kind: "submenu",
label: "Settings",
items: MenuItems[], // Nested menu items
icon?: React.ReactNode
}
- 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
Icon Integration
- Requires @mui/icons-material package
- Icons should be passed as React elements
Keyboard Shortcuts
- Automatically registered when specified in config
- Format: "Ctrl+S", "Shift+A", etc.
Styling
- Uses Material-UI's sx prop for custom styling
- Supports all Material-UI theme configurations
Performance Considerations
- Menu items are rendered lazily
- Use memoization for complex custom components
Accessibility
- Supports keyboard navigation
- ARIA attributes automatically handled
šØ Common Customization Patterns
Custom Transitions
- Configurable via transitionDuration prop
- Supports auto, number, or object configuration
Dynamic Menu Items
- Config can be updated dynamically
- Useful for context-sensitive menus
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 projectnpm run test
- Run testsnpm run test:watch
- Run tests in watch modenpm run test:coverage
- Generate test coverage reportnpm run storybook
- Start Storybook development servernpm 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
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago