-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Expand file tree
/
Copy pathButton.jsx
More file actions
110 lines (103 loc) · 2.32 KB
/
Copy pathButton.jsx
File metadata and controls
110 lines (103 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import PropTypes from 'prop-types';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
/** Primary UI component for user interaction */
export const Button = ({
primary = false,
size = 'medium',
backgroundColor,
label,
style,
onPress,
}) => {
const modeStyle = primary ? styles.primary : styles.secondary;
const textModeStyle = primary ? styles.primaryText : styles.secondaryText;
const sizeStyle = styles[size];
const textSizeStyle = textSizeStyles[size];
return (
<TouchableOpacity accessibilityRole="button" activeOpacity={0.6} onPress={onPress}>
<View
style={[
styles.button,
modeStyle,
sizeStyle,
style,
!!backgroundColor && { backgroundColor },
{ borderColor: 'black' },
]}
>
<Text style={[textModeStyle, textSizeStyle]}>{label}</Text>
</View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
borderWidth: 0,
borderRadius: 48,
},
buttonText: {
fontWeight: '700',
lineHeight: 1,
},
primary: {
backgroundColor: '#555ab9',
},
primaryText: {
color: 'white',
},
secondary: {
backgroundColor: 'transparent',
borderColor: 'rgba(0, 0, 0, 0.15)',
color: '#333',
borderWidth: 1,
},
secondaryText: {
color: '#333',
},
small: {
paddingVertical: 10,
paddingHorizontal: 16,
},
smallText: {
fontSize: 12,
},
medium: {
paddingVertical: 11,
paddingHorizontal: 20,
},
mediumText: {
fontSize: 14,
},
large: {
paddingVertical: 12,
paddingHorizontal: 24,
},
largeText: {
fontSize: 16,
},
});
const textSizeStyles = {
small: styles.smallText,
medium: styles.mediumText,
large: styles.largeText,
};
Button.propTypes = {
/** Is this the principal call to action on the page? */
primary: PropTypes.bool,
/** What background color to use */
backgroundColor: PropTypes.string,
/** How large should the button be? */
size: PropTypes.oneOf(['small', 'medium', 'large']),
/** Button contents */
label: PropTypes.string.isRequired,
/** Optional click handler */
onPress: PropTypes.func,
/** Optional extra styles */
style: PropTypes.object,
};
Button.defaultProps = {
backgroundColor: null,
primary: false,
size: 'medium',
onClick: undefined,
};