2022-05-07 13:23:08 +02:00
|
|
|
import { useAccessibility } from '@utils/accessibility/AccessibilityManager'
|
2022-05-07 00:52:32 +02:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2022-05-07 13:23:08 +02:00
|
|
|
import { Text, TextProps, TextStyle } from 'react-native'
|
2022-05-07 00:52:32 +02:00
|
|
|
|
|
|
|
type Props =
|
|
|
|
| {
|
|
|
|
style?: Omit<TextStyle, 'fontSize' | 'lineHeight' | 'fontWeight'>
|
|
|
|
fontStyle?: undefined
|
|
|
|
fontSize?: 'S' | 'M' | 'L'
|
|
|
|
lineHeight?: 'S' | 'M' | 'L'
|
|
|
|
fontWeight?: 'Normal' | 'Bold'
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
style?: Omit<TextStyle, 'fontSize' | 'lineHeight' | 'fontWeight'>
|
|
|
|
fontStyle: 'S' | 'M' | 'L'
|
|
|
|
fontSize?: undefined
|
|
|
|
lineHeight?: undefined
|
|
|
|
fontWeight?: 'Normal' | 'Bold'
|
|
|
|
}
|
|
|
|
|
|
|
|
const CustomText: React.FC<Props & TextProps> = ({
|
|
|
|
children,
|
|
|
|
style,
|
|
|
|
fontStyle,
|
|
|
|
fontSize,
|
2022-05-10 23:19:26 +02:00
|
|
|
fontWeight,
|
2022-05-07 00:52:32 +02:00
|
|
|
lineHeight,
|
|
|
|
...rest
|
|
|
|
}) => {
|
2022-05-07 13:23:08 +02:00
|
|
|
const { boldTextEnabled } = useAccessibility()
|
2022-05-07 00:52:32 +02:00
|
|
|
|
|
|
|
enum BoldMapping {
|
|
|
|
'Normal' = '600',
|
|
|
|
'Bold' = '800'
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[
|
|
|
|
style,
|
|
|
|
{ ...(fontStyle && StyleConstants.FontStyle[fontStyle]) },
|
|
|
|
{ ...(fontSize && { fontSize: StyleConstants.Font.Size[fontSize] }) },
|
|
|
|
{
|
|
|
|
...(lineHeight && {
|
|
|
|
lineHeight: StyleConstants.Font.LineHeight[lineHeight]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
2022-05-10 23:19:26 +02:00
|
|
|
fontWeight: fontWeight
|
|
|
|
? boldTextEnabled
|
|
|
|
? BoldMapping[fontWeight]
|
|
|
|
: StyleConstants.Font.Weight[fontWeight]
|
|
|
|
: undefined
|
2022-05-07 00:52:32 +02:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
{...rest}
|
2022-05-07 13:23:08 +02:00
|
|
|
children={children}
|
|
|
|
/>
|
2022-05-07 00:52:32 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CustomText
|