|
1 | | -/* eslint-disable react/prop-types */ |
2 | | -import React, { useState } from 'react'; |
3 | | -import styles from './index.styl'; |
4 | | - |
5 | | -/* |
6 | | - Custom Tooltip Component |
7 | | - Content Prop: String to be displayed when hovered |
8 | | - Disabled Prop: Varibale to set css display: none; |
9 | | - Location Prop: Where tooltip should be displayed(See css file) |
10 | | -*/ |
11 | | - |
12 | | -const Tooltip = (props) => { |
13 | | - let disabled = props.disabled; |
14 | | - let timeout; |
15 | | - const [active, setActive] = useState(false); |
16 | | - |
17 | | - const showTip = () => { |
18 | | - timeout = setTimeout(() => { |
19 | | - setActive(true); |
20 | | - }, props.delay || 1000); |
21 | | - }; |
22 | | - |
23 | | - const hideTip = () => { |
24 | | - clearInterval(timeout); |
25 | | - setActive(false); |
26 | | - }; |
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { Tooltip as MainToolTip } from 'app/components/Tooltip'; |
27 | 4 |
|
| 5 | +const Tooltip = ({ location, content, disabled, children }) => { |
28 | 6 | return ( |
29 | | - <div |
30 | | - className={styles.TooltipWrapper} |
31 | | - // When to show the tooltip |
32 | | - onMouseEnter={showTip} |
33 | | - onMouseLeave={hideTip} |
| 7 | + <MainToolTip |
| 8 | + content={content} |
| 9 | + placement={location === 'default' ? 'bottom' : location} |
| 10 | + enterDelay={1000} |
| 11 | + disabled={disabled} |
34 | 12 | > |
35 | | - {props.children} |
36 | | - {active && ( |
37 | | - <div className={disabled ? styles.disabled : styles[`${props.location}`]}> |
38 | | - {props.content} |
39 | | - </div> |
40 | | - )} |
41 | | - </div> |
| 13 | + <div> |
| 14 | + {children} |
| 15 | + </div> |
| 16 | + </MainToolTip> |
42 | 17 | ); |
43 | 18 | }; |
44 | 19 |
|
| 20 | +Tooltip.propTypes = { |
| 21 | + location: PropTypes.string, |
| 22 | + content: PropTypes.string || PropTypes.node, |
| 23 | + disabled: PropTypes.bool, |
| 24 | +}; |
| 25 | + |
45 | 26 | export default Tooltip; |
0 commit comments