-
Notifications
You must be signed in to change notification settings - Fork 31
/
ActionButton.js
67 lines (61 loc) · 1.68 KB
/
ActionButton.js
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
import PropTypes from 'prop-types';
import React from 'react';
import {
Platform,
StyleSheet,
TouchableNativeFeedback,
TouchableOpacity,
View,
} from 'react-native';
import Feather from 'react-native-vector-icons/Feather';
import {shadows, sizes} from '../util/prop-types';
import {useThemeContext} from '../util/ThemeProvider';
const getContainerStyle = ({theme, size, color, shadow}) => {
return {
...theme.shadow[shadow],
justifyContent: 'center',
alignItems: 'center',
backgroundColor: theme.colors[color],
width: theme.actionButtonSize[size],
height: theme.actionButtonSize[size],
borderRadius: theme.actionButtonSize[size] / 2,
};
};
const ActionButton = React.forwardRef(({style, ...props}, ref) => {
const theme = useThemeContext();
const TouchableElement =
Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
return (
<TouchableElement {...props} onPress={props.onPress} ref={ref}>
<View
style={StyleSheet.flatten([
getContainerStyle({...props, theme}),
style,
])}>
{props.icon || (
<Feather
name="plus"
size={theme.size[props.size]}
color={theme.colors[props.iconColor]}
/>
)}
</View>
</TouchableElement>
);
});
ActionButton.propTypes = {
size: sizes,
onPress: PropTypes.func.isRequired,
iconColor: PropTypes.string,
color: PropTypes.string,
icon: PropTypes.element,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
shadow: shadows,
};
ActionButton.defaultProps = {
size: 'md',
color: 'primary',
shadow: 'md',
iconColor: 'white',
};
export default ActionButton;