Skip to content

Commit dfb870d

Browse files
feat(refactor & style): code-block, code-text, copy-button
1 parent 23e8eb9 commit dfb870d

File tree

3 files changed

+39
-53
lines changed

3 files changed

+39
-53
lines changed
Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
.code_block {
2+
display: flex;
3+
justify-content: space-between;
24
position: relative;
35
padding: 10px;
46
font-size: 15px;
57
word-wrap: break-word;
68
white-space: pre-wrap;
79
background: #020617;
810
overflow: auto;
9-
line-height: 1.6;
10-
border: 1px solid #10b981;
11-
border-left: 2px solid #b91c1c;
11+
border: 2px solid #10b981;
12+
border-left: 3px solid #3b82f6;
1213
color: #564;
13-
min-width: 200px;
14-
width: 800px;
15-
display: flex;
16-
justify-content: space-between;
17-
}
18-
19-
.copy_block {
20-
display: flex;
21-
flex-direction: column;
22-
justify-content: flex-start;
23-
}
24-
25-
.copy_button {
26-
position: relative;
27-
cursor: pointer;
28-
color: #fff;
29-
background: gray;
30-
border-radius: 0.5em;
31-
padding: 2px 7px;
32-
margin: 10px;
33-
}
34-
35-
.copied_text {
36-
background: #fff;
37-
padding: 5px;
38-
color: #161b22;
39-
display: none;
40-
}
14+
}

apps/web/components/CodeBlock.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,39 @@ export default function CodeBlock({ block }: { block: any }) {
1414

1515
const [showCopiedMessage, setShowCopiedMessage] = useState(false);
1616

17-
return (
18-
<div className="max-w-full relative">
19-
<div className={`${styles.copy_block} absolute top-2 right-2 z-10`}>
20-
<button
21-
className="text-gray-500 p-1 relative"
22-
onClick={() => {
23-
navigator.clipboard.writeText(code).then(() => {
24-
setShowCopiedMessage(true);
25-
setTimeout(() => {
26-
setShowCopiedMessage(false);
27-
}, 2000);
28-
});
29-
}}
30-
>
31-
{showCopiedMessage ? <CopyTick /> : <CopyIcon />}
32-
</button>
33-
</div>
34-
<div className="max-w-full overflow-auto relative">
35-
<pre className={`${styles.code_block} rounded-3xl px-4 sm:px-6 md:px-8`}>
36-
<code className="language-javascript">{code}</code>
37-
</pre>
17+
return (
18+
<div>
19+
<style>
20+
{`
21+
code[class*="language-"], pre[class*="language-"]{
22+
23+
font-family: Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New;;
24+
font-size: 5rem
25+
line-height: 2rem
26+
}
27+
`}
28+
</style>
29+
<div className="max-w-full relative">
30+
<div className="flex w-full justify-end pr-1 pt-1 z-10 absolute">
31+
<button
32+
className="text-slate-100"
33+
onClick={() => {
34+
navigator.clipboard.writeText(code).then(() => {
35+
setShowCopiedMessage(true);
36+
setTimeout(() => {
37+
setShowCopiedMessage(false);
38+
}, 2000);
39+
});
40+
}}
41+
>
42+
{showCopiedMessage ? <CopyTick /> : <CopyIcon />}
43+
</button>
44+
</div>
45+
<div className="max-w-full overflow-auto relative">
46+
<pre className={`${styles.code_block} w-full px-4 sm:px-6 md:px-8`}>
47+
<code className="language-javascript">{code}</code>
48+
</pre>
49+
</div>
3850
</div>
3951
</div>
4052
);

apps/web/components/NotionRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const NotionRenderer = ({ recordMap }: { recordMap: any }) => {
1919
.dark-mode {
2020
background: #111827;
2121
color: #ffffff
22-
}
22+
}
2323
.notion-title{
2424
font-family: open-montserrat;
2525
font-size: xxx-large;

0 commit comments

Comments
 (0)