forked from bitshares/bitshares-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Icon.jsx
75 lines (68 loc) · 2.24 KB
/
Icon.jsx
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
// look for more icons here https://linearicons.com/free or here http://hawcons.com/preview/
import React from "react";
import counterpart from "counterpart";
import PropTypes from "prop-types";
import iconsMap from "../../assets/icons/icons-loader.js";
require("./icon.scss");
class Icon extends React.Component {
shouldComponentUpdate(np) {
return (
np.className !== this.props.className ||
np.name !== this.props.name ||
np.title !== this.props.title ||
np.size !== this.props.size
);
}
render() {
let classes = "icon ";
if (this.props.name !== "warning") {
// fixme remove warning, otherwise color is being overwritten. should be handled by adjusting the CSS instead
classes = classes + this.props.name;
}
if (this.props.size) {
classes += " icon-" + this.props.size;
}
if (this.props.className) {
classes += " " + this.props.className;
}
if (this.props.title != null) {
let title = this.props.title;
if (typeof title === "string" && title.indexOf(".") > 0) {
title = counterpart.translate(title);
}
return (
<span
title={title}
className={classes}
style={this.props.style || {}}
dangerouslySetInnerHTML={{
__html: iconsMap[this.props.name]
}}
onClick={this.props.onClick}
/>
);
} else {
return (
<span
className={classes}
style={this.props.style || {}}
dangerouslySetInnerHTML={{
__html: iconsMap[this.props.name]
}}
onClick={this.props.onClick}
/>
);
}
}
}
Icon.propTypes = {
name: PropTypes.string.isRequired,
title: PropTypes.string,
size: PropTypes.oneOf(["1x", "1_5x", "2x", "3x", "4x", "5x", "10x"]),
inverse: PropTypes.bool,
className: PropTypes.string
};
Icon.defaultProps = {
title: null
};
export default Icon;