-
-
Save suprith-s-reddy/472c40ad88d87be87a3212ba4cf7ff21 to your computer and use it in GitHub Desktop.
Text Atom Component
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 Text from './Text'; | |
export default Text; |
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 * as React from 'react'; | |
import { Text as BaseText, TextProps as BaseTextProps } from 'react-native'; | |
// import useThemeColors from '@src/custom-hooks/useThemeColors'; | |
interface TextProps extends BaseTextProps { | |
children?: React.ReactNode; | |
isPrimary?: boolean; | |
isSecondary?: boolean; | |
isBold?: boolean; | |
isHeadingTitle?: boolean; | |
isCenter?: boolean; | |
isWhite?: boolean; | |
hasMargin?: boolean; | |
} | |
const Text: React.FC<TextProps> = ({ | |
children, | |
isPrimary, | |
isSecondary, | |
isWhite, | |
isBold, | |
isHeadingTitle, | |
isCenter, | |
hasMargin, | |
style, | |
...rest | |
}) => { | |
// const { primary, secondary, text } = useThemeColors(); | |
const primary = '#FC6A57'; | |
const secondary = '#9b9b9b'; | |
const text = '#333333'; | |
let color = text; | |
let fontSize = 14; | |
let marginTop = 0; | |
let textAlign: 'auto' | 'center' | 'left' | 'right' | 'justify' | undefined; | |
if (isSecondary) { | |
color = secondary; | |
fontSize = 13; | |
} | |
if (isHeadingTitle) { | |
fontSize = 20; | |
} | |
if (isPrimary) { | |
color = primary; | |
} | |
if (isWhite) { | |
color = 'white'; | |
} | |
if (isCenter) { | |
textAlign = 'center'; | |
} | |
if (hasMargin) { | |
marginTop = 10; | |
} | |
const fontWeight = isBold ? 'bold' : 'normal'; | |
return ( | |
<BaseText | |
{...rest} | |
style={[ | |
{ | |
color, | |
fontWeight, | |
fontSize, | |
textAlign, | |
marginTop, | |
}, | |
style, | |
]} | |
> | |
{children} | |
</BaseText> | |
); | |
}; | |
export default Text; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment