/*
* @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, // 最多显示的行数 number
symbol: '展开', // 自定义展开描述文案 ReactNode
suffix: '', // 自定义省略内容后缀 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}>
<Paragraph
ellipsis={{
rows,
expandable: true,
symbol: '展开',
suffix: '',
}}
>
{isShow ? (
article
) : (
<>
{article}
<span className={style.collapseBtn} onClick={this.onCollapse}>
收起
</span>
</>
)}
</Paragraph>
</div>
);
}
}
export default Demo;
基于antd的Typography中的Paragraph