AI Resource Pro / website · airesourcepro.com / src / components / tutorial-card.tsx
| 1 | import Image from "next/image"; |
| 2 | import Link from "next/link"; |
| 3 | import { ArrowRight, Play, PlayCircle } from "lucide-react"; |
| 4 | import { getTrack } from "@/lib/tracks"; |
| 5 | import type { TutorialMeta } from "@/lib/tutorial-types"; |
| 6 | import { cn } from "@/lib/utils"; |
| 7 | |
| 8 | export function TrackTag({ track, className }: { track: string; className?: string }) { |
| 9 | const t = getTrack(track); |
| 10 | if (!t) return null; |
| 11 | return ( |
| 12 | <span className={cn("font-mono text-[11.5px] font-medium uppercase tracking-[0.08em]", className)} style={{ color: t.color }}> |
| 13 | {t.name} |
| 14 | </span> |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | export function TutorialMetaLine({ tutorial }: { tutorial: TutorialMeta }) { |
| 19 | return ( |
| 20 | <div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 font-mono text-[11.5px] uppercase tracking-[0.08em] text-[var(--ash)]"> |
| 21 | <TrackTag track={tutorial.track} /> |
| 22 | <span aria-hidden>·</span> |
| 23 | <span>{tutorial.level}</span> |
| 24 | <span aria-hidden>·</span> |
| 25 | <span> |
| 26 | {tutorial.minutes} min {tutorial.video ? "watch" : "read"} |
| 27 | </span> |
| 28 | {tutorial.draft && <DraftBadge />} |
| 29 | </div> |
| 30 | ); |
| 31 | } |
| 32 | |
| 33 | export function DraftBadge() { |
| 34 | return <span className="rounded-full border font-mono text-[11px] uppercase tracking-[0.08em] border-[color-mix(in_srgb,var(--link)_40%,transparent)] px-2 py-px text-[var(--link)]">Draft</span>; |
| 35 | } |
| 36 | |
| 37 | const chip = |
| 38 | "rounded-full border border-foreground/10 bg-background/70 px-2.5 py-1 font-mono text-[10.5px] font-medium uppercase tracking-[0.08em] text-foreground backdrop-blur"; |
| 39 | |
| 40 | const cardFrame = |
| 41 | "group overflow-hidden rounded-2xl border border-border bg-card transition duration-500 [transition-timing-function:cubic-bezier(0.2,0.7,0,1)] hover:-translate-y-1 hover:border-[var(--tc)] hover:shadow-[0_24px_60px_-20px_var(--card-glow)]"; |
| 42 | |
| 43 | // One tutorial as a card: cover image, track, title, description and a clear call to action |
| 44 | export function TutorialCard({ tutorial, className }: { tutorial: TutorialMeta; className?: string }) { |
| 45 | const track = getTrack(tutorial.track); |
| 46 | const video = !!tutorial.video; |
| 47 | return ( |
| 48 | <Link |
| 49 | href={`/${tutorial.track}/${tutorial.slug}`} |
| 50 | className={cn(cardFrame, "flex flex-col", className)} |
| 51 | style={{ "--tc": track?.color } as React.CSSProperties} |
| 52 | > |
| 53 | <div className="relative aspect-[5/3] overflow-hidden border-b border-border"> |
| 54 | <Image |
| 55 | src={tutorial.cover} |
| 56 | alt="" |
| 57 | fill |
| 58 | sizes="(min-width: 1280px) 440px, (min-width: 640px) 50vw, 100vw" |
| 59 | className="object-cover transition-transform duration-700 [transition-timing-function:cubic-bezier(0.2,0.7,0,1)] group-hover:scale-[1.05]" |
| 60 | /> |
| 61 | <div className="absolute left-3 top-3 z-[1] flex flex-wrap gap-1.5"> |
| 62 | <span className={chip}>{tutorial.level}</span> |
| 63 | {video && ( |
| 64 | <span className={cn(chip, "inline-flex items-center gap-1")}> |
| 65 | <PlayCircle className="h-3 w-3" /> Video |
| 66 | </span> |
| 67 | )} |
| 68 | {tutorial.draft && <span className={cn(chip, "text-[var(--link)]")}>Draft</span>} |
| 69 | </div> |
| 70 | </div> |
| 71 | <div className="flex flex-1 flex-col gap-3 p-6"> |
| 72 | <TrackTag track={tutorial.track} /> |
| 73 | <h3 className="font-display text-[clamp(21px,1.7vw,25px)] font-normal leading-[1.15] tracking-[-0.03em]">{tutorial.title}</h3> |
| 74 | <p className="line-clamp-3 text-[15px] leading-relaxed text-[var(--mist)]">{tutorial.description}</p> |
| 75 | <div className="mt-auto flex items-center justify-between pt-3 font-mono text-[11.5px] uppercase tracking-[0.08em]"> |
| 76 | <span className="text-[var(--ash)]"> |
| 77 | {tutorial.minutes} min {video ? "watch" : "read"} |
| 78 | </span> |
| 79 | <span className="inline-flex items-center gap-1.5 font-medium text-[var(--link)]"> |
| 80 | {video ? "Watch" : "Read"} |
| 81 | <ArrowRight className="h-3.5 w-3.5 transition-transform duration-500 group-hover:translate-x-1.5" /> |
| 82 | </span> |
| 83 | </div> |
| 84 | </div> |
| 85 | </Link> |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | // Cards in a responsive grid |
| 90 | export function TutorialGrid({ tutorials, className }: { tutorials: TutorialMeta[]; className?: string }) { |
| 91 | return ( |
| 92 | <div className={cn("grid gap-6 sm:grid-cols-2 xl:grid-cols-3", className)}> |
| 93 | {tutorials.map((t) => ( |
| 94 | <TutorialCard key={`${t.track}/${t.slug}`} tutorial={t} /> |
| 95 | ))} |
| 96 | </div> |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | // A tutorial with a video: its poster beside the title (or above it when compact) and a Watch link |
| 101 | function FeaturedTutorial({ tutorial, compact }: { tutorial: TutorialMeta; compact?: boolean }) { |
| 102 | const track = getTrack(tutorial.track); |
| 103 | return ( |
| 104 | <Link |
| 105 | href={`/${tutorial.track}/${tutorial.slug}`} |
| 106 | className={cn(cardFrame, compact ? "flex flex-col" : "grid lg:grid-cols-[minmax(0,1.3fr)_minmax(0,1fr)]")} |
| 107 | style={{ "--tc": track?.color } as React.CSSProperties} |
| 108 | > |
| 109 | <div className={cn("relative aspect-video overflow-hidden border-b border-border", !compact && "lg:border-b-0 lg:border-r")}> |
| 110 | <Image |
| 111 | src={`https://airesourcepro.com/media/video/${tutorial.video}/poster.jpg`} |
| 112 | alt="" |
| 113 | fill |
| 114 | sizes={compact ? "(min-width: 640px) 45vw, 100vw" : "(min-width: 1024px) 60vw, 100vw"} |
| 115 | className="object-cover transition-transform duration-700 [transition-timing-function:cubic-bezier(0.2,0.7,0,1)] group-hover:scale-[1.03]" |
| 116 | /> |
| 117 | <span className={cn("absolute bottom-4 right-4 z-[1] flex items-center justify-center rounded-full bg-primary text-primary-foreground", compact ? "h-10 w-10" : "h-12 w-12")}> |
| 118 | <Play className={cn("ml-0.5 fill-current", compact ? "h-4 w-4" : "h-5 w-5")} /> |
| 119 | </span> |
| 120 | </div> |
| 121 | <div className={cn("flex flex-1 flex-col", compact ? "gap-3 p-6" : "gap-4 p-6 sm:p-8 lg:p-10")}> |
| 122 | <TrackTag track={tutorial.track} /> |
| 123 | <h3 |
| 124 | className={cn( |
| 125 | "font-display font-normal tracking-[-0.03em]", |
| 126 | compact ? "text-[clamp(21px,1.7vw,25px)] leading-[1.15]" : "text-[clamp(26px,2.6vw,38px)] leading-[1.1]" |
| 127 | )} |
| 128 | > |
| 129 | {tutorial.title} |
| 130 | </h3> |
| 131 | <p className={cn(compact ? "line-clamp-3" : "line-clamp-4", "text-[15px] leading-relaxed text-[var(--mist)]")}>{tutorial.description}</p> |
| 132 | {tutorial.draft && <DraftBadge />} |
| 133 | <div className="mt-auto flex items-center justify-between gap-4 pt-3 font-mono text-[11.5px] uppercase tracking-[0.08em]"> |
| 134 | <span className="text-[var(--ash)]"> |
| 135 | {tutorial.level} · {tutorial.minutes} min watch |
| 136 | </span> |
| 137 | <span className="inline-flex items-center gap-1.5 font-medium text-[var(--link)]"> |
| 138 | Watch |
| 139 | <ArrowRight className="h-3.5 w-3.5 transition-transform duration-500 group-hover:translate-x-1.5" /> |
| 140 | </span> |
| 141 | </div> |
| 142 | </div> |
| 143 | </Link> |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | // Tutorials with videos get the room; pass only those. Compact puts two smaller cards per row on anything wider than a phone |
| 148 | export function FeaturedTutorials({ |
| 149 | tutorials, |
| 150 | compact, |
| 151 | className, |
| 152 | }: { |
| 153 | tutorials: TutorialMeta[]; |
| 154 | compact?: boolean; |
| 155 | className?: string; |
| 156 | }) { |
| 157 | if (tutorials.length === 0) return null; |
| 158 | return ( |
| 159 | <section className={className}> |
| 160 | <h2 className="label mb-6"> |
| 161 | <i /> |
| 162 | Featured videos |
| 163 | </h2> |
| 164 | <div className={cn("grid gap-6", compact && "sm:grid-cols-2")}> |
| 165 | {tutorials.map((t) => ( |
| 166 | <FeaturedTutorial key={`${t.track}/${t.slug}`} tutorial={t} compact={compact} /> |
| 167 | ))} |
| 168 | </div> |
| 169 | </section> |
| 170 | ); |
| 171 | } |
| 172 | |
| 173 | // Written tutorials as plain text rows, with no cover image |
| 174 | export function TutorialRows({ tutorials }: { tutorials: TutorialMeta[] }) { |
| 175 | return ( |
| 176 | <ul className="divide-y divide-border border-y border-border"> |
| 177 | {tutorials.map((t) => ( |
| 178 | <li key={`${t.track}/${t.slug}`}> |
| 179 | <Link href={`/${t.track}/${t.slug}`} className="group flex items-center justify-between gap-8 py-6"> |
| 180 | <div className="min-w-0"> |
| 181 | <TutorialMetaLine tutorial={t} /> |
| 182 | <h3 className="mt-3 font-display text-[clamp(21px,1.7vw,25px)] font-normal leading-[1.15] tracking-[-0.03em] transition-colors group-hover:text-[var(--link)]"> |
| 183 | {t.title} |
| 184 | </h3> |
| 185 | <p className="mt-2 max-w-3xl text-[15px] leading-relaxed text-[var(--mist)]">{t.description}</p> |
| 186 | </div> |
| 187 | <ArrowRight className="h-4 w-4 shrink-0 text-[var(--link)] transition-transform duration-500 group-hover:translate-x-1.5" /> |
| 188 | </Link> |
| 189 | </li> |
| 190 | ))} |
| 191 | </ul> |
| 192 | ); |
| 193 | } |