import color from 'color'; import * as React from 'react'; import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native'; import Text from '../Typography/Text'; import Icon, { IconSource } from '../Icon'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; import { withTheme } from '../../core/theming'; type Props = React.ComponentPropsWithRef & { /** * The label text of the item. */ label: string; /** * Icon to display for the `DrawerItem`. */ icon?: IconSource; /** * Whether to highlight the drawer item as active. */ active?: boolean; /** * Function to execute on press. */ onPress?: () => void; /** * Accessibility label for the button. This is read by the screen reader when the user taps the button. */ accessibilityLabel?: string; style?: StyleProp; /** * @optional */ theme: ReactNativePaper.Theme; }; /** * A component used to show an action item with an icon and a label in a navigation drawer. * *
*
* *
*
* * ## Usage * ```js * import * as React from 'react'; * import { Drawer } from 'react-native-paper'; * * const MyComponent = () => ( * * ); * * export default MyComponent; * ``` */ const DrawerItem = ({ icon, label, active, theme, style, onPress, accessibilityLabel, ...rest }: Props) => { const { colors, roundness } = theme; const backgroundColor = active ? color(colors.primary).alpha(0.12).rgb().string() : 'transparent'; const contentColor = active ? colors.primary : color(colors.text).alpha(0.68).rgb().string(); const font = theme.fonts.medium; const labelMargin = icon ? 32 : 0; return ( {icon ? : null} {label} ); }; DrawerItem.displayName = 'Drawer.Item'; const styles = StyleSheet.create({ container: { marginHorizontal: 10, marginVertical: 4, }, wrapper: { flexDirection: 'row', alignItems: 'center', padding: 8, }, label: { marginRight: 32, }, }); export default withTheme(DrawerItem);