tooot/src/components/Menu/Item.tsx

85 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-11-22 00:46:23 +01:00
import React from 'react'
import { Pressable, StyleSheet, Text, View } from 'react-native'
import { useNavigation } from '@react-navigation/native'
import { Feather } from '@expo/vector-icons'
2020-11-23 00:07:32 +01:00
import { useTheme } from 'src/utils/styles/ThemeManager'
2020-11-22 00:46:23 +01:00
2020-11-24 00:18:47 +01:00
import constants from 'src/utils/styles/constants'
2020-11-22 00:46:23 +01:00
export interface Props {
icon?: string
title: string
navigateTo?: string
navigateToParams?: {}
}
const Core: React.FC<Props> = ({ icon, title, navigateTo }) => {
2020-11-23 00:07:32 +01:00
const { theme } = useTheme()
2020-11-22 00:46:23 +01:00
return (
<View style={styles.core}>
2020-11-24 00:18:47 +01:00
{icon && (
<Feather
name={icon}
size={constants.FONT_SIZE_M + 2}
style={styles.iconLeading}
color={theme.primary}
/>
)}
<Text style={{ color: theme.primary, fontSize: constants.FONT_SIZE_M }}>
{title}
</Text>
2020-11-22 00:46:23 +01:00
{navigateTo && (
<Feather
name='chevron-right'
size={24}
2020-11-23 00:07:32 +01:00
color={theme.secondary}
2020-11-22 00:46:23 +01:00
style={styles.iconNavigation}
/>
)}
</View>
)
}
const MenuItem: React.FC<Props> = ({ ...props }) => {
2020-11-24 00:18:47 +01:00
const { theme } = useTheme()
2020-11-22 00:46:23 +01:00
const navigation = useNavigation()
return props.navigateTo ? (
<Pressable
2020-11-24 00:18:47 +01:00
style={[styles.base, { borderBottomColor: theme.separator }]}
2020-11-22 00:46:23 +01:00
onPress={() => {
navigation.navigate(props.navigateTo!, props.navigateToParams)
}}
>
<Core {...props} />
</Pressable>
) : (
<View style={styles.base}>
<Core {...props} />
</View>
)
}
const styles = StyleSheet.create({
base: {
height: 50,
borderBottomWidth: 1
},
core: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
2020-11-24 00:18:47 +01:00
paddingLeft: constants.GLOBAL_PAGE_PADDING,
paddingRight: constants.GLOBAL_PAGE_PADDING
2020-11-22 00:46:23 +01:00
},
iconLeading: {
marginRight: 8
},
iconNavigation: {
marginLeft: 'auto'
}
})
export default MenuItem