Created
March 31, 2017 16:55
-
-
Save bernardodiasc/15874f7fa1c02163bcd0776bbbfd0694 to your computer and use it in GitHub Desktop.
Tooltip component
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
import { compose, withState, onlyUpdateForKeys } from 'recompose'; | |
import { themr } from 'react-css-themr'; | |
import Tooltip from './Tooltip'; | |
import style from './Tooltip.css'; | |
export default compose( | |
themr('Tooltip', style), | |
withState('hover', 'onHover', false), | |
onlyUpdateForKeys(['hover']), | |
)(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
import React, { PropTypes } from 'react'; | |
import classNames from 'classnames'; | |
const Tooltip = ({ children, text, position, hover, onHover, theme }) => { | |
const popup = classNames(theme.popup, theme[position]); | |
return ( | |
<span | |
className={theme.tooltip} | |
onMouseEnter={() => onHover(true)} | |
onMouseLeave={() => onHover(false)} | |
> | |
{hover && <span className={popup}>{text}</span>} | |
{children || ''} | |
</span> | |
); | |
}; | |
Tooltip.propTypes = { | |
children: PropTypes.node, | |
text: PropTypes.string, | |
position: PropTypes.oneOf([ | |
'left', | |
'top', | |
'right', | |
'bottom', | |
]), | |
hover: PropTypes.bool, | |
onHover: PropTypes.func, | |
theme: PropTypes.shape({ | |
tooltip: PropTypes.string, | |
popup: PropTypes.string, | |
left: PropTypes.string, | |
top: PropTypes.string, | |
right: PropTypes.string, | |
bottom: PropTypes.string, | |
}), | |
}; | |
Tooltip.defaultProps = { | |
theme: {}, | |
text: '', | |
position: 'left', | |
}; | |
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
import React from 'react'; | |
import { shallow } from 'enzyme'; | |
import Tooltip from './Tooltip.js'; | |
const wrapper = shallow(<Tooltip />); | |
describe('(Component) Tooltip', () => { | |
it('renders without exploding', () => { | |
expect(wrapper).toHaveLength(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment