Skip to content

Instantly share code, notes, and snippets.

@gauthierm
Last active June 23, 2021 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gauthierm/2f953fe3611f0f5f7754b3b15497497d to your computer and use it in GitHub Desktop.
Save gauthierm/2f953fe3611f0f5f7754b3b15497497d to your computer and use it in GitHub Desktop.
import { StyleSheet } from 'react-native';
import { colors } from '../styles/colors';
import { font } from '../styles/font.styles';
export const styles = StyleSheet.create({
background: {
paddingTop: 8,
paddingRight: 16,
paddingBottom: 8,
paddingLeft: 16,
borderRadius: 6,
},
border: {
borderRadius: 8,
padding: 2,
backgroundColor: colors.brand['05-midtone'],
},
borderActive: {
backgroundColor: colors.blue['07-lighter'],
},
backgroundActive: {},
text: {
textAlign: 'center',
color: colors.neutral['10-white'],
fontSize: 18,
lineHeight: 18,
...font.weight700,
},
});
import React from 'react';
import { Text, Pressable, TextStyle, View, ViewStyle } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import { styles } from './Button.styles';
interface ButtonProps {
title: string;
onPress: () => void;
textStyle?: TextStyle;
backgroundStyle?: ViewStyle;
style?: ViewStyle;
}
const gradient = {
normal: ['#4875bd', '#6a95d9'],
pressed: ['#273854', '#326ac2', '#326ac2', '#326ac2', '#273854'],
};
export function Button({
title,
backgroundStyle,
textStyle,
style,
onPress,
}: ButtonProps) {
return (
<Pressable
style={style}
onPress={onPress}
accessibilityLabel={title}
accessibilityRole="button"
>
{({ pressed }) => (
<View style={[styles.border, pressed && styles.borderActive]}>
<LinearGradient
style={[
styles.background,
backgroundStyle,
pressed && styles.backgroundActive,
]}
colors={pressed ? gradient.pressed : gradient.normal}
>
<Text style={[styles.text, textStyle]}>{title}</Text>
</LinearGradient>
</View>
)}
</Pressable>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment