Skip to content

Commit 28e5cf9

Browse files
committed
More compact bash copy component
1 parent cd57949 commit 28e5cf9

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

web/src/components/docs/mdx/code-demo.tsx

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import { useMemo, useState } from 'react'
66

77
import { MermaidDiagram } from './mermaid-diagram'
88

9-
import { Separator } from '@/components/ui/separator'
10-
119

1210
type CodeDemoChildren = string | JSX.Element | JSX.Element[]
1311

@@ -177,51 +175,33 @@ export function CodeDemo({ children, language, rawContent }: CodeDemoProps) {
177175

178176
if (isMermaid) {
179177
return (
180-
<div className="rounded-lg border bg-muted/30 px-4 w-full my-3 transition-all group hover:bg-muted/40 overflow-hidden">
181-
<div className="flex items-center justify-between h-6 mt-0.5 mb-0.5">
182-
<div className="text-[10px] text-muted-foreground/40 font-mono tracking-wide">
178+
<div className="bg-zinc-800/60 rounded-md w-full my-3 overflow-hidden">
179+
<div className="flex items-center justify-between px-3 py-2">
180+
<div className="text-xs text-white/40 font-mono">
183181
mermaid diagram
184182
</div>
185183
<button
186184
onClick={() => copyToClipboard(childrenContent)}
187-
className="p-1 hover:bg-muted rounded-md transition-all md:opacity-0 md:group-hover:opacity-100 focus:opacity-100 focus-visible:outline-none"
185+
className="p-2 rounded-md text-white/60 hover:text-white hover:bg-white/5 transition-colors duration-200"
188186
aria-label={copied ? 'Copied!' : 'Copy diagram code'}
189187
>
190188
{copied ? (
191-
<Check className="h-3.5 w-3.5 text-green-500" />
189+
<Check className="h-4 w-4 text-green-500" />
192190
) : (
193-
<Copy className="h-3.5 w-3.5 text-muted-foreground/50 hover:text-foreground md:text-muted-foreground" />
191+
<Copy className="h-4 w-4" />
194192
)}
195193
</button>
196194
</div>
197-
<Separator className="bg-border/20 mb-0.5" />
198-
<div className="py-4">
195+
<div className="px-3 pb-4">
199196
<MermaidDiagram code={childrenContent} />
200197
</div>
201198
</div>
202199
)
203200
}
204201

205202
return (
206-
<div className="rounded-lg border px-4 w-full my-3 transition-all group overflow-x-auto">
207-
<div className="flex items-center justify-between h-6 mt-0.5 mb-0.5">
208-
<div className="text-[10px] text-muted-foreground/40 font-mono tracking-wide">
209-
{language.toLowerCase()}
210-
</div>
211-
<button
212-
onClick={() => copyToClipboard(childrenContent)}
213-
className="p-1 hover:bg-muted rounded-md transition-all md:opacity-0 md:group-hover:opacity-100 focus:opacity-100 focus-visible:outline-none"
214-
aria-label={copied ? 'Copied!' : 'Copy code'}
215-
>
216-
{copied ? (
217-
<Check className="h-3.5 w-3.5 text-green-500" />
218-
) : (
219-
<Copy className="h-3.5 w-3.5 text-muted-foreground/50 hover:text-foreground md:text-muted-foreground" />
220-
)}
221-
</button>
222-
</div>
223-
{language && <Separator className="bg-border/20 mb-0.5" />}
224-
<div>
203+
<div className="bg-zinc-800/60 rounded-md px-3 py-2.5 w-full my-3 flex items-center justify-between overflow-x-auto">
204+
<div className="flex-1 min-w-0">
225205
<Highlight
226206
theme={highlightTheme}
227207
code={childrenContent}
@@ -230,11 +210,12 @@ export function CodeDemo({ children, language, rawContent }: CodeDemoProps) {
230210
{({ className, style, tokens, getLineProps, getTokenProps }) => {
231211
return (
232212
<pre
233-
className={`${className} text-[13px] leading-relaxed py-2 bg-transparent rounded-lg scrollbar-thin scrollbar-thumb-muted-foreground/10 scrollbar-track-transparent`}
213+
className={`${className} text-sm leading-relaxed bg-transparent scrollbar-thin scrollbar-thumb-muted-foreground/10 scrollbar-track-transparent`}
234214
style={{
235215
...style,
236216
backgroundColor: 'transparent',
237217
color: tokenColor || style.color,
218+
margin: 0,
238219
}}
239220
>
240221
{tokens.map((line, i) => {
@@ -269,6 +250,17 @@ export function CodeDemo({ children, language, rawContent }: CodeDemoProps) {
269250
}}
270251
</Highlight>
271252
</div>
253+
<button
254+
onClick={() => copyToClipboard(childrenContent)}
255+
className="flex-shrink-0 p-2 rounded-md text-white/60 hover:text-white hover:bg-white/5 transition-colors duration-200 ml-2"
256+
aria-label={copied ? 'Copied!' : 'Copy code'}
257+
>
258+
{copied ? (
259+
<Check className="h-4 w-4 text-green-500" />
260+
) : (
261+
<Copy className="h-4 w-4" />
262+
)}
263+
</button>
272264
</div>
273265
)
274266
}

0 commit comments

Comments
 (0)