'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. */}
{description}
) : null}