Last active
December 29, 2023 21:15
-
-
Save coolsoftwaretyler/5b9c4bf15cdbcc4c5b132a4082b0f767 to your computer and use it in GitHub Desktop.
React Native Text Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { | |
StyleSheet, | |
Text as RNText, | |
TextProps as RNTextProps, | |
TextStyle, | |
} from 'react-native'; | |
const styles = StyleSheet.create({ | |
header: { | |
fontSize: 32, | |
fontWeight: 'bold', | |
lineHeight: 40, | |
textTransform: 'uppercase', | |
}, | |
subheader: { | |
fontSize: 24, | |
fontWeight: '600', | |
lineHeight: 30, | |
}, | |
body: { | |
fontSize: 16, | |
fontWeight: 'normal', | |
lineHeight: 24, | |
}, | |
defaultColor: { color: '#000000' }, | |
}); | |
type PresetNames = 'header' | 'subheader' | 'body'; | |
export interface TextProps extends RNTextProps { | |
text?: string; | |
preset?: PresetNames; | |
color?: string; | |
} | |
export function BrandText(props: TextProps) { | |
const { | |
text, | |
preset = 'body', | |
color = styles.defaultColor.color, | |
style, | |
...rest | |
} = props; | |
const presetStyle = styles[preset] || styles.body; | |
const colorStyle = { color }; | |
const combinedStyles = [presetStyle, colorStyle, style]; | |
return ( | |
<RNText {...rest} style={combinedStyles}> | |
{text} | |
</RNText> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment