forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont-icon.js
80 lines (64 loc) · 2.61 KB
/
font-icon.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
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
var React = require('react');
var StylePropable = require('./mixins/style-propable');
var Transitions = require('./styles/transitions');
var FontIcon = React.createClass({
displayName: 'FontIcon',
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: function getInitialState() {
return {
hovered: false
};
},
render: function render() {
var _props = this.props;
var color = _props.color;
var hoverColor = _props.hoverColor;
var onMouseLeave = _props.onMouseLeave;
var onMouseEnter = _props.onMouseEnter;
var style = _props.style;
var other = _objectWithoutProperties(_props, ['color', 'hoverColor', 'onMouseLeave', 'onMouseEnter', 'style']);
var spacing = this.context.muiTheme.spacing;
var offColor = color ? color : style && style.color ? style.color : this.context.muiTheme.palette.textColor;
var onColor = hoverColor ? hoverColor : offColor;
var mergedStyles = this.mergeAndPrefix({
position: 'relative',
fontSize: spacing.iconSize,
display: 'inline-block',
userSelect: 'none',
transition: Transitions.easeOut()
}, style, {
color: this.state.hovered ? onColor : offColor
});
return React.createElement('span', _extends({}, other, {
onMouseLeave: this._handleMouseLeave,
onMouseEnter: this._handleMouseEnter,
style: mergedStyles }));
},
_handleMouseLeave: function _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: function _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;