@cainiaofe/cn-ui-m
Version:
51 lines (50 loc) • 2.38 kB
JavaScript
import * as React from 'react';
import pick from 'lodash/pick';
import isNil from 'lodash/isNil';
import classnames from 'classnames';
import isPlainObject from 'lodash/isPlainObject';
// import { registerFormat } from '../../register';
import { CnPopover } from "../../../cn-popover";
// 其他组件
import { domStyleMap } from "../../../../utils/data";
import './index.scss';
export var renderValueHandleEmpty = function (value) {
if (isNil(value) || value === '') {
return '- -';
}
return value;
};
export var textRender = function (value) {
if (isPlainObject(value) && typeof value === 'object') {
// 对象传入,目前支持ToolTips,link
// const linkStyle = value?.link ? { color: '#284cc0' } : {}; // 是否带超链
var styleAttribute = pick(value, Object.keys(domStyleMap));
var textDom = void 0;
if (value === null || value === void 0 ? void 0 : value.link) {
textDom = (React.createElement("a", { rel: "noreferrer", target: "_blank", href: value.link, "data-testid": "cn-format-text", className: classnames({
'cn-format-text--link': !!(value === null || value === void 0 ? void 0 : value.link),
}), style: styleAttribute }, renderValueHandleEmpty(value.text)));
}
else {
textDom = (React.createElement("span", { "data-testid": "cn-format-text", style: styleAttribute }, renderValueHandleEmpty(value.text)));
}
if (value === null || value === void 0 ? void 0 : value.toolTips) {
// toolsTips
var renderContent = function (data) {
return (React.createElement("div", null, data.map(function (item) {
return React.createElement("div", { key: item.desc }, item.desc);
})));
};
if (Array.isArray(value === null || value === void 0 ? void 0 : value.toolTips)) {
return (React.createElement(CnPopover, { content: renderContent(value.toolTips), trigger: "click" }, textDom));
}
else {
return (React.createElement(CnPopover, { content: renderValueHandleEmpty(value.toolTips), trigger: "click" }, textDom));
}
}
return textDom;
}
return renderValueHandleEmpty(value);
};
// 动态注册
// registerFormat('text', textRender);