@@ -12,6 +12,10 @@ var _react = require('react');
12
12
13
13
var _react2 = _interopRequireDefault ( _react ) ;
14
14
15
+ var _reactDom = require ( 'react-dom' ) ;
16
+
17
+ var _reactDom2 = _interopRequireDefault ( _reactDom ) ;
18
+
15
19
var _reactRedux = require ( 'react-redux' ) ;
16
20
17
21
var _utils = require ( './utils' ) ;
@@ -81,74 +85,86 @@ var Tooltip = function (_Component) {
81
85
}
82
86
83
87
_createClass ( Tooltip , [ {
84
- key : 'componentWillUpdate ' ,
85
- value : function componentWillUpdate ( nextProps ) {
88
+ key : 'componentWillReceiveProps ' ,
89
+ value : function componentWillReceiveProps ( nextProps ) {
86
90
var el = nextProps . el ;
87
91
var place = nextProps . place ;
92
+ var content = nextProps . content ;
88
93
89
- if ( el && ( this . props . el != el || this . props . place !== place ) ) {
94
+ if ( el && ( this . props . el != el || this . props . place !== place || this . props . content !== content ) ) {
90
95
this . updatePosition ( nextProps ) ;
91
96
}
92
97
}
93
98
} , {
94
- key : 'componentDidUpdate ' ,
95
- value : function componentDidUpdate ( prevProps ) {
96
- var content = prevProps . content ;
99
+ key : 'updatePosition ' ,
100
+ value : function updatePosition ( props ) {
101
+ var _this2 = this ;
97
102
98
- if ( this . props . content !== content ) {
99
- this . updatePosition ( this . props ) ;
100
- }
103
+ // Setup hidden DOM element to determine size of the content
104
+ var content = this . children ( props ) ;
105
+ _reactDom2 . default . render ( _react2 . default . createElement (
106
+ 'div' ,
107
+ null ,
108
+ content
109
+ ) , this . refs . shadow , function ( ) {
110
+ var state = ( 0 , _utils . adjust ) ( _this2 . refs . shadow , props ) ;
111
+ _this2 . setState ( state ) ;
112
+ } ) ;
101
113
}
102
114
} , {
103
- key : 'updatePosition' ,
104
- value : function updatePosition ( props ) {
105
- var state = ( 0 , _utils . adjust ) ( this . refs . tooltip , props ) ;
106
- this . setState ( state ) ;
115
+ key : 'children' ,
116
+ value : function children ( props ) {
117
+ if ( typeof props === 'undefined' ) {
118
+ props = this . props ;
119
+ }
120
+ var _props = props ;
121
+ var content = _props . content ;
122
+
123
+ return content ? content : props . children ;
107
124
}
108
125
} , {
109
126
key : 'render' ,
110
127
value : function render ( ) {
111
- var _props = this . props ;
112
- var content = _props . content ;
113
- var onHover = _props . onHover ;
114
- var onLeave = _props . onLeave ;
128
+ var _props2 = this . props ;
129
+ var onHover = _props2 . onHover ;
130
+ var onLeave = _props2 . onLeave ;
115
131
var _state = this . state ;
116
132
var place = _state . place ;
117
133
var offset = _state . offset ;
118
134
135
+ var content = this . children ( ) ;
119
136
var visibility = this . props . el && this . props . show ? 'visible' : 'hidden' ;
120
137
var style = {
121
138
base : _extends ( { } , styles . base , themes . simple . base , { visibility : visibility } , offset ) ,
122
139
content : _extends ( { } , styles . content , themes . simple . content ) ,
123
140
arrow : _extends ( { } , styles . arrow ) ,
124
141
border : _extends ( { } , styles . border . base , styles . border [ place ] , themes . simple . border )
125
142
} ;
126
-
127
- var children = undefined ;
128
- if ( content ) {
129
- children = content ;
130
- } else {
131
- children = this . props . children ;
132
- }
143
+ style . shadow = _extends ( { } , style . content , { visibility : 'hidden' , position : 'absolute' } ) ;
133
144
134
145
return _react2 . default . createElement (
135
146
'div' ,
136
- {
137
- ref : 'tooltip' ,
138
- style : style . base ,
139
- onMouseEnter : onHover ,
140
- onMouseLeave : onLeave
141
- } ,
147
+ null ,
142
148
_react2 . default . createElement (
143
149
'div' ,
144
- { ref : 'content' , style : style . content } ,
145
- children
150
+ {
151
+ ref : 'tooltip' ,
152
+ style : style . base ,
153
+ onMouseEnter : onHover ,
154
+ onMouseLeave : onLeave
155
+ } ,
156
+ _react2 . default . createElement (
157
+ 'div' ,
158
+ { ref : 'content' , style : style . content } ,
159
+ content
160
+ ) ,
161
+ _react2 . default . createElement (
162
+ 'div' ,
163
+ { style : style . arrow , key : 'a-' + place } ,
164
+ _react2 . default . createElement ( 'span' , { ref : 'border' , style : style . border , key : 'b-' + place } )
165
+ )
146
166
) ,
147
- _react2 . default . createElement (
148
- 'div' ,
149
- { style : style . arrow , key : 'a-' + place } ,
150
- _react2 . default . createElement ( 'span' , { ref : 'border' , style : style . border , key : 'b-' + place } )
151
- )
167
+ _react2 . default . createElement ( 'div' , { ref : 'shadow' , style : style . shadow } )
152
168
) ;
153
169
}
154
170
} ] ) ;
0 commit comments