Skip to content

Instantly share code, notes, and snippets.

@pciacka
Last active July 15, 2022 11:11
Show Gist options
  • Save pciacka/bf3c975ef0c8f4e218065d40ec349366 to your computer and use it in GitHub Desktop.
Save pciacka/bf3c975ef0c8f4e218065d40ec349366 to your computer and use it in GitHub Desktop.
Example of React Native default approach to styling components
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
}
});
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