@xrenders/xflow
Version:
一款功能强大、易用灵活的流程编辑器框架,帮助你轻松构建复杂的工作流和流程产品
83 lines • 4.21 kB
JavaScript
import "antd/es/tooltip/style";
import _Tooltip from "antd/es/tooltip";
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
import React, { memo, useEffect, useState } from 'react';
import "./index.css";
var TextEllipsis = function TextEllipsis(_ref) {
var text = _ref.text,
style = _ref.style,
toolTipProps = _ref.toolTipProps,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'text' : _ref$type,
_ref$rows = _ref.rows,
rows = _ref$rows === void 0 ? 1 : _ref$rows,
className = _ref.className;
var typographyRef = React.useRef(null);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isEllipse = _useState2[0],
setIsEllipse = _useState2[1];
var component = type === 'paragraph' ? (/*#__PURE__*/React.createElement("span", {
ref: typographyRef,
className: "paragraph-ellipsis ".concat(className),
style: Object.assign(Object.assign({}, style), {
display: '-webkit-box',
overflow: 'hidden',
WebkitBoxOrient: 'vertical',
WebkitLineClamp: rows
})
}, text)) : (/*#__PURE__*/React.createElement("span", {
ref: typographyRef,
className: "text-ellipsis ".concat(className),
style: style
}, text));
useEffect(function () {
if (text) {
if (type === 'paragraph') {
var _typographyRef$curren = typographyRef.current,
offsetHeight = _typographyRef$curren.offsetHeight,
scrollHeight = _typographyRef$curren.scrollHeight,
clientHeight = _typographyRef$curren.clientHeight;
setIsEllipse(scrollHeight > clientHeight);
} else {
var _isEllipse = isEleEllipsis(typographyRef === null || typographyRef === void 0 ? void 0 : typographyRef.current);
setIsEllipse(_isEllipse);
}
}
}, [text]);
var isEleEllipsis = function isEleEllipsis(ele) {
var childDiv = document.createElement('em');
ele.appendChild(childDiv);
var rect = ele.getBoundingClientRect();
var childRect = childDiv.getBoundingClientRect();
ele.removeChild(childDiv);
return (
// Horizontal out of range
rect.left > childRect.left || childRect.right > rect.right ||
// Vertical out of range
rect.top > childRect.top || childRect.bottom > rect.bottom
);
};
if (isEllipse) {
return /*#__PURE__*/React.createElement(_Tooltip, Object.assign({
title: text,
getPopupContainer: function getPopupContainer() {
return document.getElementById('xflow-container');
},
color: "#ffff",
overlayInnerStyle: {
color: '#354052',
fontSize: '12px',
borderRadius: '8px'
},
placement: "bottomRight"
}, toolTipProps), component);
}
return component;
};
export default /*#__PURE__*/memo(TextEllipsis);