@@ -15,58 +15,88 @@ import SLDSPopover from '../SLDSPopover';
1515import { KEYS , EventUtil } from '../utils' ;
1616import omit from 'lodash.omit' ;
1717
18+ import cx from 'classnames' ;
1819
1920module . exports = React . createClass ( {
2021
2122 propTypes : {
2223 hoverCloseDelay :PropTypes . number
2324 } ,
2425
25- getDefaultProps ( ) {
26+
27+ getDefaultProps ( ) {
2628 return {
27- hoverCloseDelay :300
28- }
29+ content :< span > Tooltip</ span > ,
30+ align : 'top' ,
31+ hoverCloseDelay :200 ,
32+ openOnHover :false
33+ } ;
2934 } ,
3035
3136 getInitialState ( ) {
3237 return {
33- isOpen :false
38+ isOpen :! this . props . openOnHover ,
39+ isClosing :false
3440 } ;
3541 } ,
3642
3743 componentDidMount ( ) {
3844 } ,
3945
4046 handleMouseEnter ( event ) {
41- this . setState ( { isOpen :true } ) ;
47+ this . setState ( {
48+ isOpen :true ,
49+ isClosing :false
50+ } ) ;
4251 } ,
4352
4453 handleMouseLeave ( event ) {
45- this . setState ( { isOpen :false } ) ;
54+ this . setState ( { isClosing :true } ) ;
55+ setTimeout ( ( ) => {
56+ if ( this . isMounted && this . state . isClosing ) {
57+ this . setState ( {
58+ isOpen :false ,
59+ isClosing :false
60+ } ) ;
61+ }
62+ } , this . props . hoverCloseDelay )
4663 } ,
4764
4865 getTooltipContent ( ) {
49- return < div className = 'slds-popover__body' > SUPER STUFF IS HERE! </ div > ;
66+ return < div className = 'slds-popover__body' > { this . props . content } </ div > ;
5067 } ,
5168
5269 getTooltip ( ) {
70+ const style = {
71+ 'slds-popover' :true ,
72+ 'slds-popover--tooltip' :true ,
73+ 'slds-nubbin--top' :this . props . align === 'bottom' ,
74+ 'slds-nubbin--bottom' :this . props . align === 'top' ,
75+ 'slds-nubbin--left' :this . props . align === 'left' ,
76+ 'slds-nubbin--right' :this . props . align === 'right'
77+ } ;
78+
5379 return this . state . isOpen ?< SLDSPopover
5480 targetElement = { this . refs . tooltipTarget }
5581 closeOnTabKey = { true }
5682 className = ''
5783 marginTop = '1rem'
5884 marginBottom = '1rem'
59- horizontalAlign = 'center'
85+ marginLeft = '1rem'
86+ marginRight = '1rem'
87+ horizontalAlign = { this . props . align === 'left' || this . props . align === 'right' ?this . props . align :'center' }
88+ verticalAlign = { this . props . align === 'bottom' || this . props . align === 'top' ?this . props . align :'center' }
89+ flippable = { false }
6090 onClose = { this . handleCancel } >
61- < div className = 'slds-popover slds-popover--tooltip slds-nubbin--top' >
62- { this . getTooltipContent ( ) }
91+ < div className = { cx ( style ) } >
92+ { this . getTooltipContent ( ) }
6393 </ div >
6494 </ SLDSPopover > :null ;
6595 } ,
6696
6797 render ( ) {
6898 return (
69- < span refs = 'tooltipTarget' onMouseEnter = { this . handleMouseEnter } onMouseLeave = { this . handleMouseLeave } >
99+ < span refs = 'tooltipTarget' onMouseEnter = { this . props . openOnHover ? this . handleMouseEnter : null } onMouseLeave = { this . props . openOnHover ? this . handleMouseLeave : null } >
70100 { this . props . children }
71101 { this . getTooltip ( ) }
72102 </ span >
0 commit comments