choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
149 lines (117 loc) • 4.46 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _react = _interopRequireWildcard(require("react"));
var _animate = _interopRequireDefault(require("../animate"));
var _MouseDown = _interopRequireDefault(require("./MouseDown"));
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 = (0, _getPrototypeOf2["default"])(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return (0, _possibleConstructorReturn2["default"])(this, result);
};
}
var RippleChild =
/*#__PURE__*/
function (_PureComponent) {
(0, _inherits2["default"])(RippleChild, _PureComponent);
var _super = _createSuper(RippleChild);
function RippleChild() {
var _this;
(0, _classCallCheck2["default"])(this, RippleChild);
_this = _super.apply(this, arguments);
_this.handleMouseDown = function (child, size) {
var prefixCls = _this.props.prefixCls;
var _child$props = child.props,
children = _child$props.children,
style = _child$props.style;
var componentProps = {
className: "".concat(prefixCls, "-wrapper")
};
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 = {
children: [children, _react["default"].createElement(_animate["default"], {
key: "ripple",
component: "div",
componentProps: componentProps,
transitionName: size ? 'zoom-small-slow' : 'fade',
hiddenProp: "hidden"
}, _this.currentCircleStyle && _react["default"].createElement("div", {
hidden: !size,
className: prefixCls,
key: "circle",
style: _this.currentCircleStyle
}))],
style: _this.currentStyle || style
};
if (size && size.position === 'static') {
newProps.style = (0, _objectSpread2["default"])({}, style, {
position: 'relative'
});
_this.currentStyle = newProps.style;
}
return (0, _react.cloneElement)(child, newProps);
};
_this.ripple = function (child) {
if ((0, _react.isValidElement)(child)) {
return _react["default"].createElement(_MouseDown["default"], {
rippleChild: child
}, _this.handleMouseDown);
}
return child;
};
return _this;
}
(0, _createClass2["default"])(RippleChild, [{
key: "render",
value: function render() {
var children = this.props.children;
return this.ripple(_react.Children.only(children));
}
}]);
return RippleChild;
}(_react.PureComponent);
exports["default"] = RippleChild;
RippleChild.displayName = 'RippleChild';
//# sourceMappingURL=RippleChild.js.map