PanelHeaderMenu.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import React, { PureComponent } from 'react';
  2. import { PanelMenuItem } from '@grafana/data';
  3. import { PanelHeaderMenuItem } from './PanelHeaderMenuItem';
  4. export interface Props {
  5. items: PanelMenuItem[];
  6. }
  7. export class PanelHeaderMenu extends PureComponent<Props> {
  8. renderItems = (menu: PanelMenuItem[], isSubMenu = false) => {
  9. return (
  10. <ul className="dropdown-menu dropdown-menu--menu panel-menu" role={isSubMenu ? '' : 'menu'}>
  11. {menu.map((menuItem, idx: number) => {
  12. return (
  13. <PanelHeaderMenuItem
  14. key={`${menuItem.text}${idx}`}
  15. type={menuItem.type}
  16. text={menuItem.text}
  17. iconClassName={menuItem.iconClassName}
  18. onClick={menuItem.onClick}
  19. shortcut={menuItem.shortcut}
  20. >
  21. {menuItem.subMenu && this.renderItems(menuItem.subMenu, true)}
  22. </PanelHeaderMenuItem>
  23. );
  24. })}
  25. </ul>
  26. );
  27. };
  28. render() {
  29. return <div className="panel-menu-container dropdown open">{this.renderItems(this.props.items)}</div>;
  30. }
  31. }