From 7cab575ee84c3189b30dfad92f974ddf1c22d6ed Mon Sep 17 00:00:00 2001 From: Nicko Winner-Arroyo Date: Fri, 16 Oct 2020 17:33:00 -0400 Subject: [PATCH] Add listeners and attributes to tooltips --- src/Tooltip/index.js | 8 ++++++-- src/Tooltip/stories.js | 44 +++++++++++++++--------------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/Tooltip/index.js b/src/Tooltip/index.js index 85c4b70..3667962 100644 --- a/src/Tooltip/index.js +++ b/src/Tooltip/index.js @@ -1,10 +1,12 @@ import PropTypes from 'prop-types'; import React from 'react'; import { POSITIONS } from '../constants'; +import useEventListener from '../hooks/useEventListener'; -const Tooltip = ({ children, id, position }) => { +const Tooltip = ({ children, id, position, onClose, onOpen, onReposition, ...rest }) => { + const hxRef = useEventListener({ onClose, onOpen, onReposition }); return ( - + {children} ); @@ -14,6 +16,8 @@ Tooltip.propTypes = { children: PropTypes.node.isRequired, id: PropTypes.string.isRequired, position: PropTypes.oneOf(POSITIONS), + relativeTo: PropTypes.string, + htmlFor: PropTypes.string, }; Tooltip.defaultProps = { diff --git a/src/Tooltip/stories.js b/src/Tooltip/stories.js index e05f5ff..c525baf 100644 --- a/src/Tooltip/stories.js +++ b/src/Tooltip/stories.js @@ -1,43 +1,31 @@ import centered from '@storybook/addon-centered/react'; import { storiesOf } from '@storybook/react'; -import React, { useState } from 'react'; - -import Select from '../Select'; +import React from 'react'; +import { action } from '@storybook/addon-actions'; +import { select, text } from '@storybook/addon-knobs/react'; import Tooltip from '../Tooltip'; +import { POSITIONS } from '../constants'; const id = 'tooltipDemo'; storiesOf('Tooltip', module) .addDecorator(centered) .add('All Knobs', () => { - const [position, setPosition] = useState('top-left'); - - const handleChange = ({ target: { value } }) => { - setPosition(value); - }; + let position = select('positions', POSITIONS, 'top-left'); + let content = text('content', 'I am a tool tip'); return ( -
+ <> - - Some Message + + {content} -
- -
-
+ ); });