import * as React from "react"; import Units from "../../units"; import { Popover, Tooltip } from "antd"; import { LocaleContext } from "../../locale/LocaleProvider"; import "./index.less"; interface EllipsisTextProps { isHtml?: boolean; value: string; showMax?: number; } interface EllipsisTextState { } export default class EllipsisText extends React.PureComponent< EllipsisTextProps, EllipsisTextState > { state = {}; static contextType = LocaleContext; context: React.ContextType; static defaultProps = { isHtml: false, showMax: 30, }; toString = (value) => { if (value) { return value.toString(); } else { return value; } }; viewButton = (val: string) => { const { value, isHtml } = this.props; //const { translate } = this.context; //debugger return ( <> <> {isHtml ? (
) : (
{value}
)} // } > {/*{" "}*/} {val}
); }; render() { const { value, isHtml, showMax } = this.props; var text = this.toString(value); if (isHtml) { var re = new RegExp("<[^<>]+>", "g"); text = value?.replace(re, ""); } let style = Units.getLongTextStyle(text && text.substring ? text.substring(0, showMax) : null); return ( <> {!text ? <> : text.length <= showMax || showMax <= 0 ? ( {text} ) : ( {this.viewButton(text.substring(0, showMax) + "...")} )} ); } }