UNPKG

choerodon-ui

Version:

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

109 lines (87 loc) 3.15 kB
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 { Children, cloneElement, PureComponent } from 'react'; var TriggerChild = /*#__PURE__*/ function (_PureComponent) { _inherits(TriggerChild, _PureComponent); var _super = _createSuper(TriggerChild); function TriggerChild(props, context) { var _this; _classCallCheck(this, TriggerChild); _this = _super.call(this, props, context); var createChains = function createChains(eventName) { return function (e) { var _this$props = _this.props, handle = _this$props["on".concat(eventName)], children = _this$props.children; var child = Children.only(children); if (handle) { return handle(eventName, child, e); } if (child) { var childHandle = child.props["on".concat(eventName)]; if (childHandle) { return childHandle(e); } } }; }; _this.handleContextMenu = createChains('ContextMenu'); _this.handleClick = createChains('Click'); _this.handleMouseDown = createChains('MouseDown'); _this.handleMouseEnter = createChains('MouseEnter'); _this.handleMouseLeave = createChains('MouseLeave'); _this.handleFocus = createChains('Focus'); _this.handleBlur = createChains('Blur'); _this.handleKeyDown = createChains('KeyDown'); return _this; } _createClass(TriggerChild, [{ key: "render", value: function render() { var children = this.props.children; return cloneElement(Children.only(children), { onContextMenu: this.handleContextMenu, onClick: this.handleClick, onMouseDown: this.handleMouseDown, onMouseEnter: this.handleMouseEnter, onMouseLeave: this.handleMouseLeave, onFocus: this.handleFocus, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown }); } }]); return TriggerChild; }(PureComponent); export { TriggerChild as default }; TriggerChild.displayName = 'TriggerChild'; //# sourceMappingURL=TriggerChild.js.map