UNPKG

@i-novus/ui-core

Version:

Базовые UI компоненты

20 lines (19 loc) 1.27 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { forwardRef, useMemo } from 'react'; import classNames from 'classnames'; import { createPortal } from 'react-dom'; import { v4 as generateId } from 'uuid'; import { useConfigProvider } from '../../core'; import { TooltipController } from './TooltipController'; const DEFAULT_GET_CONTAINER = () => document?.body; export const Tooltip = forwardRef((props, ref) => { const { prefix, visible = true, placement = 'top', children, content, className, childrenWrapperClassName, getContainer = DEFAULT_GET_CONTAINER, ...restProps } = props; const { getPrefix } = useConfigProvider(); const prefixCls = getPrefix(prefix); const id = useMemo(() => generateId(), []); if (!visible) { return null; } return (_jsxs(_Fragment, { children: [!!children && (_jsx("span", { "data-tooltip-id": id, className: classNames(`${prefixCls}-tooltip__children-wrapper`, childrenWrapperClassName), children: children })), createPortal(_jsx(TooltipController, { ...restProps, ref: ref, id: id, className: classNames(`${prefixCls}-tooltip`, className), place: placement, children: content }), getContainer() || document.body)] })); }); Tooltip.displayName = 'Tooltip';