import React from 'react'; import { StyleProp, StyleSheet, TextStyle, View, ViewStyle, } from 'react-native'; import Icon, { IconSource } from '../Icon/Icon'; import TouchableHighlight from '../TouchableHighlight/TouchableHighlight'; import Text from '../Typography/Text'; import { withTheme } from '../../core/theming'; import type { Theme } from '../../types'; import { getContentMaxWidth, getMenuItemColor, MAX_WIDTH, MIN_WIDTH, } from './utils'; export type Props = { title: React.ReactNode; leadingIcon?: IconSource; trailingIcon?: IconSource; disabled?: boolean; dense?: boolean; onPress?: () => void; style?: StyleProp; contentStyle?: StyleProp; titleStyle?: StyleProp; theme: Theme; }; const MenuItem = ({ leadingIcon, dense, title, disabled, onPress, style, contentStyle, titleStyle, theme, }: Props) => { const { titleColor, iconColor, underlayColor } = getMenuItemColor({ theme, disabled, }); const containerPadding = 8; const iconWidth = 40; const minWidth = MIN_WIDTH - 16; const maxWidth = getContentMaxWidth({ iconWidth, leadingIcon }); return ( {leadingIcon ? ( ) : null} {title} ); }; MenuItem.displayName = 'Menu.Item'; const styles = StyleSheet.create({ container: { minWidth: MIN_WIDTH, maxWidth: MAX_WIDTH, height: 48, justifyContent: 'center', }, md3DenseContainer: { height: 32, }, row: { flexDirection: 'row', }, title: { fontSize: 16, }, item: { marginHorizontal: 8, }, content: { justifyContent: 'center', }, md3WithoutLeadingIcon: { marginLeft: 4, }, }); export default withTheme(MenuItem);