Skip to content

Commit 1658142

Browse files
committed
[added] Property for animation on Popover and Tooltip
1 parent fb9b3bf commit 1658142

File tree

4 files changed

+68
-8
lines changed

4 files changed

+68
-8
lines changed

src/Popover.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import classNames from 'classnames';
33
import BootstrapMixin from './BootstrapMixin';
4+
import FadeMixin from './FadeMixin';
45

56
const Popover = React.createClass({
6-
mixins: [BootstrapMixin],
7+
mixins: [BootstrapMixin, FadeMixin],
78

89
propTypes: {
910
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
@@ -15,20 +16,24 @@ const Popover = React.createClass({
1516
arrowOffsetTop: React.PropTypes.oneOfType([
1617
React.PropTypes.number, React.PropTypes.string
1718
]),
18-
title: React.PropTypes.node
19+
title: React.PropTypes.node,
20+
animation: React.PropTypes.bool
1921
},
2022

2123
getDefaultProps() {
2224
return {
23-
placement: 'right'
25+
placement: 'right',
26+
animation: true
2427
};
2528
},
2629

2730
render() {
2831
const classes = {
2932
'popover': true,
3033
[this.props.placement]: true,
31-
'in': this.props.positionLeft != null || this.props.positionTop != null
34+
// in class will be added by the FadeMixin when the animation property is true
35+
'in': !this.props.animation && (this.props.positionLeft != null || this.props.positionTop != null),
36+
'fade': this.props.animation
3237
};
3338

3439
const style = {

src/Tooltip.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import classNames from 'classnames';
33
import BootstrapMixin from './BootstrapMixin';
4+
import FadeMixin from './FadeMixin';
45

56
const Tooltip = React.createClass({
6-
mixins: [BootstrapMixin],
7+
mixins: [BootstrapMixin, FadeMixin],
78

89
propTypes: {
910
placement: React.PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
@@ -14,20 +15,24 @@ const Tooltip = React.createClass({
1415
]),
1516
arrowOffsetTop: React.PropTypes.oneOfType([
1617
React.PropTypes.number, React.PropTypes.string
17-
])
18+
]),
19+
animation: React.PropTypes.bool
1820
},
1921

2022
getDefaultProps() {
2123
return {
22-
placement: 'right'
24+
placement: 'right',
25+
animation: true
2326
};
2427
},
2528

2629
render() {
2730
const classes = {
2831
'tooltip': true,
2932
[this.props.placement]: true,
30-
'in': this.props.positionLeft != null || this.props.positionTop != null
33+
// in class will be added by the FadeMixin when the animation property is true
34+
'in': !this.props.animation && (this.props.positionLeft != null || this.props.positionTop != null),
35+
'fade': this.props.animation
3136
};
3237

3338
const style = {

test/PopoverSpec.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import ReactTestUtils from 'react/lib/ReactTestUtils';
3+
import Popover from '../src/Popover';
4+
5+
describe('Popover', function () {
6+
it('Should output a popover title and content', function () {
7+
let instance = ReactTestUtils.renderIntoDocument(
8+
<Popover title="Popover title">
9+
<strong>Popover Content</strong>
10+
</Popover>
11+
);
12+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'popover-title'));
13+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'popover-content'));
14+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'fade'));
15+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'strong'));
16+
});
17+
18+
it('Should not have the fade class if animation is false', function () {
19+
let instance = ReactTestUtils.renderIntoDocument(
20+
<Popover title="Popover title" animation={false}>
21+
<strong>Popover Content</strong>
22+
</Popover>
23+
);
24+
assert.equal(instance.getDOMNode().className.match(/\bfade\b/), null, 'The fade class should not be present');
25+
});
26+
});

test/TooltipSpec.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import ReactTestUtils from 'react/lib/ReactTestUtils';
3+
import Tooltip from '../src/Tooltip';
4+
5+
describe('Tooltip', function () {
6+
it('Should output a tooltip with content', function () {
7+
let instance = ReactTestUtils.renderIntoDocument(
8+
<Tooltip>
9+
<strong>Tooltip Content</strong>
10+
</Tooltip>
11+
);
12+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'strong'));
13+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'fade'));
14+
});
15+
16+
it('Should not have the fade class if animation is false', function () {
17+
let instance = ReactTestUtils.renderIntoDocument(
18+
<Tooltip animation={false}>
19+
<strong>Tooltip Content</strong>
20+
</Tooltip>
21+
);
22+
assert.equal(instance.getDOMNode().className.match(/\bfade\b/), null, 'The fade class should not be present');
23+
});
24+
});

0 commit comments

Comments
 (0)