import React, { HTMLAttributes, useState } from 'react'; import classNames from 'classnames'; import { CSSTransition } from 'react-transition-group'; import './index.scss'; type Position = | 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight' | 'leftTop' | 'leftCenter' | 'leftBottom' | 'rightTop' | 'rightCenter' | 'rightBottom'; export interface TooltipProps extends HTMLAttributes { position?: Position; tip?: string; children?: React.ReactNode; } const Tooltip: React.FC = (props) => { const { children, position, tip, ...rest } = props; const [isShow, setShow] = useState(false); return ( { setShow(true); }} onMouseOut={() => setShow(false)} > {tip} {children} ); }; Tooltip.defaultProps = { position: 'topCenter', tip: '提示内容', children: '' }; export default Tooltip;