import React from 'react' import classnames from 'classnames' import styles from './MenuItem.module.scss' export type MenuItemProps = { 'label': string 'href'?: string // Only applicable if href is supplied above 'target'?: string 'onClick'?: (e: React.MouseEvent) => void 'icon'?: JSX.Element 'destructive'?: boolean 'disabled'?: boolean /** * Not recommended - this was added for use in exceptional cases like the navigation bar, which needs * to highlight which page the user is currently on. By design, Menus don't have active items, * because they are supposed to be a bunch of links/actions. */ 'isActive'?: boolean 'data-testid'?: string 'id'?: string } export const MenuItem = ({ label, icon, destructive, disabled, onClick, href, target, isActive, 'data-testid': dataTestId, id, }: MenuItemProps): JSX.Element => { const wrappedLabel = {label} const iconNode = icon && {icon} const className = classnames( styles.menuItem, destructive && styles['menuItem--destructive'], disabled && styles['menuItem--disabled'], isActive && styles['menuItem--active'], ) if (disabled) { return (
  • ) } if (href) { return (
  • {iconNode} {wrappedLabel}
  • ) } return (
  • ) } MenuItem.displayName = 'MenuItem'