-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from appfolio/addTooltip
Add Tooltip Component
- Loading branch information
Showing
4 changed files
with
70 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |