-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathpopupCard.tsx
156 lines (141 loc) · 3.75 KB
/
popupCard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { default as Alert } from "antd/es/alert";
import { default as Card } from "antd/es/card";
import { CopyTextButton } from "./copyTextButton";
import { CSSProperties, ReactNode, useState } from "react";
import styled from "styled-components";
import { ErrorIcon, SuccessIcon } from "icons";
const StyledCard = styled(Card)<{ $backcolor: string }>`
z-index: 3;
margin-top: 4px;
background-color: ${(props) => (props.$backcolor ? props.$backcolor : "#eff9f6")};
border-color: #82bf99;
color: #3b734f;
border: none;
position: absolute;
border-radius: 4px;
line-height: 14px;
font-size: 13px;
word-wrap: break-word;
box-sizing: border-box;
-webkit-box-sizing: border-box;
vertical-align: baseline;
width: 100%;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
`;
const Contain = styled.div`
position: relative;
.ant-card-small > .ant-card-head > .ant-card-head-wrapper > .ant-card-extra {
padding: 0;
}
.ant-card-small > .ant-card-head {
padding: 10px 16px 0px 16px;
font-weight: normal;
font-size: 13px;
color: #333333;
line-height: 13px;
border-bottom: none;
min-height: 31px;
}
.ant-card-small > .ant-card-body {
padding: 0px 0px 10px 0px;
font-size: 13px;
color: #333333;
line-height: 13px;
overflow: auto;
}
.ant-alert {
padding: 0;
font-size: 13px;
}
.ant-card-small > .ant-card-head > .ant-card-head-wrapper > .ant-card-head-title {
padding: 0;
}
.ant-alert-success {
background: transparent;
border: none;
}
.ant-alert-error {
background: transparent;
border: none;
}
`;
const Content = styled.div`
padding-left: 16px;
font-size: 13px;
color: #333333;
line-height: 18px;
max-height: 108px;
overflow: auto;
scrollbar-gutter: stable;
white-space: pre-line;
&::-webkit-scrollbar {
width: 16px;
}
&::-webkit-scrollbar-thumb {
border: 5px solid transparent;
background-clip: content-box;
border-radius: 9999px;
background-color: rgba(139, 143, 163, 0.2);
min-height: 30px;
}
&::-webkit-scrollbar-thumb:hover {
background-color: rgba(139, 143, 163, 0.36);
}
`;
const Tips = styled.div`
margin-top: 4px;
padding: 4px 0 0 16px;
border-top: 1px solid #82bf99;
`;
const MAX_CONTENT_LENGTH = 3000;
interface PopupCardProps {
editorFocus?: boolean;
title?: string;
content?: string;
richContent?: ReactNode;
tips?: ReactNode;
hasError?: boolean;
cardStyle?: CSSProperties;
}
export function PopupCard(props: PopupCardProps) {
const [isPopupHovered, setPopupHovered] = useState(false);
return (
<>
{(props.editorFocus || isPopupHovered) && (
<Contain>
<StyledCard
style={props.cardStyle}
$backcolor={props.hasError ? "#FFF3F1" : "#EFF9F6"}
title={
<Alert
message={props.title}
type={props.hasError ? "error" : "success"}
showIcon
icon={props.hasError ? <ErrorIcon /> : <SuccessIcon />}
/>
}
extra={<CopyTextButton text={props.content ?? ""} />}
size="small"
onMouseEnter={() => {
setPopupHovered(true);
}}
onMouseLeave={() => {
setPopupHovered(false);
}}
onClick={() => {
setPopupHovered(false);
}}
>
<Content>
{props.richContent ??
(props.content?.length && props.content?.length > MAX_CONTENT_LENGTH
? props.content?.substring(0, MAX_CONTENT_LENGTH) + "..."
: props.content)}
</Content>
{props.tips && <Tips>{props.tips}</Tips>}
</StyledCard>
</Contain>
)}
</>
);
}