|
1 | 1 | 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"; |
5 | 9 |
|
6 | 10 | interface PairCardProps {
|
7 | 11 | pair: Pair;
|
8 | 12 | }
|
9 | 13 |
|
10 | 14 | 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 | + |
11 | 25 | return (
|
12 | 26 | <Card className="max-w-2xl">
|
13 | 27 | <div className="aspect-[16/9] overflow-hidden rounded-lg">
|
14 | 28 | <Image
|
15 |
| - width={400} |
16 |
| - height={300} |
| 29 | + width={640} |
| 30 | + height={360} |
17 | 31 | src={pair.image}
|
18 | 32 | className="object-cover w-full aspect-none"
|
19 | 33 | alt={`Screenshot of ${pair.font} and ${pair.theme} on visual studio code`}
|
20 | 34 | />
|
21 | 35 | </div>
|
22 | 36 | <CardContent className="p-4 md:p-6 grid gap-2">
|
23 | 37 | <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]} |
44 | 40 | </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> |
45 | 70 | </CardContent>
|
46 | 71 | </Card>
|
47 | 72 | );
|
|
0 commit comments