import { ReactNode } from 'react'; import { Box, BoxProps } from '../../Box'; import { Text } from '../../Text'; import { MenuSize } from './Menu'; import { MenuDivider } from './MenuDivider'; import { MenuItemDescription } from './MenuItemDescription'; import { MenuItemLabel } from './MenuItemLabel'; export type MenuItemRenderProps = | { children: ReactNode } | { label: ReactNode; description?: ReactNode }; export type MenuItemProps = Pick & { /** * Renders `` below the menu item. */ hasDividerBottom?: boolean; /** * Renders `` above the menu item. */ hasDividerTop?: boolean; /** * Displays an element on the left of `children` or `label. */ leftAdornment?: ReactNode; /** * Displays an element on the right of `children` or `label. */ rightAdornment?: ReactNode; /** * The `shortcut` prop will append the keys used to trigger the shortcut. */ shortcut?: string[]; /** * Defaults to value of `id` */ ['data-testid']?: string; /** * The `size` prop determines the height of the menu item and the spacing of the adornments. */ size?: MenuSize; } & MenuItemRenderProps; export const MenuItem = ({ hasDividerBottom, hasDividerTop, leftAdornment, rightAdornment, shortcut, size = 'small', tx, ...restOfProps }: MenuItemProps) => { const hasDescription = 'description' in restOfProps; const isSmallSize = size === 'small'; const numberOfShortcutKeys = shortcut?.length ?? 0; return ( <> {hasDividerTop && } {leftAdornment && ( {leftAdornment} )} {'children' in restOfProps ? ( restOfProps.children ) : ( {restOfProps.label} {restOfProps.description} )} {rightAdornment && ( {rightAdornment} )} {shortcut && ( {shortcut.map((key, index) => { const isLastKey = numberOfShortcutKeys - 1 === index; return ( <> {key} {!isLastKey && (  +  )} ); })} )} {hasDividerBottom && } ); };