1 | import React from "react";
|
2 | import { Popover } from "antd";
|
3 | import { Button } from "antd";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export 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 | }
|