choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
150 lines (123 loc) • 4.38 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Children, cloneElement, isValidElement, PureComponent } from 'react';
import Animate from '../animate';
import createChains from '../_util/createChains';
import MouseDown from './MouseDown';
var RippleChild =
/*#__PURE__*/
function (_PureComponent) {
_inherits(RippleChild, _PureComponent);
var _super = _createSuper(RippleChild);
function RippleChild() {
var _this;
_classCallCheck(this, RippleChild);
_this = _super.apply(this, arguments);
_this.handleMouseDown = function (child, size) {
var _this$props = _this.props,
prefixCls = _this$props.prefixCls,
rest = _objectWithoutProperties(_this$props, ["prefixCls"]);
var _child$props = child.props,
children = _child$props.children,
style = _child$props.style;
if (size) {
var x = size.x,
y = size.y,
width = size.width,
height = size.height;
var maxWidth = Math.max(width - x, x);
var maxHeight = Math.max(height - y, y);
var max = Math.sqrt(maxWidth * maxWidth + maxHeight * maxHeight);
_this.currentCircleStyle = {
width: max + max,
height: max + max,
left: x - max,
top: y - max
};
}
var newProps = _objectSpread({}, createChains(rest, child.props), {
children: [children, React.createElement(Animate, {
key: "ripple",
component: "div",
componentProps: _this.getComponentProps(prefixCls),
transitionName: size ? 'zoom-small-slow' : 'fade',
hiddenProp: "hidden"
}, _this.currentCircleStyle && React.createElement("div", {
hidden: !size,
className: prefixCls,
key: "circle",
style: _this.currentCircleStyle
}))],
style: _this.currentStyle || style
});
if (size && size.position === 'static') {
newProps.style = _objectSpread({}, style, {
position: 'relative'
});
_this.currentStyle = newProps.style;
}
return cloneElement(child, newProps);
};
_this.ripple = function (child) {
if (isValidElement(child)) {
return React.createElement(MouseDown, {
rippleChild: child
}, _this.handleMouseDown);
}
return child;
};
return _this;
}
_createClass(RippleChild, [{
key: "render",
value: function render() {
var children = this.props.children;
return this.ripple(Children.only(children));
}
}, {
key: "getComponentProps",
value: function getComponentProps(prefixCls) {
var className = "".concat(prefixCls, "-wrapper");
var componentProps = this.componentProps;
if (!componentProps || className !== componentProps.className) {
this.componentProps = {
className: className
};
}
return this.componentProps;
}
}]);
return RippleChild;
}(PureComponent);
export { RippleChild as default };
RippleChild.displayName = 'RippleChild';
//# sourceMappingURL=RippleChild.js.map