-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionButton.js
More file actions
93 lines (87 loc) · 2.15 KB
/
ActionButton.js
File metadata and controls
93 lines (87 loc) · 2.15 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
import React from 'react';
import {
TouchableOpacity,
TouchableNativeFeedback,
View,
Platform,
StyleSheet,
} from 'react-native';
import PropTypes from 'prop-types';
import Feather from 'react-native-vector-icons/Feather';
import {useThemeContext} from '../util/ThemeProvider';
const getContainerStyle = ({theme, size, color}) => {
return {
...styles.container,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: theme.brandColor[color],
width: theme.actionButtonSize[size],
height: theme.actionButtonSize[size],
borderRadius: theme.actionButtonSize[size] / 2,
};
};
const ActionButton = ({style, ...props}) => {
const theme = useThemeContext();
const TouchableElement =
Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
return (
<TouchableElement {...props} onPress={props.onPress}>
<View
style={StyleSheet.flatten([
getContainerStyle({...props, theme}),
style,
])}>
{props.icon || (
<Feather
name="plus"
size={theme.iconSize[props.size]}
color={props.iconColor || theme.brandColor.white}
/>
)}
</View>
</TouchableElement>
);
};
ActionButton.propTypes = {
size: PropTypes.oneOf([
'xxsmall',
'xsmall',
'small',
'medium',
'large',
'xlarge',
'xxlarge',
]),
onPress: PropTypes.func.isRequired,
iconColor: PropTypes.string,
color: PropTypes.string,
icon: PropTypes.element,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
};
ActionButton.defaultProps = {
size: 'medium',
color: 'primary',
};
const styles = StyleSheet.create({
container: {
...Platform.select({
android: {
elevation: 3,
},
ios: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.25,
shadowRadius: 3,
},
web: {
// boxShadow: `${offsetWidth}px ${offsetHeight}px ${radius}px ${rgba}`
boxShadow: '0 3px 5px rgba(0,0,0,0.10), 1px 2px 5px rgba(0,0,0,0.10)',
},
}),
},
});
export default ActionButton;