Skip to content

Commit aed60b4

Browse files
authored
Merge pull request #118 from HelixDesignSystem/tooltip-fixes
Add listeners and attributes to tooltips
2 parents a3db488 + 7cab575 commit aed60b4

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

src/Tooltip/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import { POSITIONS } from '../constants';
4+
import useEventListener from '../hooks/useEventListener';
45

5-
const Tooltip = ({ children, id, position }) => {
6+
const Tooltip = ({ children, id, position, onClose, onOpen, onReposition, ...rest }) => {
7+
const hxRef = useEventListener({ onClose, onOpen, onReposition });
68
return (
7-
<hx-tooltip for={id} position={position}>
9+
<hx-tooltip for={id} position={position} ref={hxRef} {...rest}>
810
{children}
911
</hx-tooltip>
1012
);
@@ -14,6 +16,8 @@ Tooltip.propTypes = {
1416
children: PropTypes.node.isRequired,
1517
id: PropTypes.string.isRequired,
1618
position: PropTypes.oneOf(POSITIONS),
19+
relativeTo: PropTypes.string,
20+
htmlFor: PropTypes.string,
1721
};
1822

1923
Tooltip.defaultProps = {

src/Tooltip/stories.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,31 @@
11
import centered from '@storybook/addon-centered/react';
22
import { storiesOf } from '@storybook/react';
3-
import React, { useState } from 'react';
4-
5-
import Select from '../Select';
3+
import React from 'react';
4+
import { action } from '@storybook/addon-actions';
5+
import { select, text } from '@storybook/addon-knobs/react';
66
import Tooltip from '../Tooltip';
7+
import { POSITIONS } from '../constants';
78

89
const id = 'tooltipDemo';
910

1011
storiesOf('Tooltip', module)
1112
.addDecorator(centered)
1213
.add('All Knobs', () => {
13-
const [position, setPosition] = useState('top-left');
14-
15-
const handleChange = ({ target: { value } }) => {
16-
setPosition(value);
17-
};
14+
let position = select('positions', POSITIONS, 'top-left');
15+
let content = text('content', 'I am a tool tip');
1816

1917
return (
20-
<div>
18+
<>
2119
<hx-icon id={id} type="help-circle" />
22-
<Tooltip id={id} position={position}>
23-
Some Message
20+
<Tooltip
21+
id={id}
22+
position={position}
23+
onOpen={action('onOpen')}
24+
onClose={action('onClose')}
25+
onReposition={action('onReposition')}
26+
>
27+
{content}
2428
</Tooltip>
25-
<div style={{ marginTop: 100, width: 300 }}>
26-
<Select id="selectTooltipDemo" label="Position" onChange={handleChange}>
27-
<option value="top-left">Top Left</option>
28-
<option value="top-center">Top Center</option>
29-
<option value="top-right">Top Right</option>
30-
<option value="right-top">Right Top</option>
31-
<option value="right-middle">Right Middle</option>
32-
<option value="right-bottom">Right Bottom</option>
33-
<option value="bottom-right">Bottom Right</option>
34-
<option value="bottom-center">Bottom Center</option>
35-
<option value="bottom-left">Bottom Left</option>
36-
<option value="left-bottom">Left Bottom</option>
37-
<option value="left-middle">Left Middle</option>
38-
<option value="left-top">Left Top</option>
39-
</Select>
40-
</div>
41-
</div>
29+
</>
4230
);
4331
});

0 commit comments

Comments
 (0)