/** @Descripttion:* @version:* @Author: WangPeng* @Date: 2021-09-24 11:11:44* @LastEditors: WangPeng* @LastEditTime: 2021-09-24 12:02:30*/import { Typography } from 'antd';import React from 'react';import style from './index.less';const { Paragraph } = Typography;interface props {article: string;rows: number;symbol?: any;suffix?: string;}class Demo extends React.Component<props> {static defaultProps = {article: '', // 要展示的文本rows: 2, // 最多显示的行数 numbersymbol: '展开', // 自定义展开描述文案 ReactNodesuffix: '', // 自定义省略内容后缀 string};state = {key: `${new Date()}`, // key 保持每一个div的key值 已备diff算法更新isShow: false,};// 控制收起onCollapse = () => {this.setState({key: `${new Date()}`,isShow: false,});};render() {const { article, rows } = this.props;const { key, isShow } = this.state;return (<div key={key}><Paragraphellipsis={{rows,expandable: true,symbol: '展开',suffix: '',}}>{isShow ? (article) : (<>{article}<span className={style.collapseBtn} onClick={this.onCollapse}>收起</span></>)}</Paragraph></div>);}}export default Demo;
基于antd的Typography中的Paragraph
