import React, { useState } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import './tooltip.css'; const arrowPositionStyle = { bottom: { top: -15, left: '50%', transform: 'translateX(-50%)', }, 'bottom-left': { top: -15, left: 5 }, 'bottom-right': { top: -15, right: 5 }, right: { top: 'calc(50% - 8px)', left: -15, transform: 'rotate(270deg)', }, left: { top: 'calc(50% - 8px)', right: -15, transform: 'rotate(-270deg)', }, }; const Tooltip = ({ position, content, tight, children }) => { const [isActive, setIsActive] = useState(false); return (
{ if (!isActive) { setIsActive(true); } }} onMouseOut={() => { if (isActive) { setIsActive(false); } }} > {children}
{content}
); }; Tooltip.defaultProps = { tight: false, position: 'bottom', }; Tooltip.propTypes = { tight: PropTypes.bool, position: PropTypes.oneOf([ 'bottom', 'bottom-left', 'bottom-right', 'left', 'right', ]), children: PropTypes.node.isRequired, content: PropTypes.node.isRequired, }; export default Tooltip;