Skip to content

Commit 86cbd30

Browse files
committed
add pair card component
1 parent 5c6486f commit 86cbd30

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

components/PairCard.tsx

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,72 @@
11
import Image from "next/image";
2-
import { Pair } from "@/pages/api/pairs";
3-
import { ArrowUpRightIcon, SwatchBookIcon, TypeIcon } from "lucide-react";
4-
import { Card, CardContent, CardTitle } from "./ui/card";
2+
import { useState } from "react";
3+
import { ClipboardCheckIcon, ClipboardIcon } from "lucide-react";
4+
5+
import PairItem from "./PairItem";
6+
import { Pair } from "@/models/pair";
7+
import { Button } from "./ui/button";
8+
import { Card, CardContent, CardDescription, CardTitle } from "./ui/card";
59

610
interface PairCardProps {
711
pair: Pair;
812
}
913

1014
export default function PairCard({ pair }: PairCardProps) {
15+
const [copied, setCopied] = useState(false);
16+
17+
const copyToClipboard = (font: string, theme: string) => {
18+
navigator.clipboard.writeText(`{
19+
"editor.fontFamily": ${font},
20+
"workbench.colorTheme": ${theme}
21+
}`);
22+
setCopied((prev) => !prev);
23+
};
24+
1125
return (
1226
<Card className="max-w-2xl">
1327
<div className="aspect-[16/9] overflow-hidden rounded-lg">
1428
<Image
15-
width={400}
16-
height={300}
29+
width={640}
30+
height={360}
1731
src={pair.image}
1832
className="object-cover w-full aspect-none"
1933
alt={`Screenshot of ${pair.font} and ${pair.theme} on visual studio code`}
2034
/>
2135
</div>
2236
<CardContent className="p-4 md:p-6 grid gap-2">
2337
<CardTitle className="flex flex-col items-start justify-start gap-3 whitespace-nowrap">
24-
<p className="text-sm flex flex-row items-center gap-2 hover:text-zinc-500 transition-all">
25-
<TypeIcon
26-
size={16}
27-
className="border rounded bg-transparent p-0.5"
28-
strokeWidth={2}
29-
/>
30-
<a href={pair.font.url} target="_blank">
31-
{pair.font.name}
32-
</a>
33-
</p>
34-
<p className="text-sm flex flex-row items-center gap-2 hover:text-zinc-500 transition-all">
35-
<SwatchBookIcon
36-
size={16}
37-
strokeWidth={2}
38-
className="border rounded bg-transparent p-0.5"
39-
/>
40-
<a href={pair.theme.url} target="_blank">
41-
{pair.theme.name}
42-
</a>
43-
</p>
38+
{pair.theme.name.split(" ")[0]}
39+
{pair.font.name.split(" ")[0]}
4440
</CardTitle>
41+
<CardDescription>
42+
<div className="flex flex-row items-center justify-between">
43+
<div className="flex flex-row items-center gap-2">
44+
<PairItem
45+
variant="font"
46+
url={pair.font.url}
47+
name={pair.font.name}
48+
/>
49+
<PairItem
50+
variant="theme"
51+
url={pair.theme.url}
52+
name={pair.theme.name}
53+
/>
54+
</div>
55+
<Button
56+
size="icon"
57+
variant="outline"
58+
onClick={() =>
59+
copied ? null : copyToClipboard(pair.font.name, pair.theme.name)
60+
}
61+
>
62+
{copied ? (
63+
<ClipboardCheckIcon className="h-4 w-4" />
64+
) : (
65+
<ClipboardIcon className="h-4 w-4" />
66+
)}
67+
</Button>
68+
</div>
69+
</CardDescription>
4570
</CardContent>
4671
</Card>
4772
);

0 commit comments

Comments
 (0)