Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tooltip Component #135

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/components/Tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { Tooltip as InnerTooltip } from 'reactstrap';

export default class Tooltip extends React.Component {
static propTypes = {
isOpen: React.PropTypes.bool
};

static defaultProps = {
isOpen: false
};

state = {
isOpen: this.props.isOpen
};

toggle = () => this.setState({
isOpen: !this.state.isOpen
});

render() {
const { isOpen, ...props } = this.props;

return (
<InnerTooltip isOpen={this.state.isOpen} toggle={this.toggle} {...props} />
);
}
}
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ import {
Row,
TabContent,
TabPane,
TetherContent,
Tooltip
TetherContent
} from 'reactstrap';

// Gears:
Expand All @@ -86,6 +85,7 @@ import Steps from './components/Steps.js';
import SummaryBox from './components/SummaryBox.js';
import SummaryBoxItem from './components/SummaryBoxItem.js';
import Table from './components/Table.js';
import Tooltip from './components/Tooltip.js';

export {
// reactstrap
Expand Down Expand Up @@ -152,7 +152,6 @@ export {
TabPane,
Table,
TetherContent,
Tooltip,

Select,

Expand All @@ -175,5 +174,6 @@ export {
Spinner,
Steps,
SummaryBox,
SummaryBoxItem
SummaryBoxItem,
Tooltip
};
29 changes: 2 additions & 27 deletions stories/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,18 @@ import { Tooltip } from '../src';
import { storiesOf } from '@kadira/storybook';
import { select } from '@kadira/storybook-addon-knobs';

export default class TooltipExample extends React.Component {
static displayName = 'Tooltip';

state = {
tooltipOpen: false
};

toggle = () => this.setState({
tooltipOpen: !this.state.tooltipOpen
});

render() {
return (
<Tooltip
placement={this.props.placement}
isOpen={this.state.tooltipOpen}
target={this.props.target}
toggle={this.toggle}
>
{this.props.children}
</Tooltip>
);
}
}

storiesOf('Tooltip', module)
.addWithInfo('Live example', () => (
<div>
<p>
Somewhere in here is a <a id="TooltipExample">tooltip</a>.
</p>
<TooltipExample
<Tooltip
placement={select('placement', ['top', 'left', 'bottom', 'right'], 'right')}
target="TooltipExample"
>
Hello world!
</TooltipExample>
</Tooltip>
</div>
)
);
36 changes: 36 additions & 0 deletions test/components/Tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env mocha */
import React from 'react';
import assert from 'assert';
import { shallow } from 'enzyme';

import Tooltip from '../../src/components/Tooltip';

describe('<Tooltip />', () => {
describe('by default', () => {
const component = shallow(<Tooltip placement="right" children="Hello World" target="foo" />);

it('should be closed', () => {
assert.equal(component.prop('isOpen'), false);
assert.equal(component.state('isOpen'), false);
});

it('should forward props', () => {
assert.equal(component.prop('placement'), 'right');
});

it('should toggle state', () => {
component.prop('toggle')();
assert.equal(component.prop('isOpen'), true);
assert.equal(component.state('isOpen'), true);
});
});

describe('with initial props', () => {
const component = shallow(<Tooltip isOpen children="Hello World" target="foo" />);

it('should seed state', () => {
assert.equal(component.prop('isOpen'), true);
assert.equal(component.state('isOpen'), true);
});
});
});