import * as React from 'react'; import { createComponent, createElement, createHook } from 'bumbag/utils'; import { BoxProps, BoxTouchable, BoxTouchableProps } from '../Box'; import { Flex } from '../Flex'; import { Icon, IconProps } from '../Icon'; import { TextProps } from '../Text'; import * as styles from './Menu.styles'; export type LocalMenuItemProps = { disabled?: boolean; hasDivider?: boolean; isStatic?: boolean; after?: React.ReactElement; before?: React.ReactElement; disableLeftPadding?: boolean; iconAfter?: IconProps['icon']; iconAfterProps?: Partial; iconBefore?: IconProps['icon']; iconBeforeProps?: Partial; afterWrapperProps?: Partial; beforeWrapperProps?: Partial; contentProps?: Partial; contentTextProps?: Partial; }; export type MenuItemProps = BoxTouchableProps & LocalMenuItemProps; const useProps = createHook( (props) => { const { after, before, afterWrapperProps, beforeWrapperProps, contentProps, contentTextProps, disabled, hasDivider, iconAfter, iconAfterProps, iconBefore, iconBeforeProps, isStatic, disableLeftPadding, overrides, } = props; const boxTouchableProps = BoxTouchable.useProps(props); return { ...boxTouchableProps, activeOpacity: isStatic ? 1 : 0.2, focusable: !disabled && !isStatic, children: ( {!disableLeftPadding && (before || iconBefore) && ( {iconBefore && } {before} )} {disableLeftPadding && (before || iconBefore) && ( {iconBefore && } {before} )} {props.children} {(after || iconAfter) && ( {iconAfter && } {after} )} ), }; }, { defaultProps: { _hover: true, _focus: true, _active: true, _hoveractive: true }, themeKey: 'native.Menu.Item' } ); export const MenuItem = createComponent( (props) => { const htmlProps = useProps(props); return createElement({ children: props.children, component: styles.MenuItem, htmlProps, }); }, { attach: { useProps, displayName: 'native.Menu.Item', }, themeKey: 'native.Menu.Item', } );