|
|
|
@ -44,6 +44,8 @@ export interface MenuItemProps<T = any> { |
|
|
|
|
childItems?: Array<ReactElement<MenuItemProps>>; |
|
|
|
|
/** Custom style for SubMenu */ |
|
|
|
|
customSubMenuContainerStyles?: CSSProperties; |
|
|
|
|
/** Shortcut key combination */ |
|
|
|
|
shortcut?: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** @internal */ |
|
|
|
@ -65,6 +67,7 @@ export const MenuItem = React.memo( |
|
|
|
|
role = 'menuitem', |
|
|
|
|
tabIndex = -1, |
|
|
|
|
customSubMenuContainerStyles, |
|
|
|
|
shortcut, |
|
|
|
|
} = props; |
|
|
|
|
const styles = useStyles2(getStyles); |
|
|
|
|
const [isActive, setIsActive] = useState(active); |
|
|
|
@ -132,6 +135,8 @@ export const MenuItem = React.memo( |
|
|
|
|
localRef?.current?.focus(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const hasShortcut = Boolean(shortcut && shortcut.length > 0); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<ItemElement |
|
|
|
|
target={target} |
|
|
|
@ -153,18 +158,26 @@ export const MenuItem = React.memo( |
|
|
|
|
<> |
|
|
|
|
{icon && <Icon name={icon} className={styles.icon} aria-hidden />} |
|
|
|
|
{label} |
|
|
|
|
</> |
|
|
|
|
|
|
|
|
|
{hasSubMenu && ( |
|
|
|
|
<SubMenu |
|
|
|
|
items={childItems} |
|
|
|
|
isOpen={isSubMenuOpen} |
|
|
|
|
openedWithArrow={openedWithArrow} |
|
|
|
|
setOpenedWithArrow={setOpenedWithArrow} |
|
|
|
|
close={closeSubMenu} |
|
|
|
|
customStyle={customSubMenuContainerStyles} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
<div className={cx(styles.rightWrapper, { [styles.withShortcut]: hasShortcut })}> |
|
|
|
|
{hasShortcut && ( |
|
|
|
|
<div className={styles.shortcut}> |
|
|
|
|
<Icon name="keyboard" aria-hidden /> |
|
|
|
|
{shortcut} |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
{hasSubMenu && ( |
|
|
|
|
<SubMenu |
|
|
|
|
items={childItems} |
|
|
|
|
isOpen={isSubMenuOpen} |
|
|
|
|
openedWithArrow={openedWithArrow} |
|
|
|
|
setOpenedWithArrow={setOpenedWithArrow} |
|
|
|
|
close={closeSubMenu} |
|
|
|
|
customStyle={customSubMenuContainerStyles} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
|
</> |
|
|
|
|
</ItemElement> |
|
|
|
|
); |
|
|
|
|
}) |
|
|
|
@ -238,5 +251,24 @@ const getStyles = (theme: GrafanaTheme2) => { |
|
|
|
|
margin-left: -4px; |
|
|
|
|
color: ${theme.colors.text.secondary}; |
|
|
|
|
`,
|
|
|
|
|
rightWrapper: css` |
|
|
|
|
display: flex; |
|
|
|
|
align-items: center; |
|
|
|
|
margin-left: auto; |
|
|
|
|
`,
|
|
|
|
|
shortcutIcon: css` |
|
|
|
|
margin-right: ${theme.spacing(1)}; |
|
|
|
|
`,
|
|
|
|
|
withShortcut: css` |
|
|
|
|
min-width: ${theme.spacing(10.5)}; |
|
|
|
|
`,
|
|
|
|
|
shortcut: css` |
|
|
|
|
display: flex; |
|
|
|
|
align-items: center; |
|
|
|
|
gap: ${theme.spacing(1)}; |
|
|
|
|
margin-left: ${theme.spacing(2)}; |
|
|
|
|
color: ${theme.colors.text.secondary}; |
|
|
|
|
opacity: 0.7; |
|
|
|
|
`,
|
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|