154 lines
4.8 KiB
JavaScript
154 lines
4.8 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
|
||
|
|
var _extends2 = require('babel-runtime/helpers/extends');
|
||
|
|
|
||
|
|
var _extends3 = _interopRequireDefault(_extends2);
|
||
|
|
|
||
|
|
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
||
|
|
|
||
|
|
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
||
|
|
|
||
|
|
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
|
||
|
|
|
||
|
|
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
|
||
|
|
|
||
|
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
||
|
|
|
||
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
||
|
|
|
||
|
|
var _createClass2 = require('babel-runtime/helpers/createClass');
|
||
|
|
|
||
|
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
||
|
|
|
||
|
|
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
||
|
|
|
||
|
|
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
||
|
|
|
||
|
|
var _inherits2 = require('babel-runtime/helpers/inherits');
|
||
|
|
|
||
|
|
var _inherits3 = _interopRequireDefault(_inherits2);
|
||
|
|
|
||
|
|
var _simpleAssign = require('simple-assign');
|
||
|
|
|
||
|
|
var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
|
||
|
|
|
||
|
|
var _react = require('react');
|
||
|
|
|
||
|
|
var _react2 = _interopRequireDefault(_react);
|
||
|
|
|
||
|
|
var _transitions = require('../styles/transitions');
|
||
|
|
|
||
|
|
var _transitions2 = _interopRequireDefault(_transitions);
|
||
|
|
|
||
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
|
||
|
|
function getStyles(props, context, state) {
|
||
|
|
var color = props.color,
|
||
|
|
hoverColor = props.hoverColor;
|
||
|
|
var baseTheme = context.muiTheme.baseTheme;
|
||
|
|
|
||
|
|
var offColor = color || baseTheme.palette.textColor;
|
||
|
|
var onColor = hoverColor || offColor;
|
||
|
|
|
||
|
|
return {
|
||
|
|
root: {
|
||
|
|
color: state.hovered ? onColor : offColor,
|
||
|
|
position: 'relative',
|
||
|
|
fontSize: baseTheme.spacing.iconSize,
|
||
|
|
display: 'inline-block',
|
||
|
|
userSelect: 'none',
|
||
|
|
transition: _transitions2.default.easeOut()
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
var FontIcon = function (_Component) {
|
||
|
|
(0, _inherits3.default)(FontIcon, _Component);
|
||
|
|
|
||
|
|
function FontIcon() {
|
||
|
|
var _ref;
|
||
|
|
|
||
|
|
var _temp, _this, _ret;
|
||
|
|
|
||
|
|
(0, _classCallCheck3.default)(this, FontIcon);
|
||
|
|
|
||
|
|
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||
|
|
args[_key] = arguments[_key];
|
||
|
|
}
|
||
|
|
|
||
|
|
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = FontIcon.__proto__ || (0, _getPrototypeOf2.default)(FontIcon)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
||
|
|
hovered: false
|
||
|
|
}, _this.handleMouseLeave = function (event) {
|
||
|
|
// 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(event);
|
||
|
|
}
|
||
|
|
}, _this.handleMouseEnter = function (event) {
|
||
|
|
// 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(event);
|
||
|
|
}
|
||
|
|
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
|
||
|
|
}
|
||
|
|
|
||
|
|
(0, _createClass3.default)(FontIcon, [{
|
||
|
|
key: 'render',
|
||
|
|
value: function render() {
|
||
|
|
var _props = this.props,
|
||
|
|
hoverColor = _props.hoverColor,
|
||
|
|
onMouseLeave = _props.onMouseLeave,
|
||
|
|
onMouseEnter = _props.onMouseEnter,
|
||
|
|
style = _props.style,
|
||
|
|
other = (0, _objectWithoutProperties3.default)(_props, ['hoverColor', 'onMouseLeave', 'onMouseEnter', 'style']);
|
||
|
|
var prepareStyles = this.context.muiTheme.prepareStyles;
|
||
|
|
|
||
|
|
var styles = getStyles(this.props, this.context, this.state);
|
||
|
|
|
||
|
|
return _react2.default.createElement('span', (0, _extends3.default)({}, other, {
|
||
|
|
onMouseLeave: this.handleMouseLeave,
|
||
|
|
onMouseEnter: this.handleMouseEnter,
|
||
|
|
style: prepareStyles((0, _simpleAssign2.default)(styles.root, style))
|
||
|
|
}));
|
||
|
|
}
|
||
|
|
}]);
|
||
|
|
return FontIcon;
|
||
|
|
}(_react.Component);
|
||
|
|
|
||
|
|
FontIcon.muiName = 'FontIcon';
|
||
|
|
FontIcon.defaultProps = {
|
||
|
|
onMouseEnter: function onMouseEnter() {},
|
||
|
|
onMouseLeave: function onMouseLeave() {}
|
||
|
|
};
|
||
|
|
FontIcon.contextTypes = {
|
||
|
|
muiTheme: _react.PropTypes.object.isRequired
|
||
|
|
};
|
||
|
|
process.env.NODE_ENV !== "production" ? FontIcon.propTypes = {
|
||
|
|
/**
|
||
|
|
* This is the font color of the font icon. If not specified,
|
||
|
|
* this component will default to muiTheme.palette.textColor.
|
||
|
|
*/
|
||
|
|
color: _react.PropTypes.string,
|
||
|
|
/**
|
||
|
|
* This is the icon color when the mouse hovers over the icon.
|
||
|
|
*/
|
||
|
|
hoverColor: _react.PropTypes.string,
|
||
|
|
/** @ignore */
|
||
|
|
onMouseEnter: _react.PropTypes.func,
|
||
|
|
/** @ignore */
|
||
|
|
onMouseLeave: _react.PropTypes.func,
|
||
|
|
/**
|
||
|
|
* Override the inline-styles of the root element.
|
||
|
|
*/
|
||
|
|
style: _react.PropTypes.object
|
||
|
|
} : void 0;
|
||
|
|
exports.default = FontIcon;
|