1+ 'use strict' ;
2+
3+ exports . __esModule = true ;
4+
5+ var _extends2 = require ( 'babel-runtime/helpers/extends' ) ;
6+
7+ var _extends3 = _interopRequireDefault ( _extends2 ) ;
8+
9+ var _objectWithoutProperties2 = require ( 'babel-runtime/helpers/objectWithoutProperties' ) ;
10+
11+ var _objectWithoutProperties3 = _interopRequireDefault ( _objectWithoutProperties2 ) ;
12+
13+ var _classCallCheck2 = require ( 'babel-runtime/helpers/classCallCheck' ) ;
14+
15+ var _classCallCheck3 = _interopRequireDefault ( _classCallCheck2 ) ;
16+
17+ var _possibleConstructorReturn2 = require ( 'babel-runtime/helpers/possibleConstructorReturn' ) ;
18+
19+ var _possibleConstructorReturn3 = _interopRequireDefault ( _possibleConstructorReturn2 ) ;
20+
21+ var _inherits2 = require ( 'babel-runtime/helpers/inherits' ) ;
22+
23+ var _inherits3 = _interopRequireDefault ( _inherits2 ) ;
24+
25+ var _react = require ( 'react' ) ;
26+
27+ var _react2 = _interopRequireDefault ( _react ) ;
28+
29+ var _reactDom = require ( 'react-dom' ) ;
30+
31+ var _propTypes = require ( 'prop-types' ) ;
32+
33+ var _propTypes2 = _interopRequireDefault ( _propTypes ) ;
34+
35+ var _positions = require ( 'positions' ) ;
36+
37+ var _positions2 = _interopRequireDefault ( _positions ) ;
38+
39+ var _rcTrigger = require ( 'rc-trigger' ) ;
40+
41+ var _rcTrigger2 = _interopRequireDefault ( _rcTrigger ) ;
42+
43+ var _placements = require ( './placements' ) ;
44+
45+ var _util = require ( './util' ) ;
46+
47+ var _Content = require ( './Content' ) ;
48+
49+ var _Content2 = _interopRequireDefault ( _Content ) ;
50+
51+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { 'default' : obj } ; }
52+
53+ var pointNamesMap = {
54+ tc : 'top center' ,
55+ bc : 'bottom center' ,
56+ cl : 'center left' ,
57+ cr : 'center right' ,
58+ tl : 'top left' ,
59+ tr : 'top right' ,
60+ bl : 'bottom left' ,
61+ br : 'bottom right'
62+ } ;
63+
64+ var getArrowStyle = function getArrowStyle ( position , align ) {
65+ var arrowDirection = ( 0 , _util . getArrowDirection ) ( align ) ;
66+ var arrowAlign = ( 0 , _util . getArrowAlign ) ( align ) ;
67+
68+ var style = { } ;
69+ if ( arrowDirection === 'up' || arrowDirection === 'down' ) {
70+ style . left = position . left + align . offset [ 0 ] + 'px' ;
71+ }
72+ if ( arrowDirection === 'left' || arrowDirection === 'right' ) {
73+ style . top = position . top + align . offset [ 1 ] + 'px' ;
74+ }
75+ if ( arrowAlign === 'left' ) {
76+ style . marginLeft = 5 ;
77+ }
78+ if ( arrowAlign === 'right' ) {
79+ style . marginRight = 5 ;
80+ }
81+ if ( arrowAlign === 'top' ) {
82+ style . marginTop = 5 ;
83+ }
84+ if ( arrowAlign === 'bottom' ) {
85+ style . marginBottom = 5 ;
86+ }
87+
88+ return style ;
89+ } ;
90+
91+ var Tooltip = function ( _Component ) {
92+ ( 0 , _inherits3 [ 'default' ] ) ( Tooltip , _Component ) ;
93+
94+ function Tooltip ( ) {
95+ var _temp , _this , _ret ;
96+
97+ ( 0 , _classCallCheck3 [ 'default' ] ) ( this , Tooltip ) ;
98+
99+ for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
100+ args [ _key ] = arguments [ _key ] ;
101+ }
102+
103+ return _ret = ( _temp = ( _this = ( 0 , _possibleConstructorReturn3 [ 'default' ] ) ( this , _Component . call . apply ( _Component , [ this ] . concat ( args ) ) ) , _this ) , _this . state = { arrowStyle : null } , _this . onPopupAlign = function ( popupNode , align ) {
104+ var onPopupAlign = _this . props . onPopupAlign ;
105+
106+
107+ _this . adjustArrow ( align ) ;
108+
109+ if ( onPopupAlign ) {
110+ onPopupAlign ( popupNode , align ) ;
111+ }
112+ } , _this . getPopupDomNode = function ( ) {
113+ return _this . trigger . getPopupDomNode ( ) ;
114+ } , _this . getPopupElement = function ( ) {
115+ var _this$props = _this . props ,
116+ arrowContent = _this$props . arrowContent ,
117+ overlay = _this$props . overlay ,
118+ prefixCls = _this$props . prefixCls ,
119+ id = _this$props . id ;
120+ var arrowStyle = _this . state . arrowStyle ;
121+
122+
123+ return [ _react2 [ 'default' ] . createElement (
124+ 'div' ,
125+ { ref : _this . saveArrow , className : prefixCls + '-arrow' , key : 'arrow' , style : arrowStyle } ,
126+ arrowContent
127+ ) , _react2 [ 'default' ] . createElement ( _Content2 [ 'default' ] , {
128+ key : 'content' ,
129+ trigger : _this . trigger ,
130+ prefixCls : prefixCls ,
131+ id : id ,
132+ overlay : overlay
133+ } ) ] ;
134+ } , _this . adjustArrow = function ( align ) {
135+ var arrowStyleCurrent = _this . state . arrowStyle ;
136+
137+ var targetNode = ( 0 , _reactDom . findDOMNode ) ( _this ) ;
138+
139+ var arrowPlacement = pointNamesMap [ align . points [ 0 ] ] ;
140+ var targetPlacement = pointNamesMap [ align . points [ 1 ] ] ;
141+ var position = ( 0 , _positions2 [ 'default' ] ) ( _this . arrow , arrowPlacement , targetNode , targetPlacement ) ;
142+
143+ var arrowStyle = getArrowStyle ( position , align ) ;
144+ if ( ! arrowStyleCurrent || arrowStyle . top !== arrowStyleCurrent . top || arrowStyle . left !== arrowStyleCurrent . left ) {
145+ _this . setState ( { arrowStyle : arrowStyle } ) ;
146+ }
147+ } , _this . saveArrow = function ( node ) {
148+ _this . arrow = node ;
149+ } , _this . saveTrigger = function ( node ) {
150+ _this . trigger = node ;
151+ } , _temp ) , ( 0 , _possibleConstructorReturn3 [ 'default' ] ) ( _this , _ret ) ;
152+ }
153+
154+ Tooltip . prototype . render = function render ( ) {
155+ var _props = this . props ,
156+ overlayClassName = _props . overlayClassName ,
157+ trigger = _props . trigger ,
158+ mouseEnterDelay = _props . mouseEnterDelay ,
159+ mouseLeaveDelay = _props . mouseLeaveDelay ,
160+ overlayStyle = _props . overlayStyle ,
161+ prefixCls = _props . prefixCls ,
162+ children = _props . children ,
163+ onVisibleChange = _props . onVisibleChange ,
164+ afterVisibleChange = _props . afterVisibleChange ,
165+ transitionName = _props . transitionName ,
166+ animation = _props . animation ,
167+ placement = _props . placement ,
168+ align = _props . align ,
169+ destroyTooltipOnHide = _props . destroyTooltipOnHide ,
170+ defaultVisible = _props . defaultVisible ,
171+ getTooltipContainer = _props . getTooltipContainer ,
172+ restProps = ( 0 , _objectWithoutProperties3 [ 'default' ] ) ( _props , [ 'overlayClassName' , 'trigger' , 'mouseEnterDelay' , 'mouseLeaveDelay' , 'overlayStyle' , 'prefixCls' , 'children' , 'onVisibleChange' , 'afterVisibleChange' , 'transitionName' , 'animation' , 'placement' , 'align' , 'destroyTooltipOnHide' , 'defaultVisible' , 'getTooltipContainer' ] ) ;
173+
174+ var extraProps = ( 0 , _extends3 [ 'default' ] ) ( { } , restProps ) ;
175+ if ( 'visible' in this . props ) {
176+ extraProps . popupVisible = this . props . visible ;
177+ }
178+ return _react2 [ 'default' ] . createElement (
179+ _rcTrigger2 [ 'default' ] ,
180+ ( 0 , _extends3 [ 'default' ] ) ( {
181+ popupClassName : overlayClassName ,
182+ ref : this . saveTrigger ,
183+ prefixCls : prefixCls ,
184+ popup : this . getPopupElement ,
185+ action : trigger ,
186+ builtinPlacements : _placements . placements ,
187+ popupPlacement : placement ,
188+ popupAlign : align ,
189+ getPopupContainer : getTooltipContainer ,
190+ onPopupVisibleChange : onVisibleChange ,
191+ afterPopupVisibleChange : afterVisibleChange ,
192+ popupTransitionName : transitionName ,
193+ popupAnimation : animation ,
194+ defaultPopupVisible : defaultVisible ,
195+ destroyPopupOnHide : destroyTooltipOnHide ,
196+ mouseLeaveDelay : mouseLeaveDelay ,
197+ popupStyle : overlayStyle ,
198+ mouseEnterDelay : mouseEnterDelay
199+ } , extraProps , {
200+ onPopupAlign : this . onPopupAlign
201+ } ) ,
202+ children
203+ ) ;
204+ } ;
205+
206+ return Tooltip ;
207+ } ( _react . Component ) ;
208+
209+ Tooltip . propTypes = {
210+ trigger : _propTypes2 [ 'default' ] . any ,
211+ children : _propTypes2 [ 'default' ] . any ,
212+ defaultVisible : _propTypes2 [ 'default' ] . bool ,
213+ visible : _propTypes2 [ 'default' ] . bool ,
214+ placement : _propTypes2 [ 'default' ] . string ,
215+ transitionName : _propTypes2 [ 'default' ] . oneOfType ( [ _propTypes2 [ 'default' ] . string , _propTypes2 [ 'default' ] . object ] ) ,
216+ animation : _propTypes2 [ 'default' ] . any ,
217+ onVisibleChange : _propTypes2 [ 'default' ] . func ,
218+ onPopupAlign : _propTypes2 [ 'default' ] . func ,
219+ afterVisibleChange : _propTypes2 [ 'default' ] . func ,
220+ overlay : _propTypes2 [ 'default' ] . oneOfType ( [ _propTypes2 [ 'default' ] . node , _propTypes2 [ 'default' ] . func ] ) . isRequired ,
221+ overlayStyle : _propTypes2 [ 'default' ] . object ,
222+ overlayClassName : _propTypes2 [ 'default' ] . string ,
223+ prefixCls : _propTypes2 [ 'default' ] . string ,
224+ mouseEnterDelay : _propTypes2 [ 'default' ] . number ,
225+ mouseLeaveDelay : _propTypes2 [ 'default' ] . number ,
226+ getTooltipContainer : _propTypes2 [ 'default' ] . func ,
227+ destroyTooltipOnHide : _propTypes2 [ 'default' ] . bool ,
228+ align : _propTypes2 [ 'default' ] . object ,
229+ arrowContent : _propTypes2 [ 'default' ] . any ,
230+ id : _propTypes2 [ 'default' ] . string
231+ } ;
232+ Tooltip . defaultProps = {
233+ prefixCls : 'rc-tooltip' ,
234+ mouseEnterDelay : 0 ,
235+ destroyTooltipOnHide : false ,
236+ mouseLeaveDelay : 0.1 ,
237+ align : { } ,
238+ placement : 'right' ,
239+ trigger : [ 'hover' ] ,
240+ arrowContent : null
241+ } ;
242+ exports [ 'default' ] = Tooltip ;
243+ module . exports = exports [ 'default' ] ;
0 commit comments