import color from "color"; import * as React from "react"; import { View, StyleSheet, TextStyle, ViewStyle, StyleProp, } from "react-native"; import { SvgIcon } from "../Icon"; import TouchableRipple from "../TouchableRipple/TouchableRipple"; import Text from "../Text"; import { black, white } from "../theme/colors"; import { DefaultTheme, ThemeContext } from "styled-components"; type Props = { /** * Title text for the `MenuItem`. */ title: React.ReactNode; /** * Icon to display for the `MenuItem`. */ icon?: React.ReactElement; /** * Whether the 'item' is disabled. A disabled 'item' is greyed out and `onPress` is not called on touch. */ disabled?: boolean; /** * Function to execute on press. */ onPress?: () => void; /** * @optional */ theme?: DefaultTheme; style?: StyleProp; contentStyle?: StyleProp; titleStyle?: StyleProp; /** * TestID used for testing purposes */ testID?: string; }; /** * A component to show a single list item inside a Menu. * *
*
* *
*
* * ## Usage * ```js * import * as React from 'react'; * import { View } from 'react-native'; * import { MenuItem } from 'react-native-simple-elements/components/Menu'; * * const MyComponent = () => ( * * {}} title="Redo" /> * {}} title="Undo" /> * {}} title="Cut" disabled /> * {}} title="Copy" disabled /> * {}} title="Paste" /> * * ); * * export default MyComponent; * ``` */ const MenuItem = function(props: Props) { const { icon, title, disabled, onPress, style, contentStyle, testID, titleStyle, } = props; const theme = React.useContext(ThemeContext); const disabledColor = color(theme.dark ? white : black) .alpha(0.32) .rgb() .string(); const titleColor = disabled ? disabledColor : color(theme.colors.text).alpha(0.87).rgb().string(); const iconColor = disabled ? disabledColor : color(theme.colors.text).alpha(0.54).rgb().string(); return ( {icon ? ( ) : null} {title} ); }; MenuItem.displayName = "Menu.Item"; const minWidth = 112; const maxWidth = 280; const iconWidth = 40; const styles = StyleSheet.create({ container: { // paddingHorizontal: 8, paddingRight: 8, paddingLeft: 8, minWidth, maxWidth, height: 48, justifyContent: "center", }, row: { flexDirection: "row", }, icon: { width: iconWidth, }, title: { fontSize: 16, }, item: { // marginHorizontal: 8, marginRight: 8, marginLeft: 8, }, content: { justifyContent: "center", minWidth: minWidth - 16, maxWidth: maxWidth - 16, }, widthWithIcon: { maxWidth: maxWidth - (iconWidth + 48), }, }); export default MenuItem; // @component-docs ignore-next-line export { MenuItem };