Skip to content

Commit cd726b0

Browse files
committed
Add proptypes and onclick to tooltip
1 parent d7afbcb commit cd726b0

File tree

3 files changed

+68
-30
lines changed

3 files changed

+68
-30
lines changed

components/SLDSTooltip/index.jsx

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,69 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1212
import React, {PropTypes} from 'react';
1313
import SLDSPopover from '../SLDSPopover';
1414

15-
import {KEYS,EventUtil} from '../utils';
16-
import omit from 'lodash.omit';
15+
//import {KEYS,EventUtil} from '../utils';
16+
//import omit from 'lodash.omit';
1717

1818
import cx from 'classnames';
1919

2020
module.exports = React.createClass( {
2121

22+
displayName: 'SLDSToolip',
23+
2224
propTypes: {
23-
hoverCloseDelay:PropTypes.number
25+
align: PropTypes.string,
26+
children: PropTypes.node,
27+
content: PropTypes.node,
28+
hoverCloseDelay: PropTypes.number,
29+
openByDefault: PropTypes.bool,
30+
openOnClick: PropTypes.bool,
31+
openOnHover: PropTypes.bool,
2432
},
2533

2634

2735
getDefaultProps () {
2836
return {
29-
content:<span>Tooltip</span>,
3037
align: 'top',
31-
hoverCloseDelay:350,
32-
openOnHover:false
38+
content: <span>Tooltip</span>,
39+
hoverCloseDelay: 350,
40+
openByDefault: false,
41+
openOnClick: false,
42+
openOnHover: false,
3343
};
3444
},
3545

3646
getInitialState(){
3747
return {
38-
isOpen:!this.props.openOnHover,
39-
isClosing:false
48+
isOpen: this.props.openByDefault,
49+
isClosing: false
4050
};
4151
},
4252

4353
componentDidMount(){
4454
},
4555

56+
handleMouseClick(event) {
57+
this.setState({
58+
isOpen: !this.state.isOpen,
59+
isClosing: !this.state.isOpen
60+
});
61+
},
62+
63+
4664
handleMouseEnter(event) {
4765
this.setState({
48-
isOpen:true,
49-
isClosing:false
66+
isOpen: true,
67+
isClosing: false
5068
});
5169
},
5270

5371
handleMouseLeave(event) {
54-
this.setState({isClosing:true});
72+
this.setState({isClosing: true});
5573
setTimeout(()=>{
5674
if(this.isMounted && this.state.isClosing){
5775
this.setState({
58-
isOpen:false,
59-
isClosing:false
76+
isOpen: false,
77+
isClosing: false
6078
});
6179
}
6280
},this.props.hoverCloseDelay)
@@ -88,12 +106,12 @@ module.exports = React.createClass( {
88106

89107
getTooltip() {
90108
const style = {
91-
'slds-popover':true,
92-
'slds-popover--tooltip':true,
93-
'slds-nubbin--top':this.props.align === 'bottom',
94-
'slds-nubbin--bottom':this.props.align === 'top',
95-
'slds-nubbin--left':this.props.align === 'right',
96-
'slds-nubbin--right':this.props.align === 'left'
109+
'slds-popover': true,
110+
'slds-popover--tooltip': true,
111+
'slds-nubbin--top': this.props.align === 'bottom',
112+
'slds-nubbin--bottom': this.props.align === 'top',
113+
'slds-nubbin--left': this.props.align === 'right',
114+
'slds-nubbin--right': this.props.align === 'left'
97115
};
98116

99117
return this.state.isOpen?<SLDSPopover
@@ -117,11 +135,11 @@ module.exports = React.createClass( {
117135

118136
render(){
119137
return (
120-
<span refs='tooltipTarget' onMouseEnter={this.props.openOnHover?this.handleMouseEnter:null} onMouseLeave={this.props.openOnHover?this.handleMouseLeave:null}>
138+
<span refs='tooltipTarget' onClick={this.props.openOnClick?this.handleMouseClick:null} onMouseEnter={this.props.openOnHover?this.handleMouseEnter:null} onMouseLeave={this.props.openOnHover?this.handleMouseLeave:null}>
121139
{ this.props.children }
122140
{ this.getTooltip() }
123141
</span>
124142
);
125143
}
126144

127-
});
145+
});

demo/pages/HomePage/TooltipSection.jsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = React.createClass( {
5959

6060

6161
<div className="slds-p-around--medium">
62-
<h3 id='dropdownSection' className="slds-text-heading--medium slds-truncate">
62+
<h3 id='tooltipSection' className="slds-text-heading--medium slds-truncate">
6363
Tooltip
6464
</h3>
6565
{/*
@@ -70,21 +70,36 @@ module.exports = React.createClass( {
7070
<section style={{paddingLeft:'10rem'}}>
7171
<div className="slds-p-vertical--large">
7272
<p>
73-
<SLDSTooltip
73+
<SLDSTooltip
7474
content={<span>Tooltip with top alignment</span>}
75-
align={alignNames[this.state.alignIndex]}>
76-
Tooltip align top
75+
align={alignNames[this.state.alignIndex]}
76+
openByDefault={true}>
77+
Tooltip align options
7778
</SLDSTooltip>
7879
</p>
7980
</div>
8081

81-
<div ref="super" className="slds-p-vertical--large">
82+
<div ref="tooltipOnHover" className="slds-p-vertical--large">
8283
<p style={{marginTop:'5rem'}}>
83-
<SLDSTooltip
84+
<SLDSTooltip
8485
content={<span>Tooltip with bottom alignment</span>}
8586
align='bottom'
8687
openOnHover={true}
87-
targetElement={this.refs.super}>Tooltip open on hover</SLDSTooltip>
88+
targetElement={this.refs.tooltipOnHover}>
89+
Tooltip open on hover
90+
</SLDSTooltip>
91+
</p>
92+
</div>
93+
94+
<div ref="tooltipOnClick" className="slds-p-vertical--large">
95+
<p style={{marginTop:'5rem'}}>
96+
<SLDSTooltip
97+
content={<span>Tooltip with right alignment</span>}
98+
align='right'
99+
openOnClick={true}
100+
targetElement={this.refs.tooltipOnClick}>
101+
Tooltip open on click
102+
</SLDSTooltip>
88103
</p>
89104
</div>
90105
</section>
@@ -95,4 +110,4 @@ module.exports = React.createClass( {
95110

96111
);
97112
}
98-
});
113+
});

demo/pages/HomePage/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ module.exports = React.createClass( {
6969
let that = this;
7070
return function() {
7171
var target = document.getElementById(elemId);
72+
console.log(target);
7273
that.animate(document.body, "scrollTop", "", 0, target.offsetTop, 500, true);
7374
};
7475
},
@@ -126,6 +127,9 @@ module.exports = React.createClass( {
126127
<li>
127128
<a href="javascript:void(0)" onClick={this.scrollTo('picklistSection')}>Picklist</a>
128129
</li>
130+
<li>
131+
<a href="javascript:void(0)" onClick={this.scrollTo('tooltipSection')}>Tooltip</a>
132+
</li>
129133
</ul>
130134

131135
<h3 className="slds-text-heading--medium slds-p-top--medium">Future Components</h3>
@@ -136,7 +140,6 @@ module.exports = React.createClass( {
136140
</ul>
137141
</section>
138142

139-
<TooltipSection/>
140143

141144
<ButtonSection/>
142145

@@ -160,6 +163,8 @@ module.exports = React.createClass( {
160163

161164
<PicklistBaseCustomSection />
162165

166+
<TooltipSection/>
167+
163168
<h1 className="slds-text-heading--large slds-p-top--large">Future Components</h1>
164169

165170
<DatePickerSingleSelectSection />

0 commit comments

Comments
 (0)