UNPKG

1.16 kBJavaScriptView Raw
1import React from "react";
2import { Popover } from "antd";
3import { Button } from "antd";
4/**
5 * ----------------------------------------
6 * 弹窗展示长文章详细内容
7 * 大于trunc(默认10)个字的时候
8 * @param {String} content - 内容
9 * @param {String} [trunc = 10] - 截取
10 * @param {Boolean} [plain = false] - 显示富文本
11 * ----------------------------------------
12 */
13export default function PopArticle({
14 content,
15 plain = false,
16 trunc = 10,
17 ...props
18}) {
19 if (!content) {
20 return null;
21 }
22 const isLarge = content.length > trunc;
23 const title = isLarge
24 ? content.replace(/<.+?>/g, "").substring(0, trunc) + ".."
25 : content;
26
27 const Content = () => {
28 return (
29 <div style={{ width: "300px", height: "150px", overflow: "auto" }}>
30 {plain ? (
31 <span dangerouslySetInnerHTML={{ __html: content }} />
32 ) : (
33 <span>{content}</span>
34 )}
35 </div>
36 );
37 };
38
39 return (
40 <Popover trigger="hover" title="内容详情" content={Content} {...props}>
41 <Button type="link" style={{ maxWidth: "170px" }}>
42 {title}
43 </Button>
44 </Popover>
45 );
46}