'use client'; import * as React from 'react'; import { Heart, MessageCircle, Clock, ExternalLink, Eye, Sparkles } from 'lucide-react'; function formatViews(count: number): string { if (count >= 1000) return `${(count / 1000).toFixed(1)}k`; return String(count); } import { InterlaceWeave } from '../effects/interlace-weave.js'; import { cn } from '../lib/cn.js'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '../primitives/card.js'; import { Badge } from '../primitives/badge.js'; export interface ArticleCardAuthor { name: string; imageUrl?: string; } export interface ArticleCardMeta { /** Reaction / like count. */ reactions?: number; /** Comment count. */ comments?: number; /** Reading time in minutes. */ readingTimeMinutes?: number; /** * Page-view count. Rendered abbreviated (e.g., `1.2k`) when ≥ 1000. * A zero renders NOTHING: sources that cannot report views (dev.to's * public API) return 0, and a "👁 0" chip on every card reads as product * failure, not as data. Absence is the honest presentation of absence. */ views?: number; } /** * Visual layout of the card. * * - `stack` (default): image on top, content (author / title / description / * tags / meta) stacked beneath on the card surface. Used for grids. * * - `overlay`: image fills the entire card; content is overlaid on a dark * gradient scrim at the bottom for WCAG-compliant contrast. A `FEATURED` * chip is shown top-left. Used for hero / "featured article" slots above * a grid. Card has a fixed responsive height so it reads as a hero. */ export type ArticleCardVariant = 'stack' | 'overlay'; export interface ArticleCardProps { /** Card title (article headline). */ title: string; /** Optional short description / excerpt. */ description?: string; /** Destination URL. The whole card becomes a link to it. */ href: string; /** Cover image URL. If omitted, a gradient with the title is shown. */ imageUrl?: string; /** Tags / topics — first 3 rendered as filled badges, the rest as a "+N" overflow chip. */ tags?: string[]; /** Author block. */ author?: ArticleCardAuthor; /** Publication date (any value `Date` constructor accepts). Rendered short-form: `Mar 5, 2026`. */ publishedAt?: string | number | Date; /** Reactions / comments / reading-time chips on the footer. */ meta?: ArticleCardMeta; /** Small uppercase label shown over the cover (e.g., source attribution like "Dev.to"). */ sourceLabel?: string; /** Open in a new tab. Default: `true`. */ external?: boolean; /** Visual layout. See `ArticleCardVariant`. Default: `'stack'`. */ variant?: ArticleCardVariant; /** * Hint the cover image is the LCP element on this route. Eager-loads it * with `fetchPriority="high"`. Set on the single featured/overlay card * above the fold; leave default (`false`) on every grid tile. */ priority?: boolean; /** Class on the outer anchor wrapper. */ className?: string; } function formatDate(value: ArticleCardProps['publishedAt']): string { if (value === undefined) return ''; return new Date(value).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', }); } /** * Generic article-card block: cover image + author + tags + title + description * + meta chips (reactions / comments / reading time). Useful for "from the * blog" tiles, external content lists, devto/medium aggregations, etc. * * Two layouts, same data shape, same hover, same focus ring, same chip * styling: `variant='stack'` (default, image-on-top grid card) and * `variant='overlay'` (full-image hero with text on a dark scrim). Both * are covered by Storybook stories with interaction + axe assertions. */ export function ArticleCard({ title, description, href, imageUrl, tags, author, publishedAt, meta, sourceLabel, external = true, variant = 'stack', priority = false, className, }: ArticleCardProps) { const visibleTags = tags?.slice(0, 3) ?? []; const overflowTags = tags && tags.length > 3 ? tags.length - 3 : 0; const isOverlay = variant === 'overlay'; return ( {/* The brand gesture: two strands draw and cross on hover/focus. Decorative only — the ring above stays the a11y affordance, the weave doubles it visually. */} {/* `py-0 gap-0` overrides Card's default `py-6 gap-6`. */} {isOverlay ? ( ) : ( )} ); } interface BodyProps { title: string; description?: string; imageUrl?: string; visibleTags: string[]; overflowTags: number; author?: ArticleCardAuthor; publishedAt?: string | number | Date; meta?: ArticleCardMeta; sourceLabel?: string; /** Forwarded from `ArticleCardProps.priority`. */ priority?: boolean; } /** Top-right chip used to attribute the source of the article (e.g., "Dev.to"). */ function SourceChip({ label }: { label: string }) { return (
{label}
); } /** Top-left chip shown only on the `overlay` variant. */ function FeaturedChip() { return (
Featured
); } function CoverImage({ imageUrl, title, className, fallbackTextClassName, priority = false, }: { imageUrl?: string; title: string; className?: string; fallbackTextClassName?: string; /** * When true, eager-load the cover image and hint the browser to fetch * it with high priority. Use on the LCP element of a route — typically * the featured/overlay slot on the articles index. Default: false * (lazy-loaded, fine for grid tiles below the fold). */ priority?: boolean; }) { if (imageUrl) { return ( ); } return (
{title}
); } function MetaChips({ meta, tone, }: { meta: ArticleCardMeta; tone: 'muted' | 'overlay'; }) { const baseChip = 'flex items-center gap-1.5 text-xs tabular-nums'; const colorClass = tone === 'overlay' ? 'text-white/90' : 'text-muted-foreground'; return ( <> {meta.reactions !== undefined ? ( {meta.reactions} ) : null} {meta.comments !== undefined ? ( {meta.comments} ) : null} {meta.readingTimeMinutes !== undefined ? ( {meta.readingTimeMinutes} min ) : null} {meta.views ? ( {formatViews(meta.views)} ) : null} ); } function StackBody({ title, description, imageUrl, visibleTags, overflowTags, author, publishedAt, meta, sourceLabel, priority = false, }: BodyProps) { return ( <> {/* Cover (or gradient title fallback) — edge-to-edge top of the card. */}
{sourceLabel ? : null}
{(author || publishedAt) && (
{author ? (
{author.imageUrl ? ( {author.name} ) : null} {author.name}
) : ( )} {publishedAt ? ( {formatDate(publishedAt)} ) : null}
)} {/* Content order (top → bottom): title, description, tags. Tags after description per top-1% blog-card convention — the reader's eye lands on the headline first, not on metadata. */} {title} {description ? ( {description} ) : null} {visibleTags.length > 0 ? (
{visibleTags.map((tag) => ( #{tag} ))} {overflowTags > 0 ? ( +{overflowTags} ) : null}
) : null}
{meta ? ( ) : null} ); } function OverlayBody({ title, description, imageUrl, visibleTags, overflowTags, author, publishedAt, meta, sourceLabel, priority = false, }: BodyProps) { return ( <> {/* Cover fills the entire card. Image lives in an absolute layer so a dark gradient scrim can sit between it and the text — that scrim is what guarantees WCAG-AA contrast over arbitrary covers. */}
{/* Scrim — opacity stack tuned so titles + meta on top read clean over any cover, including light or busy images. */}
{sourceLabel ? : null}
{visibleTags.length > 0 ? (
{visibleTags.map((tag) => ( #{tag} ))} {overflowTags > 0 ? ( +{overflowTags} ) : null}
) : null} {/* h2 (not h3) so the heading hierarchy from a page-level h1 → article card title increases by exactly one level. axe's `heading-order` rule flags h1→h3 jumps on the /articles route and in isolated Storybook scans. The visual size (text-2xl/3xl) is preserved via class names, decoupled from semantic level. */}

{title}

{description ? (

{description}

) : null}
{author ? (
{author.imageUrl ? ( {author.name} ) : null} {author.name}
) : null} {publishedAt ? ( <> • {formatDate(publishedAt)} ) : null} {meta ? ( <> •
) : null}
); }