Skip to content

Commit dc52656

Browse files
committed
Improve code block line wrapping
- Moves comment section to the bottom
1 parent d044083 commit dc52656

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

packages/ui/src/components/code-block/code-block.module.css

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
}
3131

3232
.content {
33-
@apply bg-card-background rounded-b-md border;
33+
@apply bg-card-background border-t-border border-t;
3434
@apply font-mono text-xs;
3535
@apply flex-1;
3636
@apply flex flex-col;
37-
@apply overflow-hidden;
37+
@apply overflow-scroll;
3838
}
3939

4040
.neutral {
@@ -57,17 +57,19 @@
5757
@apply border-brand-yellow;
5858
}
5959

60-
.scroll-container {
61-
@apply overflow-y-auto p-3;
62-
@apply w-full;
60+
.code-label {
61+
@apply p-3;
62+
@apply border-t-border border-t;
6363
}
6464

65-
.code-label {
66-
@apply text-text-secondary mb-1;
65+
.code-label-text {
66+
@apply text-text-secondary;
67+
@apply font-mono text-xs;
6768
}
6869

6970
.pre {
70-
@apply bg-transparent! p-0!;
71+
@apply bg-transparent! px-3! my-0!;
72+
@apply py-3;
7173
}
7274

7375
.code.wrap {

packages/ui/src/components/code-block/code-block.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const CodeBlock = ({
3232
const [theme] = useTheme();
3333

3434
return (
35-
<div className={cn(styles['code-block'], className)}>
35+
<div className={cn(styles['code-block'], styles[variant], className)}>
3636
<div className={styles.header}>
3737
<div className={styles['header-left']}>
3838
{title && <span className={styles.title}>{title}</span>}
@@ -44,21 +44,23 @@ const CodeBlock = ({
4444
<CopyButton value={copy || code} size="sm" />
4545
</div>
4646
</div>
47-
<div className={cn(styles.content, styles[variant])}>
48-
<div className={cn(styles['scroll-container'], 'styled-vertical-scrollbar')}>
49-
{codeLabel && <div className={styles['code-label']}>{codeLabel}</div>}
50-
<SyntaxHighlighter
51-
language={language}
52-
style={theme === 'dark' ? darkStyle : lightStyle}
53-
wrapLines={WRAP}
54-
wrapLongLines={WRAP}
55-
className={styles.pre}
56-
codeTagProps={{ className: cn(styles.code, { [styles.wrap]: WRAP }) }}
57-
>
58-
{code}
59-
</SyntaxHighlighter>
60-
</div>
47+
<div className={cn(styles.content)}>
48+
<SyntaxHighlighter
49+
language={language}
50+
style={theme === 'dark' ? darkStyle : lightStyle}
51+
wrapLines={WRAP}
52+
wrapLongLines={WRAP}
53+
className={styles.pre}
54+
codeTagProps={{ className: cn(styles.code, { [styles.wrap]: WRAP }) }}
55+
>
56+
{code}
57+
</SyntaxHighlighter>
6158
</div>
59+
{codeLabel && (
60+
<div className={styles['code-label']}>
61+
<p className={styles['code-label-text']}>{codeLabel}</p>
62+
</div>
63+
)}
6264
</div>
6365
);
6466
};

0 commit comments

Comments
 (0)