2023-01-25 00:15:46 +01:00
|
|
|
import Icon, { IconName } from '@components/Icon'
|
2022-05-07 00:52:32 +02:00
|
|
|
import CustomText from '@components/Text'
|
2024-02-07 00:22:22 +01:00
|
|
|
import { useNavigation } from '@react-navigation/native'
|
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'
|
2022-12-29 00:36:35 +01:00
|
|
|
import React from 'react'
|
2022-05-07 00:52:32 +02:00
|
|
|
import { Pressable } from 'react-native'
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2023-01-25 00:15:46 +01:00
|
|
|
export type Props = {
|
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
|
|
|
|
2024-02-07 00:22:22 +01:00
|
|
|
onPress?: () => void
|
2023-01-25 00:15:46 +01:00
|
|
|
} & ({ type?: undefined; content?: IconName } | { type: 'text'; content: string })
|
2020-12-14 22:33:19 +01:00
|
|
|
|
2021-01-30 01:29:15 +01:00
|
|
|
const HeaderLeft: React.FC<Props> = ({
|
2023-01-25 00:15:46 +01:00
|
|
|
type,
|
2021-01-30 01:29:15 +01:00
|
|
|
content,
|
|
|
|
native = true,
|
2021-03-22 00:25:53 +01:00
|
|
|
background = false,
|
2021-01-30 01:29:15 +01:00
|
|
|
onPress
|
|
|
|
}) => {
|
2024-02-07 00:22:22 +01:00
|
|
|
const navigation = useNavigation()
|
2022-12-29 00:36:35 +01:00
|
|
|
const { colors } = useTheme()
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2022-12-29 00:36:35 +01:00
|
|
|
const children = () => {
|
2020-12-26 23:27:53 +01:00
|
|
|
switch (type) {
|
2023-01-25 00:15:46 +01:00
|
|
|
case 'text':
|
|
|
|
return (
|
|
|
|
<CustomText fontStyle='M' style={{ color: colors.primaryDefault }} children={content} />
|
|
|
|
)
|
|
|
|
default:
|
2020-12-26 23:27:53 +01:00
|
|
|
return (
|
2021-01-03 02:00:26 +01:00
|
|
|
<Icon
|
2022-02-12 14:51:01 +01:00
|
|
|
color={colors.primaryDefault}
|
2023-01-25 00:15:46 +01:00
|
|
|
name={content || 'chevron-left'}
|
2020-12-26 23:27:53 +01:00
|
|
|
size={StyleConstants.Spacing.M * 1.25}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2022-12-29 00:36:35 +01:00
|
|
|
}
|
2020-12-26 23:27:53 +01:00
|
|
|
|
2020-11-30 00:24:53 +01:00
|
|
|
return (
|
2020-12-13 23:38:37 +01:00
|
|
|
<Pressable
|
2024-02-07 00:22:22 +01:00
|
|
|
onPress={onPress ? onPress : () => navigation.goBack()}
|
2022-12-29 00:36:35 +01:00
|
|
|
children={children()}
|
2022-05-07 00:52:32 +02:00
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
2022-12-29 00:36:35 +01:00
|
|
|
backgroundColor: background ? colors.backgroundOverlayDefault : undefined,
|
2022-05-07 00:52:32 +02:00
|
|
|
minHeight: 44,
|
|
|
|
minWidth: 44,
|
2022-12-29 00:36:35 +01:00
|
|
|
marginLeft: native ? -StyleConstants.Spacing.S : StyleConstants.Spacing.S,
|
2023-01-25 00:15:46 +01:00
|
|
|
...(type === undefined && {
|
2023-02-12 18:38:06 +01:00
|
|
|
borderRadius: 99
|
2022-05-07 00:52:32 +02:00
|
|
|
}),
|
|
|
|
...(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
|