|
1 | 1 | "use client";
|
2 | 2 |
|
3 |
| -/* eslint-disable @next/next/no-img-element */ |
4 |
| -import { cn } from "@/app/_lib/utils"; |
5 |
| -import Link from "next/link"; |
6 |
| - |
7 |
| -import { useHover } from "react-use"; |
8 |
| -import { Hoverable } from "./hover"; |
9 |
| - |
10 | 3 | import { ArrowRightIcon } from "../icons/ArrowRight";
|
| 4 | +import Image from "next/image"; |
| 5 | +import { cva, VariantProps } from "class-variance-authority"; |
| 6 | +import clsx from "clsx"; |
| 7 | +import { useRouter } from "next/navigation"; |
11 | 8 |
|
12 | 9 | interface PreviewCardProps {
|
| 10 | + subtitle: string; |
13 | 11 | title: string;
|
14 | 12 | image: string;
|
15 |
| - href: string; |
| 13 | + href?: string; |
| 14 | + onClick?: () => void; |
| 15 | + direction: "left" | "right"; |
16 | 16 | }
|
17 | 17 |
|
18 |
| -export function PreviewCard({ title, image, href }: PreviewCardProps) { |
19 |
| - const [previewCardContent, isHovered] = useHover( |
20 |
| - <div> |
21 |
| - <Hoverable> |
22 |
| - {(isInnerHovered) => ( |
23 |
| - <div className="flex w-full cursor-pointer flex-col gap-3 p-5 pr-10 transition-colors duration-300 hover:bg-zinc-900 md:p-5 md:pr-0 md:hover:bg-transparent"> |
24 |
| - <div className="flex items-center justify-between"> |
25 |
| - <div className="flex flex-1 flex-col gap-1"> |
26 |
| - <p className="text-lg font-[450] text-zinc-400">Next</p> |
27 |
| - <p className="text-2xl font-medium text-zinc-50">{title}</p> |
28 |
| - </div> |
29 |
| - {/** Right Arrow Button */} |
30 |
| - <Link href={href}> |
31 |
| - <ArrowRightIcon |
32 |
| - width={48} |
33 |
| - height={48} |
34 |
| - className={cn("text-zinc-600")} |
35 |
| - /> |
36 |
| - </Link> |
37 |
| - </div> |
38 |
| - <div className="hidden overflow-hidden rounded-[8px] md:block"> |
39 |
| - <img |
40 |
| - src={image} |
41 |
| - alt={`${title}_thumbnail`} |
42 |
| - className={cn( |
43 |
| - "aspect-video w-full bg-[#27272A] object-cover transition-all duration-300", |
44 |
| - { |
45 |
| - "scale-110": isInnerHovered, |
46 |
| - }, |
47 |
| - )} |
48 |
| - /> |
49 |
| - </div> |
50 |
| - </div> |
51 |
| - )} |
52 |
| - </Hoverable> |
53 |
| - </div>, |
54 |
| - ); |
| 18 | +const cardVariants = cva( |
| 19 | + "group relative z-10 w-full md:w-[420px] md:h-[300px] overflow-hidden bg-[#101010]/80 transition-all duration-300", |
| 20 | + { |
| 21 | + variants: { |
| 22 | + direction: { |
| 23 | + left: "md:rounded-r-xl md:pl-20", |
| 24 | + right: "md:rounded-s-xl md:pr-20", |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | +); |
| 29 | + |
| 30 | +export function PreviewCard({ subtitle, title, image, href, direction, onClick }: PreviewCardProps & VariantProps<typeof cardVariants>) { |
| 31 | + const isLeft = direction === "left"; |
| 32 | + const router = useRouter(); |
| 33 | + |
| 34 | + const handleClick = () => { |
| 35 | + if(href) router.push(href) |
| 36 | + if(onClick) onClick() |
| 37 | + } |
55 | 38 |
|
56 | 39 | return (
|
57 |
| - <div |
58 |
| - className={cn( |
59 |
| - "relative z-10 w-full bg-transparent md:w-[420px] md:pr-20", |
60 |
| - )} |
61 |
| - > |
62 |
| - {previewCardContent} |
63 |
| - {/* Gradient */} |
64 |
| - <div |
65 |
| - className={cn( |
66 |
| - "absolute top-0 right-0 -z-10 hidden h-full w-full bg-[linear-gradient(270deg,_#27272A_0%,_transparent_32%)] opacity-0 transition-opacity duration-300 md:block", |
67 |
| - { |
68 |
| - "opacity-100": isHovered, |
69 |
| - }, |
70 |
| - )} |
71 |
| - /> |
72 |
| - </div> |
| 40 | + <div className={cardVariants({ direction })} onClick={handleClick}> |
| 41 | + <div className="flex w-full cursor-pointer flex-col gap-3 p-5 pr-10 transition-colors duration-300 md:hover:bg-transparent"> |
| 42 | + <div className={clsx("w-full flex items-center justify-between", isLeft && "flex-row-reverse")}> |
| 43 | + <div className="flex flex-col gap-1"> |
| 44 | + <p className="text-lg font-[450] text-zinc-400">{subtitle}</p> |
| 45 | + <p className="text-2xl font-medium text-zinc-50">{title}</p> |
| 46 | + </div> |
| 47 | + <ArrowRightIcon |
| 48 | + width={48} |
| 49 | + height={48} |
| 50 | + className={clsx("text-zinc-600 group-hover:text-zinc-100 transition-all duration-300", isLeft && "rotate-180")} |
| 51 | + /> |
| 52 | + </div> |
| 53 | + <div className={clsx("relative hidden h-[380px] w-[296px] overflow-hidden rounded-[17px] transition-all duration-300 md:block border border-transparent group-hover:border-[#86FFD9] group-hover:drop-shadow-[0_100px_100px_#86FFD966]")}> |
| 54 | + <Image src={image} alt={`${title}_thumbnail`} objectFit="cover" fill /> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + </div> |
73 | 58 | );
|
74 | 59 | }
|
0 commit comments