UNPKG

qt-public-ui

Version:

新设计规范下业务组件库

47 lines 1.96 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import React, { useEffect, useState, useRef } from 'react'; import { Tooltip } from 'antd'; import './style.less'; var SINGLE_LINE_STYLE = { overflow: 'hidden', 'text-overflow': 'ellipsis', 'white-space': 'nowrap', width: '100%' }; var MULTIPLE_LINES_STYLE = { overflow: 'hidden', 'text-overflow': 'ellipsis', display: '-webkit-box', '-webkit-box-orient': 'vertical', width: '100%' }; var AutoAddTooltipComp = function AutoAddTooltipComp(props) { var contentFunc = props.contentFunc, tooltipProps = props.tooltipProps; var _useState = useState(false), isAddTooltip = _useState[0], setIsAddTooltip = _useState[1]; var contentRef = useRef(null); var wrapperStyle = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.type) === 'multipleLines' ? _extends({}, MULTIPLE_LINES_STYLE, { '-webkit-line-clamp': String((tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.lines) || 3) }) : SINGLE_LINE_STYLE; var wrapperClassName = (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.type) === 'multipleLines' ? 'um-ui-auto-add-tooltip-multiple-lines' : 'um-ui-auto-add-tooltip-single-line'; useEffect(function () { if (contentRef.current) { var wrapperDom = contentRef.current; setIsAddTooltip(wrapperDom.scrollWidth > wrapperDom.clientWidth || wrapperDom.scrollHeight > wrapperDom.clientHeight); } }, [tooltipProps]); var content = contentFunc(contentRef, { wrapperStyle: wrapperStyle, wrapperClassName: wrapperClassName }); return isAddTooltip ? /*#__PURE__*/React.createElement(Tooltip, tooltipProps, content) : content; }; var autoAddTooltip = function autoAddTooltip(contentFunc, tooltipProps) { return /*#__PURE__*/React.createElement(AutoAddTooltipComp, { contentFunc: contentFunc, tooltipProps: tooltipProps }); }; export default autoAddTooltip;