-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathArticleInfo.tsx
206 lines (186 loc) · 4.74 KB
/
ArticleInfo.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import { css } from "@emotion/react";
import type { ReactNode } from "react";
import { useEffect, useState } from "react";
import {
Colors,
LineHeight,
Typography,
Weight,
getSpace,
} from "../lib/variables";
import { MaterialSymbol } from "./MaterialSymbol";
interface Props {
secret: boolean;
modified: boolean;
organizationUrlName: string | null;
published: boolean;
errorMessages: string[];
qiitaItemUrl: string | null;
slide: boolean;
isOlderThanRemote: boolean;
}
export const ArticleInfo = ({
secret,
modified,
organizationUrlName,
published,
errorMessages,
qiitaItemUrl,
slide,
isOlderThanRemote,
}: Props) => {
const [isOpen, setIsOpen] = useState(
localStorage.getItem("openInfoState") === "true" ? true : false,
);
const toggleAccordion = (event: React.MouseEvent<HTMLInputElement>) => {
event.preventDefault();
setIsOpen((prev) => !prev);
};
useEffect(() => {
localStorage.setItem("openInfoState", JSON.stringify(isOpen));
}, [isOpen]);
return (
<>
<details css={infoStyle} open={isOpen}>
<summary css={infoSummaryStyle} onClick={toggleAccordion}>
記事情報
</summary>
<InfoItem title="公開範囲">
{secret ? (
<>
<MaterialSymbol
css={{ color: Colors.disabled }}
size={14}
fill={true}
>
lock
</MaterialSymbol>{" "}
限定共有
</>
) : (
<>
<MaterialSymbol size={14} css={{ color: Colors.disabled }}>
public
</MaterialSymbol>{" "}
全体
</>
)}
</InfoItem>
<InfoItem title="記事の状態">
{published ? (
qiitaItemUrl ? (
<a href={qiitaItemUrl} target="_blank" rel="noopener noreferrer">
投稿済み
</a>
) : (
"投稿済み"
)
) : (
"未投稿"
)}
</InfoItem>
<InfoItem title="差分">{modified ? "あり" : "なし"}</InfoItem>
<InfoItem title="Organization">
{organizationUrlName || "紐付けなし"}
</InfoItem>
<InfoItem title="スライドモード">{slide ? "ON" : "OFF"}</InfoItem>
</details>
{isOlderThanRemote && (
<div css={errorContentsStyle}>
<p css={errorStyle}>
<MaterialSymbol fill={true} css={exclamationIconStyle}>
error
</MaterialSymbol>
{
"この記事ファイルの内容は、Qiita上の記事より古い可能性があります。"
}
</p>
</div>
)}
{errorMessages.length > 0 && (
<div css={errorContentsStyle}>
{errorMessages.map((errorMessage, index) => (
<p key={`error-message-${index}`} css={errorStyle}>
<MaterialSymbol fill={true} css={exclamationIconStyle}>
error
</MaterialSymbol>
{errorMessage}
</p>
))}
</div>
)}
</>
);
};
const infoStyle = css({
backgroundColor: Colors.gray10,
borderRadius: 8,
display: "flex",
flexDirection: "column",
padding: `${getSpace(3 / 2)}px ${getSpace(2)}px`,
width: "100%",
"& > summary::after": {
fontFamily: "Material Symbols Outlined",
content: "'expand_less'",
},
"&[open] > summary::after": {
content: "'expand_more'",
},
});
const infoSummaryStyle = css({
alignItems: "center",
display: "flex",
cursor: "pointer",
"&::-webkit-details-marker": {
display: "none",
},
});
interface InfoItemProps {
children?: ReactNode;
title: string;
}
const InfoItem = ({ children, title }: InfoItemProps) => {
return (
<div css={infoListStyle}>
<p css={titleStyle}>{title}</p>
<p css={bodyStyle}>{children}</p>
</div>
);
};
const infoListStyle = css({
display: "grid",
gridTemplateColumns: "100px minmax(0, 1fr)",
gap: getSpace(3 / 2),
"& + &": {
marginTop: getSpace(1 / 2),
},
});
const titleStyle = css({
color: Colors.disabled,
fontSize: Typography.body2,
fontWeight: Weight.bold,
});
const bodyStyle = css({
display: "flex",
alignItems: "center",
gap: ` 0 ${getSpace(1 / 2)}px`,
fontSize: Typography.body2,
lineHeight: LineHeight.bodyDense,
wordBreak: "break-word",
});
const exclamationIconStyle = css({
color: Colors.yellow60,
});
const errorContentsStyle = css({
marginTop: getSpace(3),
});
const errorStyle = css({
alignItems: "center",
display: "flex",
fontSize: Typography.body2,
lineHeight: LineHeight.bodyDense,
gap: getSpace(1 / 2),
"& + &": {
marginTop: getSpace(3 / 2),
},
});