tooot/src/components/Header/Left.tsx

75 lines
1.7 KiB
TypeScript
Raw Normal View History

import Icon from '@components/Icon'
import CustomText from '@components/Text'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
2020-12-26 23:27:53 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useMemo } from 'react'
import { Pressable } from 'react-native'
2020-11-30 00:24:53 +01:00
2020-12-26 23:27:53 +01:00
export interface Props {
type?: 'icon' | 'text'
content?: string
2021-01-30 01:29:15 +01:00
native?: boolean
2021-03-22 00:25:53 +01:00
background?: boolean
2020-11-30 00:24:53 +01:00
2020-12-26 23:27:53 +01:00
onPress: () => void
}
2021-01-30 01:29:15 +01:00
const HeaderLeft: React.FC<Props> = ({
type = 'icon',
content,
native = true,
2021-03-22 00:25:53 +01:00
background = false,
2021-01-30 01:29:15 +01:00
onPress
}) => {
2022-02-12 14:51:01 +01:00
const { colors, theme } = useTheme()
2020-11-30 00:24:53 +01:00
2020-12-26 23:27:53 +01:00
const children = useMemo(() => {
switch (type) {
case 'icon':
return (
<Icon
2022-02-12 14:51:01 +01:00
color={colors.primaryDefault}
name={content || 'ChevronLeft'}
2020-12-26 23:27:53 +01:00
size={StyleConstants.Spacing.M * 1.25}
/>
)
case 'text':
return (
<CustomText
fontStyle='M'
style={{ color: colors.primaryDefault }}
2020-12-26 23:27:53 +01:00
children={content}
/>
)
}
}, [theme])
2020-11-30 00:24:53 +01:00
return (
2020-12-13 23:38:37 +01:00
<Pressable
onPress={onPress}
2020-12-26 23:27:53 +01:00
children={children}
style={{
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: background
? colors.backgroundOverlayDefault
: undefined,
minHeight: 44,
minWidth: 44,
marginLeft: native
? -StyleConstants.Spacing.S
: StyleConstants.Spacing.S,
...(type === 'icon' && {
borderRadius: 100
}),
...(type === 'text' && {
paddingHorizontal: StyleConstants.Spacing.S
})
}}
2020-12-26 23:27:53 +01:00
/>
2020-11-30 00:24:53 +01:00
)
}
2020-12-12 12:49:29 +01:00
export default HeaderLeft