Skip to content

Commit 6180953

Browse files
committed
next image for country cards
1 parent a59f17d commit 6180953

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

app/components/CountryCard.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import Link from "next/link";
22
import { Country } from "../_types/types";
3+
import { AspectRatio } from "@/components/ui/aspect-ratio";
4+
import Image from "next/image";
35

46
const CountryCard = ({ country }: { country: Country }) => {
57
return (
68
<Link href={`/country/${country.cca3}`}>
79
<article className="p-5 rounded-lg shadow-sm bg-white dark:bg-gray-700 space-y-7 border border-gray-300/50 dark:border-gray-500/50 md:hover:scale-[104%] transition-transform">
8-
<div className="aspect-video">
9-
<img
10-
className="object-cover w-full h-full rounded-lg shadow-sm"
10+
<AspectRatio ratio={16 / 9}>
11+
<Image
12+
width={300}
13+
height={200}
1114
src={country.flags.png}
1215
alt={country.name.common}
16+
className="object-cover w-full h-full rounded-lg shadow-sm"
1317
/>
14-
</div>
18+
</AspectRatio>
1519

1620
<div className="space-y-2">
1721
<h2 className="font-semibold text-lg line-clamp-1">

components/ui/aspect-ratio.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use client"
2+
3+
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio"
4+
5+
const AspectRatio = AspectRatioPrimitive.Root
6+
7+
export { AspectRatio }

next.config.mjs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/** @type {import('next').NextConfig} */
2-
const nextConfig = {};
3-
4-
export default nextConfig;
2+
const nextConfig = {
3+
images: {
4+
remotePatterns: [
5+
{
6+
protocol: "https",
7+
hostname: "**",
8+
},
9+
],
10+
},
11+
}
12+
13+
export default nextConfig

package-lock.json

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@clerk/nextjs": "^5.3.0",
1313
"@heroicons/react": "^2.1.5",
1414
"@prisma/client": "^5.18.0",
15+
"@radix-ui/react-aspect-ratio": "^1.1.0",
1516
"@radix-ui/react-dropdown-menu": "^2.1.1",
1617
"@radix-ui/react-select": "^2.1.1",
1718
"@radix-ui/react-slot": "^1.1.0",

0 commit comments

Comments
 (0)