Skip to content

Commit c4d5497

Browse files
fix svg preview and add template preview in home page
1 parent 2454945 commit c4d5497

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

app/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
"use client";
22

33
import HeroSection from "@/components/Home/HeroSection";
4+
import PreviewSection from "@/components/Home/PreviewSection";
45

56
export default function Page() {
6-
return <HeroSection />;
7+
return (
8+
<>
9+
<HeroSection />
10+
<PreviewSection />
11+
</>
12+
);
713
}

components/Collections/WorkViewer.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,32 @@ export function WorkViewer({
6565
}
6666
};
6767

68+
const fixSvg = (svg: string) => {
69+
// get width/height
70+
const widthMatch = svg.match(/width="(\d+)"/);
71+
const heightMatch = svg.match(/height="(\d+)"/);
72+
73+
if (widthMatch && heightMatch) {
74+
const width = widthMatch[1];
75+
const height = heightMatch[1];
76+
77+
// make width/height to 100%
78+
svg = svg
79+
.replace(/width="[^"]*"/, 'width="100%"')
80+
.replace(/height="[^"]*"/, 'height="100%"');
81+
82+
// add viewBox if missing
83+
if (!/viewBox=/.test(svg)) {
84+
svg = svg.replace(
85+
/<svg([^>]*)>/,
86+
`<svg$1 viewBox="0 0 ${width} ${height}">`
87+
);
88+
}
89+
}
90+
91+
return svg;
92+
};
93+
6894
return (
6995
<AnimatePresence>
7096
{isOpen && (
@@ -160,7 +186,9 @@ export function WorkViewer({
160186
{work.svg_data ? (
161187
<div
162188
className="w-full h-full p-2 flex items-center justify-center"
163-
dangerouslySetInnerHTML={{ __html: work.svg_data }}
189+
dangerouslySetInnerHTML={{
190+
__html: fixSvg(work.svg_data),
191+
}}
164192
/>
165193
) : (
166194
<div className="text-center text-slate-600 dark:text-neutral-400">

components/Home/PreviewSection.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const PreviewSection = () => {
2+
return (
3+
<section className="relative z-10 mt-16 w-full mb-5">
4+
<div className="mx-auto max-w-6xl space-y-6 rounded-3xl border border-slate-200 bg-white/70 px-6 py-8 shadow-2xl shadow-emerald-400/10 backdrop-blur dark:border-neutral-800 dark:bg-neutral-900/70">
5+
<div className="flex flex-col gap-2 text-center">
6+
<p className="text-sm font-semibold uppercase tracking-[0.3em] text-emerald-500 dark:text-violet-400">
7+
Instant Preview
8+
</p>
9+
<p className="text-2xl font-bold text-slate-900 dark:text-neutral-100">
10+
See your raster input and the SVG output in one glance
11+
</p>
12+
<p className="text-sm text-slate-600 dark:text-neutral-400">
13+
Drop any PNG, JPG or other raster image and watch the converter
14+
render the matching SVG on the right.
15+
</p>
16+
</div>
17+
18+
<div className="grid gap-6 sm:grid-cols-2">
19+
<div className="flex flex-col gap-4 rounded-2xl border border-slate-200 bg-zinc-50/80 p-5 dark:border-neutral-800 dark:bg-neutral-900/50">
20+
<div className="aspect-[4/3] w-full rounded-2xl bg-gradient-to-br from-emerald-100 to-white ring-1 ring-emerald-200 dark:from-violet-900/30 dark:to-purple-900/60 dark:ring-violet-500/40">
21+
<div className="flex h-full flex-col items-center justify-center gap-2 text-slate-500 dark:text-neutral-400">
22+
<span className="text-lg font-semibold text-slate-600 dark:text-neutral-100">
23+
Input Placeholder
24+
</span>
25+
<span className="text-xs uppercase tracking-[0.3em]">
26+
PNG / JPG
27+
</span>
28+
</div>
29+
</div>
30+
<div className="space-y-1 text-sm text-slate-600 dark:text-neutral-400">
31+
<p className="font-semibold text-slate-900 dark:text-neutral-100">
32+
Raster Image
33+
</p>
34+
<p className="text-xs text-slate-500 dark:text-neutral-500">
35+
This area will show the file you upload before conversion.
36+
</p>
37+
</div>
38+
</div>
39+
40+
<div className="flex flex-col gap-4 rounded-2xl border border-slate-200 bg-white/80 p-5 dark:border-neutral-800 dark:bg-neutral-900/60">
41+
<div className="aspect-[4/3] w-full rounded-2xl bg-gradient-to-br from-slate-900 to-zinc-900 shadow-inner shadow-black/30">
42+
<div className="flex h-full flex-col items-center justify-center gap-2 text-emerald-400">
43+
<span className="text-lg font-semibold">
44+
Output Placeholder
45+
</span>
46+
<span className="text-xs uppercase tracking-[0.3em]">
47+
SVG Vector
48+
</span>
49+
</div>
50+
</div>
51+
<div className="space-y-1 text-sm text-slate-600 dark:text-neutral-400">
52+
<p className="font-semibold text-slate-900 dark:text-neutral-100">
53+
Editable SVG
54+
</p>
55+
<p className="text-xs text-slate-500 dark:text-neutral-500">
56+
The converted vector will appear here with clean paths.
57+
</p>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
</section>
63+
);
64+
};
65+
66+
export default PreviewSection;

0 commit comments

Comments
 (0)