UNPKG

choerodon-ui

Version:

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

125 lines (100 loc) 3.26 kB
import _extends from "@babel/runtime/helpers/extends"; 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 { cloneElement, PureComponent } from 'react'; import PropTypes from 'prop-types'; function wrapEvent(element, eventName, callback) { return function (e) { var originalEvent = element.props[eventName]; if (originalEvent) { originalEvent(e); } callback(e); }; } var MouseDown = /*#__PURE__*/ function (_PureComponent) { _inherits(MouseDown, _PureComponent); var _super = _createSuper(MouseDown); function MouseDown() { var _this; _classCallCheck(this, MouseDown); _this = _super.apply(this, arguments); _this.state = {}; _this.show = function (e) { var currentTarget = e.currentTarget; var pos = currentTarget.getBoundingClientRect(); _this.setState({ size: { x: e.clientX - pos.left, y: e.clientY - pos.top, width: currentTarget.clientWidth, height: currentTarget.clientHeight, position: document.defaultView && document.defaultView.getComputedStyle(currentTarget).position } }); }; _this.hide = function () { _this.setState({ size: undefined }); }; return _this; } _createClass(MouseDown, [{ key: "render", value: function render() { var _this$props = this.props, children = _this$props.children, rippleChild = _this$props.rippleChild; var size = this.state.size; var element = children(rippleChild, size); var newProps = { onMouseDown: wrapEvent(element, 'onMouseDown', this.show) }; if (size) { _extends(newProps, { onMouseUp: wrapEvent(element, 'onMouseUp', this.hide), onMouseLeave: wrapEvent(element, 'onMouseLeave', this.hide), onDragEnd: wrapEvent(element, 'onDragEnd', this.hide) }); } return cloneElement(element, newProps); } }]); return MouseDown; }(PureComponent); export { MouseDown as default }; MouseDown.displayName = 'MouseDown'; MouseDown.propTypes = { rippleChild: PropTypes.node }; //# sourceMappingURL=MouseDown.js.map