195 lines
5.9 KiB
JavaScript
195 lines
5.9 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
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 _reactDom = require('react-dom');
|
|
|
|
var _reactDom2 = _interopRequireDefault(_reactDom);
|
|
|
|
var _shallowEqual = require('recompose/shallowEqual');
|
|
|
|
var _shallowEqual2 = _interopRequireDefault(_shallowEqual);
|
|
|
|
var _autoPrefix = require('../utils/autoPrefix');
|
|
|
|
var _autoPrefix2 = _interopRequireDefault(_autoPrefix);
|
|
|
|
var _transitions = require('../styles/transitions');
|
|
|
|
var _transitions2 = _interopRequireDefault(_transitions);
|
|
|
|
var _ScaleIn = require('./ScaleIn');
|
|
|
|
var _ScaleIn2 = _interopRequireDefault(_ScaleIn);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
var pulsateDuration = 750;
|
|
|
|
var FocusRipple = function (_Component) {
|
|
(0, _inherits3.default)(FocusRipple, _Component);
|
|
|
|
function FocusRipple() {
|
|
var _ref;
|
|
|
|
var _temp, _this, _ret;
|
|
|
|
(0, _classCallCheck3.default)(this, FocusRipple);
|
|
|
|
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 = FocusRipple.__proto__ || (0, _getPrototypeOf2.default)(FocusRipple)).call.apply(_ref, [this].concat(args))), _this), _this.pulsate = function () {
|
|
var innerCircle = _reactDom2.default.findDOMNode(_this.refs.innerCircle);
|
|
if (!innerCircle) return;
|
|
|
|
var startScale = 'scale(1)';
|
|
var endScale = 'scale(0.85)';
|
|
var currentScale = innerCircle.style.transform || startScale;
|
|
var nextScale = currentScale === startScale ? endScale : startScale;
|
|
|
|
_autoPrefix2.default.set(innerCircle.style, 'transform', nextScale);
|
|
_this.timeout = setTimeout(_this.pulsate, pulsateDuration);
|
|
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
|
|
}
|
|
|
|
(0, _createClass3.default)(FocusRipple, [{
|
|
key: 'componentDidMount',
|
|
value: function componentDidMount() {
|
|
if (this.props.show) {
|
|
this.setRippleSize();
|
|
this.pulsate();
|
|
}
|
|
}
|
|
}, {
|
|
key: 'shouldComponentUpdate',
|
|
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
return !(0, _shallowEqual2.default)(this.props, nextProps) || !(0, _shallowEqual2.default)(this.state, nextState);
|
|
}
|
|
}, {
|
|
key: 'componentDidUpdate',
|
|
value: function componentDidUpdate() {
|
|
if (this.props.show) {
|
|
this.setRippleSize();
|
|
this.pulsate();
|
|
} else {
|
|
if (this.timeout) clearTimeout(this.timeout);
|
|
}
|
|
}
|
|
}, {
|
|
key: 'componentWillUnmount',
|
|
value: function componentWillUnmount() {
|
|
clearTimeout(this.timeout);
|
|
}
|
|
}, {
|
|
key: 'getRippleElement',
|
|
value: function getRippleElement(props) {
|
|
var color = props.color,
|
|
innerStyle = props.innerStyle,
|
|
opacity = props.opacity;
|
|
var _context$muiTheme = this.context.muiTheme,
|
|
prepareStyles = _context$muiTheme.prepareStyles,
|
|
ripple = _context$muiTheme.ripple;
|
|
|
|
|
|
var innerStyles = (0, _simpleAssign2.default)({
|
|
position: 'absolute',
|
|
height: '100%',
|
|
width: '100%',
|
|
borderRadius: '50%',
|
|
opacity: opacity ? opacity : 0.16,
|
|
backgroundColor: color || ripple.color,
|
|
transition: _transitions2.default.easeOut(pulsateDuration + 'ms', 'transform', null, _transitions2.default.easeInOutFunction)
|
|
}, innerStyle);
|
|
|
|
return _react2.default.createElement('div', { ref: 'innerCircle', style: prepareStyles((0, _simpleAssign2.default)({}, innerStyles)) });
|
|
}
|
|
}, {
|
|
key: 'setRippleSize',
|
|
value: function setRippleSize() {
|
|
var el = _reactDom2.default.findDOMNode(this.refs.innerCircle);
|
|
var height = el.offsetHeight;
|
|
var width = el.offsetWidth;
|
|
var size = Math.max(height, width);
|
|
|
|
var oldTop = 0;
|
|
// For browsers that don't support endsWith()
|
|
if (el.style.top.indexOf('px', el.style.top.length - 2) !== -1) {
|
|
oldTop = parseInt(el.style.top);
|
|
}
|
|
el.style.height = size + 'px';
|
|
el.style.top = height / 2 - size / 2 + oldTop + 'px';
|
|
}
|
|
}, {
|
|
key: 'render',
|
|
value: function render() {
|
|
var _props = this.props,
|
|
show = _props.show,
|
|
style = _props.style;
|
|
|
|
|
|
var mergedRootStyles = (0, _simpleAssign2.default)({
|
|
height: '100%',
|
|
width: '100%',
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0
|
|
}, style);
|
|
|
|
var ripple = show ? this.getRippleElement(this.props) : null;
|
|
|
|
return _react2.default.createElement(
|
|
_ScaleIn2.default,
|
|
{
|
|
maxScale: 0.85,
|
|
style: mergedRootStyles
|
|
},
|
|
ripple
|
|
);
|
|
}
|
|
}]);
|
|
return FocusRipple;
|
|
}(_react.Component);
|
|
|
|
FocusRipple.contextTypes = {
|
|
muiTheme: _react.PropTypes.object.isRequired
|
|
};
|
|
process.env.NODE_ENV !== "production" ? FocusRipple.propTypes = {
|
|
color: _react.PropTypes.string,
|
|
innerStyle: _react.PropTypes.object,
|
|
opacity: _react.PropTypes.number,
|
|
show: _react.PropTypes.bool,
|
|
style: _react.PropTypes.object
|
|
} : void 0;
|
|
exports.default = FocusRipple; |