Socket
Socket
Sign inDemoInstall

@bearei/react-menu

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bearei/react-menu

Base menu components that support React and React native


Version published
Weekly downloads
13
increased by18.18%
Maintainers
1
Weekly downloads
 
Created
Source

react-menu

Base menu components that support React and React native

Installation

yarn add @bearei/react-menu --save

Parameters

Menu Options
NameTypeRequiredDescription
keystringThe key currently selected on the menu
selectedKeysstring[]The menu selects the completed key
eventunknownTriggers an event when a menu option changes
Menu
NameTypeRequiredDescription
selectedKeysstring[]The menu selects the completed key
defaultSelectedKeysstring[]The menu selects the completion item by default
items(BaseMenuItemProps & {key?: string})[]Menu items
multiplebooleanAllow multiple menu items to be selected
expandIconReactNodeMenu item expansion icon
modevertical horizontal inlineMenu mode
onSelect(options: MenuOptions) => voidThis function is called back when the menu item selection is complete
renderMain(props: MenuMainProps) => ReactNodeRender the menu main
renderContainer(props: MenuContainerProps) => ReactNodeRender the menu container
MenuItem
NameTypeRequiredDescription
modevertical horizontal inlineMenu mode
expandIconReactNodeMenu item expansion icon
selectedKeysstring[]The menu selects the completed key
labelstringMenu item label
indexstringMenu item index
parentIndexstringMenu parent index
keystringMenu key
iconReactNodeMenu item icon
disabledbooleanWhether or not to disable the menu item
loadingbooleanWhether the menu item is loading
onClick(e: React.MouseEvent) => voidThis function is called when menu item is clicked
onTouchEnd(e: React.TouchEvent) => voidThis function is called when the menu item is pressed
onPress(e: GestureResponderEvent) => voidThis function is called when the menu item is pressed -- react native
renderIcon (props: MenuItemIconProps) => ReactNodeRender the menu item icon
renderExpandIcon (props: MenuItemExpandIconProps) => ReactNodeRender the menu item expansion icon
renderMain (props: MenuItemMainProps) => ReactNodeRender the menu item main
renderContainer (props: MenuItemContainerProps) => ReactNodeRender the menu item container
childrenBaseMenuItemProps[]Menu children

Use

import React from 'React';
import ReactDOM from 'react-dom';
import Menu, {MenuItem} from '@bearei/react-menu';

const menus = [
  {label: 'MenuItem1', key: '1', icon: <i />},
  {label: 'MenuItem2', key: '2', icon: <i />},
  {label: 'MenuItem3', key: '3', icon: <i />, disabled: true},
];

const renderMenuItem = (
  {loading, disabled, icon, key, label, ...props}: BaseMenuItemProps,
  onSelect?: (
    e: React.MouseEvent<HTMLDivElement, MouseEvent>,
    key: string,
  ) => void,
) => (
  <MenuItem
    {...props}
    key={key}
    loading={loading}
    disabled={disabled}
    icon={icon}
    index={key}
    label={label}
    onClick={e => key && onSelect?.(e, key)}
    renderIcon={({children, ...props}) => (
      <i {...props}>{children}</i>
    )}
    renderExpandIcon={({children, ...props}) => (
      <i {..props}>{children}</i>
    )}
    renderMain={({label, ...props}) => (
      <div {...props}>{label}</div>
    )}
    renderContainer={({id, children, ...props}) => (
      <div {...props}>{children}</div>
    )}
  />
);

const menu = (
  <Menu
    items={menus}
    renderMain={({items, onSelect}) => (
      <div>{items?.map(item => renderMenuItem(item, onSelect))}</div>
    )}
    renderContainer={({id, children, ...props}) => (
      <div data-id={id} {...props}>
        {children}
      </div>
    )}
  />
);

ReactDOM.render(menu, container);

Keywords

FAQs

Package last updated on 27 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc