-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathicon-button.js
89 lines (79 loc) · 2.13 KB
/
icon-button.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import isString from 'lodash/isString';
import omit from 'lodash/omit';
import pick from 'lodash/pick';
import React, {
Component,
PropTypes,
} from 'react';
import {
StyleSheet,
Text,
TouchableHighlight,
View,
} from './react-native';
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
padding: 8,
},
touchable: {
overflow: 'hidden',
},
icon: {
marginRight: 10,
},
text: {
fontWeight: '600',
backgroundColor: 'transparent',
},
});
const IOS7_BLUE = '#007AFF';
export default function createIconButtonComponent(Icon) {
return class IconButton extends Component {
static propTypes = {
...View.propTypes,
backgroundColor: PropTypes.string,
borderRadius: PropTypes.number,
color: PropTypes.string,
size: PropTypes.number,
};
static defaultProps = {
backgroundColor: IOS7_BLUE,
borderRadius: 5,
color: 'white',
size: 20,
};
render() {
const { style, iconStyle, children, ...restProps } = this.props;
const iconProps = pick(restProps, Object.keys(Text.propTypes), 'style', 'name', 'size', 'color');
const touchableProps = pick(restProps, Object.keys(TouchableHighlight.propTypes));
const props = omit(
restProps,
Object.keys(iconProps),
Object.keys(touchableProps),
'iconStyle',
'borderRadius',
'backgroundColor'
);
iconProps.style = (iconStyle ? [styles.icon, iconStyle] : styles.icon);
const colorStyle = pick(this.props, 'color');
const blockStyle = pick(this.props, 'backgroundColor', 'borderRadius');
return (
<TouchableHighlight style={[styles.touchable, blockStyle]} {...touchableProps}>
<View
style={[styles.container, blockStyle, style]}
{...props}
>
<Icon {...iconProps} />
{isString(children)
? (<Text style={[styles.text, colorStyle]}>{children}</Text>)
: children
}
</View>
</TouchableHighlight>
);
}
};
}