forked from bulwark-crypto/bulwark-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
29 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 |
---|---|---|
@@ -1,36 +1,26 @@ | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import {pickRest} from '../lib/utils' | ||
|
||
const Tooltip = ({bgcolor, children, content, fgcolor, position, ...props}) => { | ||
const Tooltip = (props) => { | ||
const [ mods, {children, content, ...rest} ] = pickRest(props, ['bottom', 'left', 'primary', 'right', 'top', 'urgent']) | ||
return ( | ||
<div {...props} className="tooltip"> | ||
<div | ||
className={`tooltip__content tooltip__content--${position}`} | ||
style={{backgroundColor: bgcolor, color: fgcolor}}> | ||
{content} | ||
</div> | ||
<div block='tooltip' {...rest}> | ||
<span block='tooltip' elem='content' mods={mods}>{content}</span> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
Tooltip.defaultProps = { | ||
bgcolor: 'black', | ||
fgcolor: 'white', | ||
position: 'top' | ||
} | ||
|
||
Tooltip.propTypes = { | ||
bgcolor: PropTypes.string.isRequired, | ||
bottom: PropTypes.bool, | ||
children: PropTypes.any.isRequired, | ||
content: PropTypes.any.isRequired, | ||
fgcolor: PropTypes.string.isRequired, | ||
position: PropTypes.oneOf([ | ||
'top', | ||
'right', | ||
'bottom', | ||
'left' | ||
]).isRequired | ||
left: PropTypes.bool, | ||
primary: PropTypes.bool, | ||
right: PropTypes.bool, | ||
top: PropTypes.bool, | ||
urgent: PropTypes.bool | ||
} | ||
|
||
export default Tooltip |
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,39 @@ | ||
/* global describe, it */ | ||
import React from 'react' | ||
import expect from 'must' | ||
import { shallow } from 'enzyme' | ||
import Tooltip from '../react/Tooltip' | ||
|
||
describe('<Tooltip />', () => { | ||
it('renders as a tooltip', () => { | ||
const wrapper = shallow(<Tooltip content="testtip">testtip</Tooltip>) | ||
expect(wrapper.is('div')).to.be.true() | ||
expect(wrapper.hasClass('tooltip')).to.be.true() | ||
}) | ||
|
||
it('renders as a tooltip__content', () => { | ||
const wrapper = shallow(<Tooltip content="testtip">testtip</Tooltip>) | ||
expect(wrapper.children()).to.have.length(2) | ||
expect(wrapper.children().at(0).is('span')).to.be.true() | ||
expect(wrapper.children().at(0).html()).to.equal('<span class="tooltip__content">testtip</span>') | ||
expect(wrapper.children().at(1).text()).to.equal('testtip') | ||
}) | ||
|
||
it('renders classes', () => { | ||
const wrapper = shallow(<Tooltip bottom left right top primary urgent content="bar foo">foo bar</Tooltip>) | ||
const content = wrapper.children('.tooltip__content') | ||
expect(wrapper.hasClass('tooltip')).to.be.true() | ||
expect(content.hasClass('tooltip__content--bottom')).to.be.true() | ||
expect(content.hasClass('tooltip__content--left')).to.be.true() | ||
expect(content.hasClass('tooltip__content--right')).to.be.true() | ||
expect(content.hasClass('tooltip__content--top')).to.be.true() | ||
expect(content.hasClass('tooltip__content--primary')).to.be.true() | ||
expect(content.hasClass('tooltip__content--urgent')).to.be.true() | ||
}) | ||
|
||
it('renders its text', () => { | ||
const wrapper = shallow(<Tooltip content="muspi">lorem ipsum</Tooltip>) | ||
expect(wrapper.children('.tooltip__content').text()).to.equal('muspi') | ||
expect(wrapper.text()).to.equal('muspilorem ipsum') | ||
}) | ||
}) |
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