nuke-touchable
Version:
可点击容器
143 lines (112 loc) • 5.02 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
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; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _rax = require('rax');
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; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** @jsx createElement */
var rippleStyle = {
position: 'absolute',
borderRadius: '50%',
opacity: 0,
width: 35,
height: 35,
transform: 'translate(-50%, -50%)',
pointerEvents: 'none'
};
var wrapStyle = {
position: 'relative',
display: 'flex',
flexDirection: 'column',
overflow: 'hidden'
};
var Ripples = function (_PureComponent) {
_inherits(Ripples, _PureComponent);
function Ripples(props, context) {
_classCallCheck(this, Ripples);
var _this = _possibleConstructorReturn(this, (Ripples.__proto__ || Object.getPrototypeOf(Ripples)).call(this, props));
_this.handleClick = function (ev) {
if (ev.stopPropagation) {
ev.stopPropagation();
}
var _this$props = _this.props,
onClick = _this$props.onClick,
color = _this$props.color,
during = _this$props.during;
var pageX = ev.pageX,
pageY = ev.pageY,
_ev$currentTarget = ev.currentTarget,
offsetLeft = _ev$currentTarget.offsetLeft,
offsetTop = _ev$currentTarget.offsetTop,
offsetWidth = _ev$currentTarget.offsetWidth,
offsetHeight = _ev$currentTarget.offsetHeight;
var left = pageX - offsetLeft;
var top = pageY - offsetTop;
_this.setState({
rippleStyle: {
top: top,
left: left,
opacity: 1,
backgroundColor: color
}
});
setTimeout(function () {
var size = Math.max(offsetWidth, offsetHeight);
_this.setState({
rippleStyle: {
top: top,
left: left,
backgroundColor: color,
transition: 'all ' + during + 'ms',
transform: rippleStyle.transform + ' scale(' + size / 9 + ')',
opacity: 0
}
});
}, 50);
if (typeof onClick === 'function') {
onClick(ev);
}
};
_this.state = {
rippleStyle: {}
};
return _this;
}
_createClass(Ripples, [{
key: 'render',
value: function render() {
var _props = this.props,
children = _props.children,
style = _props.style,
during = _props.during,
color = _props.color,
props = _objectWithoutProperties(_props, ['children', 'style', 'during', 'color']);
var state = this.state,
handleClick = this.handleClick;
var s = _extends({}, wrapStyle, style);
return (0, _rax.createElement)(
'div',
_extends({}, props, { style: s, onClick: handleClick }),
children,
(0, _rax.createElement)('s', {
style: _extends({}, rippleStyle, state.rippleStyle)
})
);
}
}]);
return Ripples;
}(_rax.PureComponent);
Ripples.propTypes = {
during: _rax.PropTypes.number,
color: _rax.PropTypes.string
};
Ripples.defaultProps = {
during: 600,
color: 'rgba(0, 0, 0, .3)'
};
exports.default = Ripples;
module.exports = exports['default'];
;