UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

117 lines (97 loc) 3.64 kB
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 _createSuper from "@babel/runtime/helpers/createSuper"; var _excluded = ["prefixCls"]; 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, _excluded); 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(_objectSpread({}, createChains(rest, child.props)), {}, { children: [children, /*#__PURE__*/React.createElement(Animate, { key: "ripple", component: "div", componentProps: _this.getComponentProps(prefixCls), transitionName: size ? 'zoom-small-slow' : 'fade', hiddenProp: "hidden" }, _this.currentCircleStyle && /*#__PURE__*/React.createElement("div", { hidden: !size, className: prefixCls, key: "circle", style: _this.currentCircleStyle }))], style: _this.currentStyle || style }); if (size && size.position === 'static') { newProps.style = _objectSpread(_objectSpread({}, style), {}, { position: 'relative' }); _this.currentStyle = newProps.style; } return /*#__PURE__*/cloneElement(child, newProps); }; _this.ripple = function (child) { if ( /*#__PURE__*/isValidElement(child)) { return /*#__PURE__*/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