Skip to content

Commit

Permalink
feat(tooltip): Extend React.Component
Browse files Browse the repository at this point in the history
  • Loading branch information
lzcabrera committed Sep 29, 2017
1 parent d88ee7b commit c18c7f4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
41 changes: 30 additions & 11 deletions src/components/Tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,36 @@ import styles from './Tooltip.modules.scss'
/**
* Provide more detailed instructions.
*/
const Tooltip = ({ direction, children, ...rest }) => {
return (
<div {...safeRest(rest)} className={styles.wrapper}>
<span className={styles[direction]}>
{children}
</span>
<button className={styles.trigger}>
<DecorativeIcon symbol="questionMarkCircle" size={16} />
</button>
</div>
)
class Tooltip extends React.Component {
constructor(props) {
super(props)

this.state = {
opened: false
}
}

onClick = (event) => {
const { onClick } = this.props

this.setState({ opened: true })
}

render() {
const { direction, children, ...rest } = this.props

return (
<div {...safeRest(rest)} className={styles.wrapper}>
<span className={styles[direction]}>
{children}
</span>
<button className={styles.trigger}>
<DecorativeIcon symbol="questionMarkCircle" size={16} />
</button>
</div>
)

}
}

Tooltip.propTypes = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tooltip/Tooltip.modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

.base {
display: block;
display: none;
//position: absolute;
// top: -10px;
// right: 5px;
Expand Down
19 changes: 9 additions & 10 deletions src/components/Tooltip/__tests__/Tooltip.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@ describe('Tooltip', () => {
expect(tooltip.find('button')).toContainReact(<DecorativeIcon symbol="questionMarkCircle" size={16} />)
})

it('has a bubble', () => {
it('has a direction', () => {
let tooltip = doShallow()
expect(tooltip.find('span')).toHaveClassName('right')

tooltip = doShallow({direction: 'left'})
expect(tooltip.find('span')).toHaveClassName('left')
})

it('has a bubble and is hidden by default', () => {
const tooltip = doShallow()

expect(tooltip.find('span').text()).toEqual('Helper text')
})

// it('can set direction', () => {
// let tooltip = doShallow()
// expect(tooltip).toHaveClassName('right')
//
// tooltip = doShallow({ direction: 'left' })
// expect(tooltip).toHaveClassName('left')
//
// })

it('passes additional attributes to the element', () => {
const tooltip = doShallow({ id: 'the-id', 'data-some-attr': 'some value' })

Expand Down

0 comments on commit c18c7f4

Please sign in to comment.