Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

774 lignes
24 KiB

  1. 'use strict';
  2. exports.__esModule = true;
  3. var _extends2 = require('babel-runtime/helpers/extends');
  4. var _extends3 = _interopRequireDefault(_extends2);
  5. var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
  6. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  7. var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
  8. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  9. var _inherits2 = require('babel-runtime/helpers/inherits');
  10. var _inherits3 = _interopRequireDefault(_inherits2);
  11. var _react = require('react');
  12. var _react2 = _interopRequireDefault(_react);
  13. var _propTypes = require('prop-types');
  14. var _propTypes2 = _interopRequireDefault(_propTypes);
  15. var _reactDom = require('react-dom');
  16. var _reactLifecyclesCompat = require('react-lifecycles-compat');
  17. var _contains = require('rc-util/lib/Dom/contains');
  18. var _contains2 = _interopRequireDefault(_contains);
  19. var _addEventListener = require('rc-util/lib/Dom/addEventListener');
  20. var _addEventListener2 = _interopRequireDefault(_addEventListener);
  21. var _ContainerRender = require('rc-util/lib/ContainerRender');
  22. var _ContainerRender2 = _interopRequireDefault(_ContainerRender);
  23. var _Portal = require('rc-util/lib/Portal');
  24. var _Portal2 = _interopRequireDefault(_Portal);
  25. var _classnames = require('classnames');
  26. var _classnames2 = _interopRequireDefault(_classnames);
  27. var _utils = require('./utils');
  28. var _Popup = require('./Popup');
  29. var _Popup2 = _interopRequireDefault(_Popup);
  30. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  31. function noop() {}
  32. function returnEmptyString() {
  33. return '';
  34. }
  35. function returnDocument() {
  36. return window.document;
  37. }
  38. var ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter', 'onMouseLeave', 'onFocus', 'onBlur', 'onContextMenu'];
  39. var IS_REACT_16 = !!_reactDom.createPortal;
  40. var contextTypes = {
  41. rcTrigger: _propTypes2['default'].shape({
  42. onPopupMouseDown: _propTypes2['default'].func
  43. })
  44. };
  45. var Trigger = function (_React$Component) {
  46. (0, _inherits3['default'])(Trigger, _React$Component);
  47. function Trigger(props) {
  48. (0, _classCallCheck3['default'])(this, Trigger);
  49. var _this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call(this, props));
  50. _initialiseProps.call(_this);
  51. var popupVisible = void 0;
  52. if ('popupVisible' in props) {
  53. popupVisible = !!props.popupVisible;
  54. } else {
  55. popupVisible = !!props.defaultPopupVisible;
  56. }
  57. _this.state = {
  58. prevPopupVisible: popupVisible,
  59. popupVisible: popupVisible
  60. };
  61. ALL_HANDLERS.forEach(function (h) {
  62. _this['fire' + h] = function (e) {
  63. _this.fireEvents(h, e);
  64. };
  65. });
  66. return _this;
  67. }
  68. Trigger.prototype.getChildContext = function getChildContext() {
  69. return {
  70. rcTrigger: {
  71. onPopupMouseDown: this.onPopupMouseDown
  72. }
  73. };
  74. };
  75. Trigger.prototype.componentDidMount = function componentDidMount() {
  76. this.componentDidUpdate({}, {
  77. popupVisible: this.state.popupVisible
  78. });
  79. };
  80. Trigger.prototype.componentDidUpdate = function componentDidUpdate(_, prevState) {
  81. var props = this.props;
  82. var state = this.state;
  83. var triggerAfterPopupVisibleChange = function triggerAfterPopupVisibleChange() {
  84. if (prevState.popupVisible !== state.popupVisible) {
  85. props.afterPopupVisibleChange(state.popupVisible);
  86. }
  87. };
  88. if (!IS_REACT_16) {
  89. this.renderComponent(null, triggerAfterPopupVisibleChange);
  90. }
  91. // We must listen to `mousedown` or `touchstart`, edge case:
  92. // https://github.com/ant-design/ant-design/issues/5804
  93. // https://github.com/react-component/calendar/issues/250
  94. // https://github.com/react-component/trigger/issues/50
  95. if (state.popupVisible) {
  96. var currentDocument = void 0;
  97. if (!this.clickOutsideHandler && (this.isClickToHide() || this.isContextMenuToShow())) {
  98. currentDocument = props.getDocument();
  99. this.clickOutsideHandler = (0, _addEventListener2['default'])(currentDocument, 'mousedown', this.onDocumentClick);
  100. }
  101. // always hide on mobile
  102. if (!this.touchOutsideHandler) {
  103. currentDocument = currentDocument || props.getDocument();
  104. this.touchOutsideHandler = (0, _addEventListener2['default'])(currentDocument, 'touchstart', this.onDocumentClick);
  105. }
  106. // close popup when trigger type contains 'onContextMenu' and document is scrolling.
  107. if (!this.contextMenuOutsideHandler1 && this.isContextMenuToShow()) {
  108. currentDocument = currentDocument || props.getDocument();
  109. this.contextMenuOutsideHandler1 = (0, _addEventListener2['default'])(currentDocument, 'scroll', this.onContextMenuClose);
  110. }
  111. // close popup when trigger type contains 'onContextMenu' and window is blur.
  112. if (!this.contextMenuOutsideHandler2 && this.isContextMenuToShow()) {
  113. this.contextMenuOutsideHandler2 = (0, _addEventListener2['default'])(window, 'blur', this.onContextMenuClose);
  114. }
  115. return;
  116. }
  117. this.clearOutsideHandler();
  118. };
  119. Trigger.prototype.componentWillUnmount = function componentWillUnmount() {
  120. this.clearDelayTimer();
  121. this.clearOutsideHandler();
  122. clearTimeout(this.mouseDownTimeout);
  123. };
  124. Trigger.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) {
  125. var popupVisible = _ref.popupVisible;
  126. var newState = {};
  127. if (popupVisible !== undefined && prevState.popupVisible !== popupVisible) {
  128. newState.popupVisible = popupVisible;
  129. newState.prevPopupVisible = prevState.popupVisible;
  130. }
  131. return newState;
  132. };
  133. Trigger.prototype.getPopupDomNode = function getPopupDomNode() {
  134. // for test
  135. if (this._component && this._component.getPopupDomNode) {
  136. return this._component.getPopupDomNode();
  137. }
  138. return null;
  139. };
  140. Trigger.prototype.getPopupAlign = function getPopupAlign() {
  141. var props = this.props;
  142. var popupPlacement = props.popupPlacement,
  143. popupAlign = props.popupAlign,
  144. builtinPlacements = props.builtinPlacements;
  145. if (popupPlacement && builtinPlacements) {
  146. return (0, _utils.getAlignFromPlacement)(builtinPlacements, popupPlacement, popupAlign);
  147. }
  148. return popupAlign;
  149. };
  150. /**
  151. * @param popupVisible Show or not the popup element
  152. * @param event SyntheticEvent, used for `pointAlign`
  153. */
  154. Trigger.prototype.setPopupVisible = function setPopupVisible(popupVisible, event) {
  155. var alignPoint = this.props.alignPoint;
  156. var prevPopupVisible = this.state.popupVisible;
  157. this.clearDelayTimer();
  158. if (prevPopupVisible !== popupVisible) {
  159. if (!('popupVisible' in this.props)) {
  160. this.setState({ popupVisible: popupVisible, prevPopupVisible: prevPopupVisible });
  161. }
  162. this.props.onPopupVisibleChange(popupVisible);
  163. }
  164. // Always record the point position since mouseEnterDelay will delay the show
  165. if (alignPoint && event) {
  166. this.setPoint(event);
  167. }
  168. };
  169. Trigger.prototype.delaySetPopupVisible = function delaySetPopupVisible(visible, delayS, event) {
  170. var _this2 = this;
  171. var delay = delayS * 1000;
  172. this.clearDelayTimer();
  173. if (delay) {
  174. var point = event ? { pageX: event.pageX, pageY: event.pageY } : null;
  175. this.delayTimer = setTimeout(function () {
  176. _this2.setPopupVisible(visible, point);
  177. _this2.clearDelayTimer();
  178. }, delay);
  179. } else {
  180. this.setPopupVisible(visible, event);
  181. }
  182. };
  183. Trigger.prototype.clearDelayTimer = function clearDelayTimer() {
  184. if (this.delayTimer) {
  185. clearTimeout(this.delayTimer);
  186. this.delayTimer = null;
  187. }
  188. };
  189. Trigger.prototype.clearOutsideHandler = function clearOutsideHandler() {
  190. if (this.clickOutsideHandler) {
  191. this.clickOutsideHandler.remove();
  192. this.clickOutsideHandler = null;
  193. }
  194. if (this.contextMenuOutsideHandler1) {
  195. this.contextMenuOutsideHandler1.remove();
  196. this.contextMenuOutsideHandler1 = null;
  197. }
  198. if (this.contextMenuOutsideHandler2) {
  199. this.contextMenuOutsideHandler2.remove();
  200. this.contextMenuOutsideHandler2 = null;
  201. }
  202. if (this.touchOutsideHandler) {
  203. this.touchOutsideHandler.remove();
  204. this.touchOutsideHandler = null;
  205. }
  206. };
  207. Trigger.prototype.createTwoChains = function createTwoChains(event) {
  208. var childPros = this.props.children.props;
  209. var props = this.props;
  210. if (childPros[event] && props[event]) {
  211. return this['fire' + event];
  212. }
  213. return childPros[event] || props[event];
  214. };
  215. Trigger.prototype.isClickToShow = function isClickToShow() {
  216. var _props = this.props,
  217. action = _props.action,
  218. showAction = _props.showAction;
  219. return action.indexOf('click') !== -1 || showAction.indexOf('click') !== -1;
  220. };
  221. Trigger.prototype.isContextMenuToShow = function isContextMenuToShow() {
  222. var _props2 = this.props,
  223. action = _props2.action,
  224. showAction = _props2.showAction;
  225. return action.indexOf('contextMenu') !== -1 || showAction.indexOf('contextMenu') !== -1;
  226. };
  227. Trigger.prototype.isClickToHide = function isClickToHide() {
  228. var _props3 = this.props,
  229. action = _props3.action,
  230. hideAction = _props3.hideAction;
  231. return action.indexOf('click') !== -1 || hideAction.indexOf('click') !== -1;
  232. };
  233. Trigger.prototype.isMouseEnterToShow = function isMouseEnterToShow() {
  234. var _props4 = this.props,
  235. action = _props4.action,
  236. showAction = _props4.showAction;
  237. return action.indexOf('hover') !== -1 || showAction.indexOf('mouseEnter') !== -1;
  238. };
  239. Trigger.prototype.isMouseLeaveToHide = function isMouseLeaveToHide() {
  240. var _props5 = this.props,
  241. action = _props5.action,
  242. hideAction = _props5.hideAction;
  243. return action.indexOf('hover') !== -1 || hideAction.indexOf('mouseLeave') !== -1;
  244. };
  245. Trigger.prototype.isFocusToShow = function isFocusToShow() {
  246. var _props6 = this.props,
  247. action = _props6.action,
  248. showAction = _props6.showAction;
  249. return action.indexOf('focus') !== -1 || showAction.indexOf('focus') !== -1;
  250. };
  251. Trigger.prototype.isBlurToHide = function isBlurToHide() {
  252. var _props7 = this.props,
  253. action = _props7.action,
  254. hideAction = _props7.hideAction;
  255. return action.indexOf('focus') !== -1 || hideAction.indexOf('blur') !== -1;
  256. };
  257. Trigger.prototype.forcePopupAlign = function forcePopupAlign() {
  258. if (this.state.popupVisible && this._component && this._component.alignInstance) {
  259. this._component.alignInstance.forceAlign();
  260. }
  261. };
  262. Trigger.prototype.fireEvents = function fireEvents(type, e) {
  263. var childCallback = this.props.children.props[type];
  264. if (childCallback) {
  265. childCallback(e);
  266. }
  267. var callback = this.props[type];
  268. if (callback) {
  269. callback(e);
  270. }
  271. };
  272. Trigger.prototype.close = function close() {
  273. this.setPopupVisible(false);
  274. };
  275. Trigger.prototype.render = function render() {
  276. var _this3 = this;
  277. var popupVisible = this.state.popupVisible;
  278. var _props8 = this.props,
  279. children = _props8.children,
  280. forceRender = _props8.forceRender,
  281. alignPoint = _props8.alignPoint,
  282. className = _props8.className;
  283. var child = _react2['default'].Children.only(children);
  284. var newChildProps = { key: 'trigger' };
  285. if (this.isContextMenuToShow()) {
  286. newChildProps.onContextMenu = this.onContextMenu;
  287. } else {
  288. newChildProps.onContextMenu = this.createTwoChains('onContextMenu');
  289. }
  290. if (this.isClickToHide() || this.isClickToShow()) {
  291. newChildProps.onClick = this.onClick;
  292. newChildProps.onMouseDown = this.onMouseDown;
  293. newChildProps.onTouchStart = this.onTouchStart;
  294. } else {
  295. newChildProps.onClick = this.createTwoChains('onClick');
  296. newChildProps.onMouseDown = this.createTwoChains('onMouseDown');
  297. newChildProps.onTouchStart = this.createTwoChains('onTouchStart');
  298. }
  299. if (this.isMouseEnterToShow()) {
  300. newChildProps.onMouseEnter = this.onMouseEnter;
  301. if (alignPoint) {
  302. newChildProps.onMouseMove = this.onMouseMove;
  303. }
  304. } else {
  305. newChildProps.onMouseEnter = this.createTwoChains('onMouseEnter');
  306. }
  307. if (this.isMouseLeaveToHide()) {
  308. newChildProps.onMouseLeave = this.onMouseLeave;
  309. } else {
  310. newChildProps.onMouseLeave = this.createTwoChains('onMouseLeave');
  311. }
  312. if (this.isFocusToShow() || this.isBlurToHide()) {
  313. newChildProps.onFocus = this.onFocus;
  314. newChildProps.onBlur = this.onBlur;
  315. } else {
  316. newChildProps.onFocus = this.createTwoChains('onFocus');
  317. newChildProps.onBlur = this.createTwoChains('onBlur');
  318. }
  319. var childrenClassName = (0, _classnames2['default'])(child && child.props && child.props.className, className);
  320. if (childrenClassName) {
  321. newChildProps.className = childrenClassName;
  322. }
  323. var trigger = _react2['default'].cloneElement(child, newChildProps);
  324. if (!IS_REACT_16) {
  325. return _react2['default'].createElement(
  326. _ContainerRender2['default'],
  327. {
  328. parent: this,
  329. visible: popupVisible,
  330. autoMount: false,
  331. forceRender: forceRender,
  332. getComponent: this.getComponent,
  333. getContainer: this.getContainer
  334. },
  335. function (_ref2) {
  336. var renderComponent = _ref2.renderComponent;
  337. _this3.renderComponent = renderComponent;
  338. return trigger;
  339. }
  340. );
  341. }
  342. var portal = void 0;
  343. // prevent unmounting after it's rendered
  344. if (popupVisible || this._component || forceRender) {
  345. portal = _react2['default'].createElement(
  346. _Portal2['default'],
  347. { key: 'portal', getContainer: this.getContainer, didUpdate: this.handlePortalUpdate },
  348. this.getComponent()
  349. );
  350. }
  351. return [trigger, portal];
  352. };
  353. return Trigger;
  354. }(_react2['default'].Component);
  355. Trigger.propTypes = {
  356. children: _propTypes2['default'].any,
  357. action: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].arrayOf(_propTypes2['default'].string)]),
  358. showAction: _propTypes2['default'].any,
  359. hideAction: _propTypes2['default'].any,
  360. getPopupClassNameFromAlign: _propTypes2['default'].any,
  361. onPopupVisibleChange: _propTypes2['default'].func,
  362. afterPopupVisibleChange: _propTypes2['default'].func,
  363. popup: _propTypes2['default'].oneOfType([_propTypes2['default'].node, _propTypes2['default'].func]).isRequired,
  364. popupStyle: _propTypes2['default'].object,
  365. prefixCls: _propTypes2['default'].string,
  366. popupClassName: _propTypes2['default'].string,
  367. className: _propTypes2['default'].string,
  368. popupPlacement: _propTypes2['default'].string,
  369. builtinPlacements: _propTypes2['default'].object,
  370. popupTransitionName: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].object]),
  371. popupAnimation: _propTypes2['default'].any,
  372. mouseEnterDelay: _propTypes2['default'].number,
  373. mouseLeaveDelay: _propTypes2['default'].number,
  374. zIndex: _propTypes2['default'].number,
  375. focusDelay: _propTypes2['default'].number,
  376. blurDelay: _propTypes2['default'].number,
  377. getPopupContainer: _propTypes2['default'].func,
  378. getDocument: _propTypes2['default'].func,
  379. forceRender: _propTypes2['default'].bool,
  380. destroyPopupOnHide: _propTypes2['default'].bool,
  381. mask: _propTypes2['default'].bool,
  382. maskClosable: _propTypes2['default'].bool,
  383. onPopupAlign: _propTypes2['default'].func,
  384. popupAlign: _propTypes2['default'].object,
  385. popupVisible: _propTypes2['default'].bool,
  386. defaultPopupVisible: _propTypes2['default'].bool,
  387. maskTransitionName: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].object]),
  388. maskAnimation: _propTypes2['default'].string,
  389. stretch: _propTypes2['default'].string,
  390. alignPoint: _propTypes2['default'].bool // Maybe we can support user pass position in the future
  391. };
  392. Trigger.contextTypes = contextTypes;
  393. Trigger.childContextTypes = contextTypes;
  394. Trigger.defaultProps = {
  395. prefixCls: 'rc-trigger-popup',
  396. getPopupClassNameFromAlign: returnEmptyString,
  397. getDocument: returnDocument,
  398. onPopupVisibleChange: noop,
  399. afterPopupVisibleChange: noop,
  400. onPopupAlign: noop,
  401. popupClassName: '',
  402. mouseEnterDelay: 0,
  403. mouseLeaveDelay: 0.1,
  404. focusDelay: 0,
  405. blurDelay: 0.15,
  406. popupStyle: {},
  407. destroyPopupOnHide: false,
  408. popupAlign: {},
  409. defaultPopupVisible: false,
  410. mask: false,
  411. maskClosable: true,
  412. action: [],
  413. showAction: [],
  414. hideAction: []
  415. };
  416. var _initialiseProps = function _initialiseProps() {
  417. var _this4 = this;
  418. this.onMouseEnter = function (e) {
  419. var mouseEnterDelay = _this4.props.mouseEnterDelay;
  420. _this4.fireEvents('onMouseEnter', e);
  421. _this4.delaySetPopupVisible(true, mouseEnterDelay, mouseEnterDelay ? null : e);
  422. };
  423. this.onMouseMove = function (e) {
  424. _this4.fireEvents('onMouseMove', e);
  425. _this4.setPoint(e);
  426. };
  427. this.onMouseLeave = function (e) {
  428. _this4.fireEvents('onMouseLeave', e);
  429. _this4.delaySetPopupVisible(false, _this4.props.mouseLeaveDelay);
  430. };
  431. this.onPopupMouseEnter = function () {
  432. _this4.clearDelayTimer();
  433. };
  434. this.onPopupMouseLeave = function (e) {
  435. // https://github.com/react-component/trigger/pull/13
  436. // react bug?
  437. if (e.relatedTarget && !e.relatedTarget.setTimeout && _this4._component && _this4._component.getPopupDomNode && (0, _contains2['default'])(_this4._component.getPopupDomNode(), e.relatedTarget)) {
  438. return;
  439. }
  440. _this4.delaySetPopupVisible(false, _this4.props.mouseLeaveDelay);
  441. };
  442. this.onFocus = function (e) {
  443. _this4.fireEvents('onFocus', e);
  444. // incase focusin and focusout
  445. _this4.clearDelayTimer();
  446. if (_this4.isFocusToShow()) {
  447. _this4.focusTime = Date.now();
  448. _this4.delaySetPopupVisible(true, _this4.props.focusDelay);
  449. }
  450. };
  451. this.onMouseDown = function (e) {
  452. _this4.fireEvents('onMouseDown', e);
  453. _this4.preClickTime = Date.now();
  454. };
  455. this.onTouchStart = function (e) {
  456. _this4.fireEvents('onTouchStart', e);
  457. _this4.preTouchTime = Date.now();
  458. };
  459. this.onBlur = function (e) {
  460. _this4.fireEvents('onBlur', e);
  461. _this4.clearDelayTimer();
  462. if (_this4.isBlurToHide()) {
  463. _this4.delaySetPopupVisible(false, _this4.props.blurDelay);
  464. }
  465. };
  466. this.onContextMenu = function (e) {
  467. e.preventDefault();
  468. _this4.fireEvents('onContextMenu', e);
  469. _this4.setPopupVisible(true, e);
  470. };
  471. this.onContextMenuClose = function () {
  472. if (_this4.isContextMenuToShow()) {
  473. _this4.close();
  474. }
  475. };
  476. this.onClick = function (event) {
  477. _this4.fireEvents('onClick', event);
  478. // focus will trigger click
  479. if (_this4.focusTime) {
  480. var preTime = void 0;
  481. if (_this4.preClickTime && _this4.preTouchTime) {
  482. preTime = Math.min(_this4.preClickTime, _this4.preTouchTime);
  483. } else if (_this4.preClickTime) {
  484. preTime = _this4.preClickTime;
  485. } else if (_this4.preTouchTime) {
  486. preTime = _this4.preTouchTime;
  487. }
  488. if (Math.abs(preTime - _this4.focusTime) < 20) {
  489. return;
  490. }
  491. _this4.focusTime = 0;
  492. }
  493. _this4.preClickTime = 0;
  494. _this4.preTouchTime = 0;
  495. // Only prevent default when all the action is click.
  496. // https://github.com/ant-design/ant-design/issues/17043
  497. // https://github.com/ant-design/ant-design/issues/17291
  498. if (_this4.isClickToShow() && (_this4.isClickToHide() || _this4.isBlurToHide()) && event && event.preventDefault) {
  499. event.preventDefault();
  500. }
  501. var nextVisible = !_this4.state.popupVisible;
  502. if (_this4.isClickToHide() && !nextVisible || nextVisible && _this4.isClickToShow()) {
  503. _this4.setPopupVisible(!_this4.state.popupVisible, event);
  504. }
  505. };
  506. this.onPopupMouseDown = function () {
  507. var _context$rcTrigger = _this4.context.rcTrigger,
  508. rcTrigger = _context$rcTrigger === undefined ? {} : _context$rcTrigger;
  509. _this4.hasPopupMouseDown = true;
  510. clearTimeout(_this4.mouseDownTimeout);
  511. _this4.mouseDownTimeout = setTimeout(function () {
  512. _this4.hasPopupMouseDown = false;
  513. }, 0);
  514. if (rcTrigger.onPopupMouseDown) {
  515. rcTrigger.onPopupMouseDown.apply(rcTrigger, arguments);
  516. }
  517. };
  518. this.onDocumentClick = function (event) {
  519. if (_this4.props.mask && !_this4.props.maskClosable) {
  520. return;
  521. }
  522. var target = event.target;
  523. var root = (0, _reactDom.findDOMNode)(_this4);
  524. if (!(0, _contains2['default'])(root, target) && !_this4.hasPopupMouseDown) {
  525. _this4.close();
  526. }
  527. };
  528. this.getRootDomNode = function () {
  529. return (0, _reactDom.findDOMNode)(_this4);
  530. };
  531. this.getPopupClassNameFromAlign = function (align) {
  532. var className = [];
  533. var _props9 = _this4.props,
  534. popupPlacement = _props9.popupPlacement,
  535. builtinPlacements = _props9.builtinPlacements,
  536. prefixCls = _props9.prefixCls,
  537. alignPoint = _props9.alignPoint,
  538. getPopupClassNameFromAlign = _props9.getPopupClassNameFromAlign;
  539. if (popupPlacement && builtinPlacements) {
  540. className.push((0, _utils.getAlignPopupClassName)(builtinPlacements, prefixCls, align, alignPoint));
  541. }
  542. if (getPopupClassNameFromAlign) {
  543. className.push(getPopupClassNameFromAlign(align));
  544. }
  545. return className.join(' ');
  546. };
  547. this.getComponent = function () {
  548. var _props10 = _this4.props,
  549. prefixCls = _props10.prefixCls,
  550. destroyPopupOnHide = _props10.destroyPopupOnHide,
  551. popupClassName = _props10.popupClassName,
  552. action = _props10.action,
  553. onPopupAlign = _props10.onPopupAlign,
  554. popupAnimation = _props10.popupAnimation,
  555. popupTransitionName = _props10.popupTransitionName,
  556. popupStyle = _props10.popupStyle,
  557. mask = _props10.mask,
  558. maskAnimation = _props10.maskAnimation,
  559. maskTransitionName = _props10.maskTransitionName,
  560. zIndex = _props10.zIndex,
  561. popup = _props10.popup,
  562. stretch = _props10.stretch,
  563. alignPoint = _props10.alignPoint;
  564. var _state = _this4.state,
  565. popupVisible = _state.popupVisible,
  566. point = _state.point;
  567. var align = _this4.getPopupAlign();
  568. var mouseProps = {};
  569. if (_this4.isMouseEnterToShow()) {
  570. mouseProps.onMouseEnter = _this4.onPopupMouseEnter;
  571. }
  572. if (_this4.isMouseLeaveToHide()) {
  573. mouseProps.onMouseLeave = _this4.onPopupMouseLeave;
  574. }
  575. mouseProps.onMouseDown = _this4.onPopupMouseDown;
  576. mouseProps.onTouchStart = _this4.onPopupMouseDown;
  577. return _react2['default'].createElement(
  578. _Popup2['default'],
  579. (0, _extends3['default'])({
  580. prefixCls: prefixCls,
  581. destroyPopupOnHide: destroyPopupOnHide,
  582. visible: popupVisible,
  583. point: alignPoint && point,
  584. className: popupClassName,
  585. action: action,
  586. align: align,
  587. onAlign: onPopupAlign,
  588. animation: popupAnimation,
  589. getClassNameFromAlign: _this4.getPopupClassNameFromAlign
  590. }, mouseProps, {
  591. stretch: stretch,
  592. getRootDomNode: _this4.getRootDomNode,
  593. style: popupStyle,
  594. mask: mask,
  595. zIndex: zIndex,
  596. transitionName: popupTransitionName,
  597. maskAnimation: maskAnimation,
  598. maskTransitionName: maskTransitionName,
  599. ref: _this4.savePopup
  600. }),
  601. typeof popup === 'function' ? popup() : popup
  602. );
  603. };
  604. this.getContainer = function () {
  605. var props = _this4.props;
  606. var popupContainer = document.createElement('div');
  607. // Make sure default popup container will never cause scrollbar appearing
  608. // https://github.com/react-component/trigger/issues/41
  609. popupContainer.style.position = 'absolute';
  610. popupContainer.style.top = '0';
  611. popupContainer.style.left = '0';
  612. popupContainer.style.width = '100%';
  613. var mountNode = props.getPopupContainer ? props.getPopupContainer((0, _reactDom.findDOMNode)(_this4)) : props.getDocument().body;
  614. mountNode.appendChild(popupContainer);
  615. return popupContainer;
  616. };
  617. this.setPoint = function (point) {
  618. var alignPoint = _this4.props.alignPoint;
  619. if (!alignPoint || !point) return;
  620. _this4.setState({
  621. point: {
  622. pageX: point.pageX,
  623. pageY: point.pageY
  624. }
  625. });
  626. };
  627. this.handlePortalUpdate = function () {
  628. if (_this4.state.prevPopupVisible !== _this4.state.popupVisible) {
  629. _this4.props.afterPopupVisibleChange(_this4.state.popupVisible);
  630. }
  631. };
  632. this.savePopup = function (node) {
  633. _this4._component = node;
  634. };
  635. };
  636. (0, _reactLifecyclesCompat.polyfill)(Trigger);
  637. exports['default'] = Trigger;
  638. module.exports = exports['default'];