@@ -7,77 +7,77 @@ Neither the name of salesforce.com, inc. nor the names of its contributors may b
7
7
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8
8
*/
9
9
10
- 'use strict' ;
11
10
12
- import React , { PropTypes } from 'react' ;
11
+ import React from 'react' ;
13
12
import SLDSPopover from '../SLDSPopover' ;
14
-
15
- import cx from 'classnames' ;
16
-
17
- module . exports = React . createClass ( {
18
-
19
- displayName : 'SLDSToolip' ,
20
-
21
- propTypes : {
22
- align : PropTypes . string ,
23
- children : PropTypes . node ,
24
- content : PropTypes . node ,
25
- hoverCloseDelay : PropTypes . number ,
26
- openByDefault : PropTypes . bool ,
27
- openOn : PropTypes . string ,
28
- } ,
29
-
30
-
31
- getDefaultProps ( ) {
32
- return {
33
- align : 'top' ,
34
- content : < span > Tooltip</ span > ,
35
- hoverCloseDelay : 350 ,
36
- openByDefault : false ,
37
- openOn : 'hover' ,
38
- } ;
39
- } ,
40
-
41
- getInitialState ( ) {
42
- return {
13
+ const classNames = require ( "classnames" ) ;
14
+
15
+ const displayName = "SLDSTooltip" ;
16
+ const propTypes = {
17
+ align : React . PropTypes . string ,
18
+ children : React . PropTypes . node ,
19
+ content : React . PropTypes . node ,
20
+ hoverCloseDelay : React . PropTypes . number ,
21
+ openByDefault : React . PropTypes . bool ,
22
+ openOn : React . PropTypes . string ,
23
+ } ;
24
+ const defaultProps = {
25
+ align : 'top' ,
26
+ content : < span > Tooltip</ span > ,
27
+ hoverCloseDelay : 350 ,
28
+ openByDefault : false ,
29
+ openOn : 'hover' ,
30
+ } ;
31
+
32
+ class SLDSTooltip extends React . Component {
33
+
34
+ constructor ( props ) {
35
+ super ( props ) ;
36
+ this . state = {
37
+ isClosing : false ,
43
38
isOpen : this . props . openByDefault ,
44
- isClosing : false
45
39
} ;
46
- } ,
40
+ }
41
+
42
+ componentDidMount ( ) {
43
+ this . setState ( { isMounted : true } ) ;
44
+ }
47
45
48
- componentDidMount ( ) {
49
- } ,
46
+ componentWillUnmount ( ) {
47
+ this . setState ( { isMounted : false } ) ;
48
+ }
50
49
51
- handleMouseClick ( event ) {
50
+ handleMouseClick ( ) {
52
51
this . setState ( {
53
52
isOpen : ! this . state . isOpen ,
54
53
isClosing : ! this . state . isOpen
55
54
} ) ;
56
- } ,
55
+ }
57
56
58
57
59
- handleMouseEnter ( event ) {
58
+ handleMouseEnter ( ) {
60
59
this . setState ( {
61
60
isOpen : true ,
62
61
isClosing : false
63
62
} ) ;
64
- } ,
63
+ }
64
+
65
+ handleMouseLeave ( ) {
66
+ this . setState ( { isClosing : true } ) ;
65
67
66
- handleMouseLeave ( event ) {
67
- this . setState ( { isClosing : true } ) ;
68
68
setTimeout ( ( ) => {
69
- if ( this . isMounted && this . state . isClosing ) {
69
+ if ( this . state . isMounted && this . state . isClosing ) {
70
70
this . setState ( {
71
71
isOpen : false ,
72
72
isClosing : false
73
73
} ) ;
74
74
}
75
75
} , this . props . hoverCloseDelay )
76
- } ,
76
+ }
77
77
78
78
getTooltipContent ( ) {
79
79
return < div className = 'slds-popover__body' > { this . props . content } </ div > ;
80
- } ,
80
+ }
81
81
82
82
getHorizontalAlign ( ) {
83
83
if ( this . props . align === 'left' ) {
@@ -87,7 +87,7 @@ module.exports = React.createClass( {
87
87
return 'right' ;
88
88
}
89
89
return 'center' ;
90
- } ,
90
+ }
91
91
92
92
getVerticalAlign ( ) {
93
93
if ( this . props . align === 'bottom' ) {
@@ -97,25 +97,26 @@ module.exports = React.createClass( {
97
97
return 'top' ;
98
98
}
99
99
return 'middle' ;
100
- } ,
100
+ }
101
101
102
102
handleCancel ( ) {
103
103
this . setState ( {
104
104
isOpen : false ,
105
105
isClosing : false
106
106
} ) ;
107
- } ,
107
+ }
108
108
109
- getTooltip ( ) {
110
- const style = {
111
- ' slds-popover' : true ,
112
- ' slds-popover--tooltip' : true ,
113
- 'slds-nubbin--top' : this . props . align === 'bottom ' ,
114
- 'slds-nubbin--bottom' : this . props . align === 'top ' ,
115
- 'slds-nubbin--left' : this . props . align === 'right' ,
116
- 'slds-nubbin--right' : this . props . align === 'left'
117
- } ;
109
+ getClassName ( ) {
110
+ return classNames ( this . props . className , "slds-popover" , {
111
+ [ " slds-popover--tooltip" ] : true ,
112
+ [ " slds-nubbin--top" ] : this . props . align === 'bottom' ,
113
+ [ 'slds-nubbin--bottom' ] : this . props . align === 'top ' ,
114
+ [ 'slds-nubbin--left' ] : this . props . align === 'right ' ,
115
+ [ 'slds-nubbin--right' ] : this . props . align === 'left'
116
+ } ) ;
117
+ }
118
118
119
+ getTooltip ( ) {
119
120
return this . state . isOpen ?< SLDSPopover
120
121
key = { this . getHorizontalAlign ( ) + ' ' + this . getVerticalAlign ( ) }
121
122
targetElement = { this . refs . tooltipTarget }
@@ -128,20 +129,28 @@ module.exports = React.createClass( {
128
129
horizontalAlign = { this . getHorizontalAlign ( ) }
129
130
verticalAlign = { this . getVerticalAlign ( ) }
130
131
flippable = { false }
131
- onClose = { this . handleCancel } >
132
- < div className = { cx ( style ) } >
132
+ onClose = { this . handleCancel . bind ( this ) } >
133
+ < div className = { this . getClassName ( ) } role = "tooltip" >
133
134
{ this . getTooltipContent ( ) }
134
135
</ div >
135
136
</ SLDSPopover > :null ;
136
- } ,
137
+ }
137
138
138
139
render ( ) {
139
140
return (
140
- < span refs = 'tooltipTarget' onClick = { this . props . openOn === 'click' ? this . handleMouseClick :null } onMouseEnter = { this . props . openOn === 'hover' ? this . handleMouseEnter :null } onMouseLeave = { this . props . openOn === 'hover' ? this . handleMouseLeave :null } >
141
+ < span refs = 'tooltipTarget' onClick = { this . props . openOn === 'click' ? this . handleMouseClick . bind ( this ) :null } onMouseEnter = { this . props . openOn === 'hover' ? this . handleMouseEnter . bind ( this ) :null } onMouseLeave = { this . props . openOn === 'hover' ? this . handleMouseLeave . bind ( this ) :null } >
141
142
{ this . props . children }
142
143
{ this . getTooltip ( ) }
143
144
</ span >
144
145
) ;
145
146
}
146
147
147
- } ) ;
148
+ }
149
+
150
+
151
+ SLDSTooltip . displayName = displayName ;
152
+ SLDSTooltip . propTypes = propTypes ;
153
+ SLDSTooltip . defaultProps = defaultProps ;
154
+
155
+ module . exports = SLDSTooltip ;
156
+
0 commit comments