import React, { FC, memo, useRef, useState } from 'react'; import { Wrapper } from '../../..'; import { cn } from '../../util/bem'; import { SizeType } from '../../util/global-props'; import { useAutoPosition } from './autoposition.hook'; import './tooltip.component.scss'; export type TooltipPropsType = { className?: string; children: React.ReactNode; message?: React.ReactNode; title?: string disabled?: boolean; timeout?: number; manual?: boolean; margin?: SizeType; menuWidth?: string; position?: | 'auto-vertical-left' | 'auto-vertical-center' | 'auto-vertical-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'top-left' | 'top-center' | 'top-right'; style?: React.CSSProperties; } const className = cn('tooltip'); export const Tooltip: FC = memo((props) => { const triggerEl = useRef(null); const dropdownEl = useRef(null); const [ open, setOpen ] = useState(false); const [ autoPosition ] = useAutoPosition({ dropdownEl: dropdownEl.current, triggerEl: triggerEl.current, openState: props.manual || open, position: props.position }); const onMouseEnter = () => { setOpen(true); }; const onMouseLeave = () => { setOpen(false); }; return (
{ props.children }
e.stopPropagation() } > { props.message && ( { props.title && { props.title } } { props.message } ) }
); }); Tooltip.defaultProps = { disabled: false, position: 'auto-vertical-center', timeout: 200 };