Last active
July 15, 2022 11:11
-
-
Save przemekciacka/bf3c975ef0c8f4e218065d40ec349366 to your computer and use it in GitHub Desktop.
Example of React Native default approach to styling components
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'; | |
function Card({ children }: PropsWithChildren<unknown>) { | |
return ( | |
<View style={styles.cardContainer}> | |
{children} | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
cardContainer: { | |
backgroundColor: 'rgba(255, 255, 255, 1)', | |
borderRadius: 20, | |
padding: 16 | |
} | |
}); |
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 { Text as RNText } from 'react-native'; | |
type TextProps = { | |
variant?: 'body' | 'overline'; | |
}; | |
function Text({ variant = 'body' }: PropsWithChildren<TextProps>) { | |
const style = variant === 'body' ? styles.variantBody : styles.variantOverline; | |
return <RNText style={style}>{children}</RNText>; | |
} | |
const styles = StyleSheet.create({ | |
variantBody: { | |
color: 'rgba(0, 0, 0, 1)', | |
fontSize: 12, | |
fontWeight: 500, | |
textTransform: 'uppercase' | |
}, | |
variantOverline: { | |
color: 'rgba(151, 151, 151, 1)', | |
fontSize: 16, | |
fontWeight: 700 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment