Skip to content

Commit 1a92ccf

Browse files
committed
tooltip progress
1 parent 9580855 commit 1a92ccf

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

components/SLDSPopover.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module.exports = React.createClass( {
4141
className: 'slds-dropdown',
4242
closeOnTabKey: false,
4343
marginTop:'0.20rem',
44-
marginBottom:'0.35rem'
44+
marginBottom:'0.35rem',
45+
marginLeft:0,
46+
marginRight:0,
47+
flippable:true
4548
};
4649
},
4750

@@ -95,6 +98,8 @@ module.exports = React.createClass( {
9598
WebkitTransform:'none',
9699
'marginTop':this.props.marginTop,
97100
'marginBottom':this.props.marginBottom,
101+
'marginLeft':this.props.marginLeft,
102+
'marginRight':this.props.marginRight,
98103
'float':'inherit',
99104
'position':'inherit'
100105
}}
@@ -114,13 +119,14 @@ module.exports = React.createClass( {
114119
dropOptions () {
115120
const target = this.props.targetElement?React.findDOMNode(this.props.targetElement):React.findDOMNode(this).parentNode;
116121
const position = this.props.verticalAlign+' '+this.props.horizontalAlign;
122+
console.log('position: ',position);
117123
return {
118124
target: target,
119125
content: this.popoverElement,
120126
position: position,
121127
openOn: 'always',
122128
beforeClose:this.beforeClose,
123-
constrainToWindow:true,
129+
constrainToWindow:this.props.flippable,
124130
constrainToScrollParent:false,
125131
remove:true
126132
};

components/SLDSTooltip/index.jsx

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,88 @@ import SLDSPopover from '../SLDSPopover';
1515
import {KEYS,EventUtil} from '../utils';
1616
import omit from 'lodash.omit';
1717

18+
import cx from 'classnames';
1819

1920
module.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>

demo/pages/HomePage/TooltipSection.jsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,33 @@ module.exports = React.createClass( {
4444

4545
<div className="slds-p-around--medium">
4646
<h3 id='dropdownSection' className="slds-text-heading--medium slds-truncate">
47-
Dropdown Base
47+
Tooltip
4848
</h3>
49-
49+
{/*
5050
<PrismCode className='language-markup'>
5151
{require("raw-loader!../../code-snippets/SLDSDropdownPage.txt")}
5252
</PrismCode>
53+
*/}
54+
<div ref="super" className="slds-p-vertical--large">
55+
<p>
56+
<SLDSTooltip
57+
content={<span>Tooltip with top alignment</span>}
58+
align='top'
59+
targetElement={this.refs.super}>Tooltip align top</SLDSTooltip>
60+
</p>
61+
</div>
62+
5363
<div ref="super" className="slds-p-vertical--large">
54-
SUPER!!!
64+
<p>
65+
<SLDSTooltip
66+
content={<span>Tooltip with bottom alignment</span>}
67+
align='bottom'
68+
openOnHover={true}
69+
targetElement={this.refs.super}>Tooltip open on hover</SLDSTooltip>
70+
</p>
5571
</div>
56-
<SLDSTooltip targetElement={this.refs.super}>Tooltip trigger</SLDSTooltip>
72+
73+
5774
</div>
5875

5976

0 commit comments

Comments
 (0)