forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont-icon.jsx
81 lines (68 loc) · 1.83 KB
/
font-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
76
77
78
79
80
81
let React = require('react');
let StylePropable = require('./mixins/style-propable');
let Transitions = require('./styles/transitions');
let FontIcon = React.createClass({
mixins: [StylePropable],
contextTypes: {
muiTheme: React.PropTypes.object,
},
propTypes: {
color: React.PropTypes.string,
hoverColor: React.PropTypes.string,
onMouseLeave: React.PropTypes.func,
onMouseEnter: React.PropTypes.func,
},
getInitialState() {
return {
hovered: false,
};
},
render() {
let {
color,
hoverColor,
onMouseLeave,
onMouseEnter,
style,
...other,
} = this.props;
let spacing = this.context.muiTheme.spacing;
let offColor = color ? color :
style && style.color ? style.color :
this.context.muiTheme.palette.textColor;
let onColor = hoverColor ? hoverColor : offColor;
let mergedStyles = this.mergeAndPrefix({
position: 'relative',
fontSize: spacing.iconSize,
display: 'inline-block',
userSelect: 'none',
transition: Transitions.easeOut(),
}, style, {
color: this.state.hovered ? onColor : offColor,
});
return (
<span
{...other}
onMouseLeave={this._handleMouseLeave}
onMouseEnter={this._handleMouseEnter}
style={mergedStyles} />
);
},
_handleMouseLeave(e) {
// hover is needed only when a hoverColor is defined
if (this.props.hoverColor !== undefined)
this.setState({hovered: false});
if (this.props.onMouseLeave) {
this.props.onMouseLeave(e);
}
},
_handleMouseEnter(e) {
// hover is needed only when a hoverColor is defined
if (this.props.hoverColor !== undefined)
this.setState({hovered: true});
if (this.props.onMouseEnter) {
this.props.onMouseEnter(e);
}
},
});
module.exports = FontIcon;