Skip to content

Commit b33b158

Browse files
wontoryclaude
andcommitted
refactor(web): add variant prop to preview component
Support fill and center variants for different preview layouts, enabling badge preview without aspect-square constraint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5273db commit b33b158

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

apps/web/src/components/preview.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,37 @@ import Image from 'next/image'
99

1010
import { CodeBlock } from '#components/code-block'
1111

12-
export function Preview({ src, code }: { src: string; code: string }) {
12+
export function Preview({
13+
src,
14+
code,
15+
variant = 'fill',
16+
}: {
17+
src: string
18+
code: string
19+
variant?: 'fill' | 'center'
20+
}) {
1321
return (
1422
<section className="@5xl/main:order-last order-first">
1523
<Card className="@container/card">
1624
<CardHeader>
1725
<CardTitle>Preview</CardTitle>
1826
</CardHeader>
1927
<CardContent className="relative">
20-
<div className="relative aspect-square size-full">
21-
<Image
22-
src={src}
23-
alt="Preview"
24-
fill={true}
25-
draggable={false}
26-
unoptimized={true}
27-
/>
28-
</div>
28+
{variant === 'fill' ? (
29+
<div className="relative aspect-square size-full">
30+
<Image
31+
src={src}
32+
alt="Preview"
33+
fill={true}
34+
draggable={false}
35+
unoptimized={true}
36+
/>
37+
</div>
38+
) : (
39+
<div className="flex min-h-40 items-center justify-center">
40+
<img src={src} alt="Preview" draggable={false} />
41+
</div>
42+
)}
2943
</CardContent>
3044
<CardFooter>
3145
<CodeBlock language="markdown" code={code} />

0 commit comments

Comments
 (0)