2023-01-25 00:15:46 +01:00
|
|
|
import Icon, { IconName } from '@components/Icon'
|
2023-01-15 20:34:22 +01:00
|
|
|
import { Loading } from '@components/Loading'
|
2022-05-07 00:52:32 +02:00
|
|
|
import CustomText from '@components/Text'
|
2021-01-03 02:00:26 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
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 { AccessibilityProps, Pressable, View } from 'react-native'
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2023-01-25 00:15:46 +01:00
|
|
|
export type Props = {
|
2021-04-09 21:43:12 +02:00
|
|
|
accessibilityLabel?: string
|
|
|
|
accessibilityHint?: string
|
|
|
|
accessibilityState?: AccessibilityProps['accessibilityState']
|
|
|
|
|
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
|
|
|
loading?: boolean
|
|
|
|
disabled?: boolean
|
2022-12-22 01:21:51 +01:00
|
|
|
destructive?: boolean
|
2023-07-13 21:55:26 +02:00
|
|
|
destructiveColor?: string
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2020-12-26 23:27:53 +01:00
|
|
|
onPress: () => void
|
2023-01-25 00:15:46 +01:00
|
|
|
} & ({ type?: undefined; content: IconName } | { type: 'text'; content: string })
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2020-12-26 23:27:53 +01:00
|
|
|
const HeaderRight: React.FC<Props> = ({
|
2021-04-09 21:43:12 +02:00
|
|
|
// Accessibility - Start
|
|
|
|
accessibilityLabel,
|
|
|
|
accessibilityHint,
|
|
|
|
accessibilityState,
|
|
|
|
// Accessibility - End
|
2023-01-25 00:15:46 +01:00
|
|
|
type,
|
2020-12-26 23:27:53 +01:00
|
|
|
content,
|
2021-01-30 01:29:15 +01:00
|
|
|
native = true,
|
2021-03-22 00:25:53 +01:00
|
|
|
background = false,
|
2020-12-26 23:27:53 +01:00
|
|
|
loading,
|
2020-12-03 01:28:56 +01:00
|
|
|
disabled,
|
2022-12-22 01:21:51 +01:00
|
|
|
destructive = false,
|
2023-07-13 21:55:26 +02:00
|
|
|
destructiveColor,
|
2020-12-26 23:27:53 +01:00
|
|
|
onPress
|
2020-11-30 00:24:53 +01:00
|
|
|
}) => {
|
2023-01-25 00:15:46 +01:00
|
|
|
const { colors } = useTheme()
|
2020-11-30 00:24:53 +01:00
|
|
|
|
2022-12-29 00:36:35 +01:00
|
|
|
const loadingSpinkit = () =>
|
|
|
|
loading ? (
|
2020-12-26 23:27:53 +01:00
|
|
|
<View style={{ position: 'absolute' }}>
|
2023-01-15 20:34:22 +01:00
|
|
|
<Loading />
|
2020-12-26 23:27:53 +01:00
|
|
|
</View>
|
2022-12-29 00:36:35 +01:00
|
|
|
) : null
|
2020-12-26 23:27:53 +01:00
|
|
|
|
2022-12-29 00:36:35 +01:00
|
|
|
const children = () => {
|
2020-12-26 23:27:53 +01:00
|
|
|
switch (type) {
|
|
|
|
case 'text':
|
|
|
|
return (
|
|
|
|
<>
|
2022-05-07 00:52:32 +02:00
|
|
|
<CustomText
|
|
|
|
fontStyle='M'
|
2022-12-22 01:21:51 +01:00
|
|
|
fontWeight={destructive ? 'Bold' : 'Normal'}
|
2022-05-07 00:52:32 +02:00
|
|
|
style={{
|
2022-12-22 01:21:51 +01:00
|
|
|
color: disabled
|
|
|
|
? colors.secondary
|
|
|
|
: destructive
|
2023-07-13 21:55:26 +02:00
|
|
|
? destructiveColor || colors.red
|
2022-12-22 01:21:51 +01:00
|
|
|
: colors.primaryDefault,
|
2022-05-07 00:52:32 +02:00
|
|
|
opacity: loading ? 0 : 1
|
|
|
|
}}
|
2020-12-26 23:27:53 +01:00
|
|
|
children={content}
|
|
|
|
/>
|
2022-12-29 00:36:35 +01:00
|
|
|
{loadingSpinkit()}
|
2020-12-26 23:27:53 +01:00
|
|
|
</>
|
|
|
|
)
|
2023-01-25 00:15:46 +01:00
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Icon
|
|
|
|
name={content}
|
|
|
|
style={{ opacity: loading ? 0 : 1 }}
|
|
|
|
size={StyleConstants.Spacing.M * 1.25}
|
|
|
|
color={disabled ? colors.secondary : destructive ? colors.red : colors.primaryDefault}
|
|
|
|
/>
|
|
|
|
{loadingSpinkit()}
|
|
|
|
</>
|
|
|
|
)
|
2020-12-26 23:27:53 +01:00
|
|
|
}
|
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
|
2021-04-09 21:43:12 +02:00
|
|
|
accessibilityLabel={accessibilityLabel}
|
|
|
|
accessibilityHint={accessibilityHint}
|
|
|
|
accessibilityRole='button'
|
|
|
|
accessibilityState={accessibilityState}
|
2020-12-28 16:54:19 +01:00
|
|
|
onPress={onPress}
|
2022-12-29 00:36:35 +01:00
|
|
|
children={children()}
|
2020-12-28 16:54:19 +01:00
|
|
|
disabled={disabled || loading}
|
2022-05-07 00:52:32 +02:00
|
|
|
style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
2022-12-22 01:21:51 +01:00
|
|
|
backgroundColor: background ? colors.backgroundOverlayDefault : undefined,
|
2022-05-07 00:52:32 +02:00
|
|
|
minHeight: 44,
|
|
|
|
minWidth: 44,
|
2022-12-22 01:21:51 +01:00
|
|
|
marginRight: native ? -StyleConstants.Spacing.S : StyleConstants.Spacing.S,
|
2023-02-12 18:38:06 +01:00
|
|
|
...(type === undefined && { 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 HeaderRight
|