-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.js
87 lines (74 loc) · 2.69 KB
/
index.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
import React, {PureComponent} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
import themeColors from '../../styles/themes/default';
import variables from '../../styles/variables';
import * as StyleUtils from '../../styles/StyleUtils';
import IconWrapperStyles from './IconWrapperStyles';
const propTypes = {
/** The asset to render. */
src: PropTypes.func.isRequired,
/** The width of the icon. */
width: PropTypes.number,
/** The height of the icon. */
height: PropTypes.number,
/** The fill color for the icon. Can be hex, rgb, rgba, or valid react-native named color such as 'red' or 'blue'. */
fill: PropTypes.string,
/** Is small icon */
small: PropTypes.bool,
/** Is inline icon */
inline: PropTypes.bool,
// eslint-disable-next-line react/forbid-prop-types
additionalStyles: PropTypes.arrayOf(PropTypes.object),
};
const defaultProps = {
width: variables.iconSizeNormal,
height: variables.iconSizeNormal,
fill: themeColors.icon,
small: false,
inline: false,
additionalStyles: [],
};
// We must use a class component to create an animatable component with the Animated API
// eslint-disable-next-line react/prefer-stateless-function
class Icon extends PureComponent {
render() {
const width = this.props.small ? variables.iconSizeSmall : this.props.width;
const height = this.props.small ? variables.iconSizeSmall : this.props.height;
const iconStyles = [StyleUtils.getWidthAndHeightStyle(width, height), IconWrapperStyles, styles.pAbsolute,
...this.props.additionalStyles,
];
if (this.props.inline) {
return (
<View
testID={`${this.props.src.name} Icon`}
style={[StyleUtils.getWidthAndHeightStyle(width, height), styles.bgTransparent, styles.overflowVisible]}
>
<View style={iconStyles}>
<this.props.src
width={width}
height={height}
fill={this.props.fill}
/>
</View>
</View>
);
}
return (
<View
testID={`${this.props.src.name} Icon`}
style={this.props.additionalStyles}
>
<this.props.src
width={width}
height={height}
fill={this.props.fill}
/>
</View>
);
}
}
Icon.propTypes = propTypes;
Icon.defaultProps = defaultProps;
export default Icon;