rc-trigger
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -17,6 +17,2 @@ 'use strict'; | ||
var _createChainedFunction = require('rc-util/lib/createChainedFunction'); | ||
var _createChainedFunction2 = _interopRequireDefault(_createChainedFunction); | ||
var _contains = require('rc-util/lib/Dom/contains'); | ||
@@ -54,3 +50,4 @@ | ||
propTypes: { | ||
action: _react.PropTypes.any, | ||
children: _react.PropTypes.any, | ||
action: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.arrayOf(_react.PropTypes.string)]), | ||
showAction: _react.PropTypes.any, | ||
@@ -102,6 +99,6 @@ hideAction: _react.PropTypes.any, | ||
if (instance.isMouseEnterToShow()) { | ||
mouseProps.onMouseEnter = instance.onMouseEnter; | ||
mouseProps.onMouseEnter = instance.onPopupMouseEnter; | ||
} | ||
if (instance.isMouseLeaveToHide()) { | ||
mouseProps.onMouseLeave = instance.onMouseLeave; | ||
mouseProps.onMouseLeave = instance.onPopupMouseLeave; | ||
} | ||
@@ -168,2 +165,11 @@ return _react2["default"].createElement( | ||
}, | ||
componentWillMount: function componentWillMount() { | ||
var _this = this; | ||
ALL_HANDLERS.forEach(function (h) { | ||
_this['fire' + h] = function (e) { | ||
_this.fireEvents(h, e); | ||
}; | ||
}); | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
@@ -216,9 +222,17 @@ this.componentDidUpdate({}, { | ||
}, | ||
onMouseEnter: function onMouseEnter() { | ||
onMouseEnter: function onMouseEnter(e) { | ||
this.fireEvents('onMouseEnter', e); | ||
this.delaySetPopupVisible(true, this.props.mouseEnterDelay); | ||
}, | ||
onMouseLeave: function onMouseLeave(e) { | ||
this.fireEvents('onMouseLeave', e); | ||
this.delaySetPopupVisible(false, this.props.mouseLeaveDelay); | ||
}, | ||
onPopupMouseEnter: function onPopupMouseEnter() { | ||
this.clearDelayTimer(); | ||
}, | ||
onPopupMouseLeave: function onPopupMouseLeave(e) { | ||
// https://github.com/react-component/trigger/pull/13 | ||
// react bug? | ||
if (e.relatedTarget && !e.relatedTarget.setTimeout && (0, _contains2["default"])(this.popupContainer, e.relatedTarget)) { | ||
if (e.relatedTarget && !e.relatedTarget.setTimeout && this._component && (0, _contains2["default"])(this._component.getPopupDomNode(), e.relatedTarget)) { | ||
return; | ||
@@ -228,3 +242,4 @@ } | ||
}, | ||
onFocus: function onFocus() { | ||
onFocus: function onFocus(e) { | ||
this.fireEvents('onFocus', e); | ||
// incase focusin and focusout | ||
@@ -237,9 +252,12 @@ this.clearDelayTimer(); | ||
}, | ||
onMouseDown: function onMouseDown() { | ||
onMouseDown: function onMouseDown(e) { | ||
this.fireEvents('onMouseDown', e); | ||
this.preClickTime = Date.now(); | ||
}, | ||
onTouchStart: function onTouchStart() { | ||
onTouchStart: function onTouchStart(e) { | ||
this.fireEvents('onTouchStart', e); | ||
this.preTouchTime = Date.now(); | ||
}, | ||
onBlur: function onBlur() { | ||
onBlur: function onBlur(e) { | ||
this.fireEvents('onBlur', e); | ||
this.clearDelayTimer(); | ||
@@ -251,2 +269,3 @@ if (this.isBlurToHide()) { | ||
onClick: function onClick(event) { | ||
this.fireEvents('onClick', event); | ||
// focus will trigger click | ||
@@ -331,3 +350,3 @@ if (this.focusTime) { | ||
delaySetPopupVisible: function delaySetPopupVisible(visible, delayS) { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -338,4 +357,4 @@ var delay = delayS * 1000; | ||
this.delayTimer = setTimeout(function () { | ||
_this.setPopupVisible(visible); | ||
_this.clearDelayTimer(); | ||
_this2.setPopupVisible(visible); | ||
_this2.clearDelayTimer(); | ||
}, delay); | ||
@@ -352,2 +371,10 @@ } else { | ||
}, | ||
createTwoChains: function createTwoChains(event) { | ||
var childPros = this.props.children.props; | ||
var props = this.props; | ||
if (childPros[event] && props[event]) { | ||
return this['fire' + event]; | ||
} | ||
return childPros[event] || props[event]; | ||
}, | ||
isClickToShow: function isClickToShow() { | ||
@@ -400,2 +427,12 @@ var _props = this.props; | ||
}, | ||
fireEvents: function fireEvents(type, e) { | ||
var childCallback = this.props.children.props[type]; | ||
if (childCallback) { | ||
childCallback(e); | ||
} | ||
var callback = this.props[type]; | ||
if (callback) { | ||
callback(e); | ||
} | ||
}, | ||
render: function render() { | ||
@@ -405,33 +442,31 @@ var props = this.props; | ||
var child = _react2["default"].Children.only(children); | ||
var childProps = child.props || {}; | ||
var newChildProps = {}; | ||
if (this.isClickToHide() || this.isClickToShow()) { | ||
newChildProps.onClick = (0, _createChainedFunction2["default"])(this.onClick, childProps.onClick); | ||
newChildProps.onMouseDown = (0, _createChainedFunction2["default"])(this.onMouseDown, childProps.onMouseDown); | ||
newChildProps.onTouchStart = (0, _createChainedFunction2["default"])(this.onTouchStart, childProps.onTouchStart); | ||
newChildProps.onClick = this.onClick; | ||
newChildProps.onMouseDown = this.onMouseDown; | ||
newChildProps.onTouchStart = this.onTouchStart; | ||
} else { | ||
newChildProps.onClick = this.createTwoChains('onClick'); | ||
newChildProps.onMouseDown = this.createTwoChains('onMouseDown'); | ||
newChildProps.onTouchStart = this.createTwoChains('onTouchStart'); | ||
} | ||
if (this.isMouseEnterToShow()) { | ||
newChildProps.onMouseEnter = (0, _createChainedFunction2["default"])(this.onMouseEnter, childProps.onMouseEnter); | ||
newChildProps.onMouseEnter = this.onMouseEnter; | ||
} else { | ||
newChildProps.onMouseEnter = this.createTwoChains('onMouseEnter'); | ||
} | ||
if (this.isMouseLeaveToHide()) { | ||
newChildProps.onMouseLeave = (0, _createChainedFunction2["default"])(this.onMouseLeave, childProps.onMouseLeave); | ||
newChildProps.onMouseLeave = this.onMouseLeave; | ||
} else { | ||
newChildProps.onMouseLeave = this.createTwoChains('onMouseLeave'); | ||
} | ||
if (this.isFocusToShow() || this.isBlurToHide()) { | ||
newChildProps.onFocus = (0, _createChainedFunction2["default"])(this.onFocus, childProps.onFocus); | ||
newChildProps.onBlur = (0, _createChainedFunction2["default"])(this.onBlur, childProps.onBlur); | ||
newChildProps.onFocus = this.onFocus; | ||
newChildProps.onBlur = this.onBlur; | ||
} else { | ||
newChildProps.onFocus = this.createTwoChains('onFocus'); | ||
newChildProps.onBlur = this.createTwoChains('onBlur'); | ||
} | ||
ALL_HANDLERS.forEach(function (handler) { | ||
var newFn = void 0; | ||
if (props[handler] && newChildProps[handler]) { | ||
newFn = (0, _createChainedFunction2["default"])(props[handler], newChildProps[handler]); | ||
} else { | ||
newFn = props[handler] || newChildProps[handler]; | ||
} | ||
if (newFn) { | ||
newChildProps[handler] = newFn; | ||
} | ||
}); | ||
return _react2["default"].cloneElement(child, newChildProps); | ||
@@ -438,0 +473,0 @@ } |
{ | ||
"name": "rc-trigger", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "base abstract trigger component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41020
918