UNPKG

choerodon-ui

Version:

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

75 lines (60 loc) 2.29 kB
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"; 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 /*#__PURE__*/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