{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tweet-card",
  "title": "Tweet Card",
  "description": "X-style post cards from data with highlighted mentions, media grid, compact stats, a like pop and a scrolling testimonial wall.",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "https://trytweenly.vercel.app/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/new-york/tweet-card/tweet-card.tsx",
      "content": "\"use client\"\n\nimport { useState } from \"react\"\nimport { AnimatePresence, motion } from \"motion/react\"\nimport { ChartNoAxesColumn, Heart, MessageCircle, Repeat2 } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useReducedMotion } from \"@/registry/new-york/hooks/use-reduced-motion\"\n\nexport type TweetCardVariant = \"default\" | \"compact\" | \"minimal\"\n\nexport interface TweetAuthor {\n  /** Display name. */\n  name: string\n  /** Handle without the @. */\n  handle: string\n  /** Avatar image URL. Falls back to initials on a color derived from the handle. */\n  avatar?: string\n  /** Show the verified badge. Default: false */\n  verified?: boolean\n}\n\nexport interface TweetStats {\n  /** Default: 0 */\n  replies?: number\n  /** Default: 0 */\n  reposts?: number\n  /** Likes, excluding the viewer's own like. Default: 0 */\n  likes?: number\n  /** Default: 0 */\n  views?: number\n}\n\nexport interface TweetCardProps {\n  /** Who posted it. */\n  author: TweetAuthor\n  /** Post text. @mentions, #hashtags and URLs are highlighted automatically. */\n  content: string\n  /** Date label shown as-is, e.g. \"Mar 4\" or \"2h\". */\n  date: string\n  /** Up to 4 image URLs. Images that fail to load are hidden. */\n  media?: string[]\n  /** Engagement counts, shown compactly (1.2K). */\n  stats?: TweetStats\n  /** Makes the whole card a link, e.g. to the original post. */\n  href?: string\n  /** Layout density. Default: \"default\" */\n  variant?: TweetCardVariant\n  /** Start with the like button toggled on. Default: false */\n  defaultLiked?: boolean\n  /** Called when the like button toggles. */\n  onLike?: (liked: boolean) => void\n  /** Show the X logo in the corner. Default: true */\n  showLogo?: boolean\n  /** Color for links, mentions and hashtags (any CSS color). Default: \"#ff4d12\" */\n  accent?: string\n  className?: string\n}\n\nconst compact = new Intl.NumberFormat(\"en\", { notation: \"compact\", maximumFractionDigits: 1 })\nconst formatCount = (n: number) => compact.format(n)\n\nconst TOKEN = /(https?:\\/\\/[^\\s]+|@\\w+|#\\w+)/g\nconst pop = { type: \"spring\", stiffness: 500, damping: 30 } as const\n\nfunction hashHue(s: string) {\n  let h = 0\n  for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) >>> 0\n  return h % 360\n}\n\nfunction initials(name: string) {\n  const parts = name.trim().split(/\\s+/)\n  return ((parts[0]?.[0] ?? \"\") + (parts.length > 1 ? parts[parts.length - 1][0] : \"\")).toUpperCase()\n}\n\nfunction XLogo({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className={className} fill=\"currentColor\">\n      <path d=\"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z\" />\n    </svg>\n  )\n}\n\nfunction Verified({ className }: { className?: string }) {\n  return (\n    <svg viewBox=\"0 0 22 22\" aria-label=\"Verified account\" role=\"img\" className={className}>\n      <path\n        fill=\"#1d9bf0\"\n        d=\"M20.396 11c-.018-.646-.215-1.275-.57-1.816-.354-.54-.852-.972-1.438-1.246.223-.607.27-1.264.14-1.897-.131-.634-.437-1.218-.882-1.687-.47-.445-1.053-.75-1.687-.882-.633-.13-1.29-.083-1.897.14-.273-.587-.704-1.086-1.245-1.44S11.647 1.62 11 1.604c-.646.017-1.273.213-1.813.568s-.969.854-1.24 1.44c-.608-.223-1.267-.272-1.902-.14-.635.13-1.22.436-1.69.882-.445.47-.749 1.055-.878 1.688-.13.633-.08 1.29.144 1.896-.587.274-1.087.705-1.443 1.245-.356.54-.555 1.17-.574 1.817.02.647.218 1.276.574 1.817.356.54.856.972 1.443 1.245-.224.606-.274 1.263-.144 1.896.13.634.433 1.218.877 1.688.47.443 1.054.747 1.687.878.633.132 1.29.084 1.897-.136.274.586.705 1.084 1.246 1.439.54.354 1.17.551 1.816.569.647-.016 1.276-.213 1.817-.567s.972-.854 1.245-1.44c.604.239 1.266.296 1.903.164.636-.132 1.22-.447 1.68-.907.46-.46.776-1.044.908-1.681s.075-1.299-.165-1.903c.586-.274 1.084-.705 1.439-1.246.354-.54.551-1.17.569-1.816z\"\n      />\n      <path fill=\"#fff\" d=\"M9.662 14.85l-3.429-3.428 1.293-1.302 2.072 2.072 4.4-4.794 1.347 1.246z\" />\n    </svg>\n  )\n}\n\nfunction Avatar({ author, size }: { author: TweetAuthor; size: number }) {\n  const [failed, setFailed] = useState(false)\n  const hue = hashHue(author.handle.toLowerCase())\n\n  if (author.avatar && !failed) {\n    return (\n      <img\n        src={author.avatar}\n        alt=\"\"\n        width={size}\n        height={size}\n        onError={() => setFailed(true)}\n        ref={(img) => {\n          if (img && img.complete && img.naturalWidth === 0) setFailed(true)\n        }}\n        className=\"shrink-0 rounded-full object-cover\"\n        style={{ width: size, height: size }}\n      />\n    )\n  }\n\n  return (\n    <span\n      aria-hidden=\"true\"\n      className=\"flex shrink-0 select-none items-center justify-center rounded-full font-semibold text-white\"\n      style={{\n        width: size,\n        height: size,\n        fontSize: size * 0.38,\n        backgroundColor: `hsl(${hue} 62% 46%)`,\n      }}\n    >\n      {initials(author.name)}\n    </span>\n  )\n}\n\nfunction RichText({ text, accent, interactive }: { text: string; accent: string; interactive: boolean }) {\n  return text.split(TOKEN).map((part, i) => {\n    if (i % 2 === 0) return part\n    const style = { color: accent }\n    if (!interactive) return <span key={i} style={style}>{part}</span>\n    const href = part.startsWith(\"@\")\n      ? `https://x.com/${part.slice(1)}`\n      : part.startsWith(\"#\")\n        ? `https://x.com/hashtag/${part.slice(1)}`\n        : part\n    const label = part.startsWith(\"http\") ? part.replace(/^https?:\\/\\/(www\\.)?/, \"\") : part\n    return (\n      <a key={i} href={href} target=\"_blank\" rel=\"noopener noreferrer\" style={style} className=\"relative z-10 hover:underline\">\n        {label}\n      </a>\n    )\n  })\n}\n\nfunction MediaGrid({ media }: { media: string[] }) {\n  const [failed, setFailed] = useState<string[]>([])\n  const visible = media.filter((src) => !failed.includes(src)).slice(0, 4)\n  if (visible.length === 0) return null\n\n  const fail = (src: string) => setFailed((f) => (f.includes(src) ? f : [...f, src]))\n  const n = visible.length\n\n  return (\n    <div\n      className={cn(\n        \"mt-3 grid gap-0.5 overflow-hidden rounded-xl border border-border\",\n        n === 1 ? \"grid-cols-1\" : \"grid-cols-2\",\n        n === 1 ? \"aspect-[16/10]\" : n === 2 ? \"aspect-[2/1]\" : \"aspect-[16/10] grid-rows-2\"\n      )}\n    >\n      {visible.map((src, i) => (\n        <img\n          key={src}\n          src={src}\n          alt=\"\"\n          loading=\"lazy\"\n          onError={() => fail(src)}\n          ref={(img) => {\n            if (img && img.complete && img.naturalWidth === 0) fail(src)\n          }}\n          className={cn(\"size-full bg-foreground/[0.05] object-cover\", n === 3 && i === 0 && \"row-span-2\")}\n        />\n      ))}\n    </div>\n  )\n}\n\nfunction LikeAction({\n  likes,\n  defaultLiked,\n  onLike,\n  reduced,\n  showCount,\n}: {\n  likes: number\n  defaultLiked: boolean\n  onLike?: (liked: boolean) => void\n  reduced: boolean\n  showCount: boolean\n}) {\n  const [liked, setLiked] = useState(defaultLiked)\n  const [burst, setBurst] = useState(0)\n  const total = likes + (liked ? 1 : 0)\n\n  return (\n    <button\n      type=\"button\"\n      aria-pressed={liked}\n      aria-label={liked ? \"Unlike\" : \"Like\"}\n      onClick={() => {\n        const next = !liked\n        setLiked(next)\n        if (next) setBurst((b) => b + 1)\n        onLike?.(next)\n      }}\n      className={cn(\n        \"group/like relative z-10 -m-1.5 flex items-center gap-1.5 rounded-full p-1.5 outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[#f91880]/60\",\n        liked ? \"text-[#f91880]\" : \"hover:text-[#f91880]\"\n      )}\n    >\n      <span className=\"relative flex size-[18px] items-center justify-center\">\n        <AnimatePresence>\n          {burst > 0 && liked && !reduced && (\n            <motion.span\n              key={burst}\n              aria-hidden=\"true\"\n              className=\"absolute inset-0 rounded-full border-2 border-[#f91880]\"\n              initial={{ scale: 0.3, opacity: 0.9 }}\n              animate={{ scale: 2, opacity: 0 }}\n              exit={{ opacity: 0 }}\n              transition={{ duration: 0.5, ease: [0.22, 1, 0.36, 1] }}\n            />\n          )}\n        </AnimatePresence>\n        <motion.span\n          key={String(liked)}\n          className=\"flex\"\n          initial={reduced ? false : { scale: liked ? 0.3 : 0.8 }}\n          animate={{ scale: 1 }}\n          transition={pop}\n        >\n          <Heart className=\"size-[18px]\" fill={liked ? \"currentColor\" : \"none\"} strokeWidth={liked ? 0 : 1.75} />\n        </motion.span>\n      </span>\n      {showCount && <span className=\"tabular-nums\">{formatCount(total)}</span>}\n    </button>\n  )\n}\n\nexport function TweetCard({\n  author,\n  content,\n  date,\n  media,\n  stats,\n  href,\n  variant = \"default\",\n  defaultLiked = false,\n  onLike,\n  showLogo = true,\n  accent = \"#ff4d12\",\n  className,\n}: TweetCardProps) {\n  const reduced = useReducedMotion()\n  const isCompact = variant === \"compact\"\n  const isMinimal = variant === \"minimal\"\n  const avatarSize = isCompact ? 36 : isMinimal ? 32 : 42\n\n  return (\n    <article\n      className={cn(\n        \"group/tweet relative text-left text-foreground\",\n        isMinimal\n          ? \"p-1\"\n          : cn(\n              \"rounded-2xl border border-border bg-card transition-colors\",\n              isCompact ? \"p-3.5\" : \"p-5\",\n              href && \"hover:bg-foreground/[0.03]\"\n            ),\n        className\n      )}\n    >\n      {href && (\n        <a href={href} target=\"_blank\" rel=\"noopener noreferrer\" aria-label={`Post by ${author.name}`} className=\"absolute inset-0 rounded-[inherit] outline-none focus-visible:ring-2 focus-visible:ring-[#ff4d12]\" />\n      )}\n\n      <header className=\"flex items-start gap-3\">\n        <Avatar author={author} size={avatarSize} />\n        <div className={cn(\"min-w-0 flex-1\", showLogo && \"pr-6\")}>\n          <div className=\"flex items-center gap-1\">\n            <span className={cn(\"truncate font-semibold\", isCompact || isMinimal ? \"text-sm\" : \"text-[15px]\")}>{author.name}</span>\n            {author.verified && <Verified className=\"size-4 shrink-0\" />}\n          </div>\n          <div className=\"flex items-center gap-1 truncate text-[13px] text-muted-foreground\">\n            <span className=\"truncate\">@{author.handle}</span>\n            {!isCompact && (\n              <>\n                <span aria-hidden=\"true\">·</span>\n                <time className=\"shrink-0\">{date}</time>\n              </>\n            )}\n          </div>\n        </div>\n        {showLogo && <XLogo className=\"absolute right-4 top-4 size-4 text-foreground/80\" />}\n      </header>\n\n      <p\n        className={cn(\n          \"whitespace-pre-wrap break-words\",\n          isCompact ? \"mt-2 text-sm leading-snug\" : isMinimal ? \"mt-2.5 text-sm leading-relaxed text-foreground/90\" : \"mt-3 text-[15px] leading-relaxed\"\n        )}\n      >\n        <RichText text={content} accent={accent} interactive={!href} />\n      </p>\n\n      {!isCompact && !isMinimal && media && media.length > 0 && <MediaGrid media={media} />}\n\n      {isCompact && <time className=\"mt-2 block text-xs text-muted-foreground\">{date}</time>}\n\n      {stats && !isMinimal && (\n        <footer className={cn(\"flex items-center text-[13px] text-muted-foreground\", isCompact ? \"mt-2.5 gap-5\" : \"mt-4 justify-between pr-2\")}>\n          <span className=\"flex items-center gap-1.5\">\n            <MessageCircle className=\"size-[18px]\" strokeWidth={1.75} aria-hidden=\"true\" />\n            <span className=\"tabular-nums\">{formatCount(stats.replies ?? 0)}</span>\n            <span className=\"sr-only\">replies</span>\n          </span>\n          <span className=\"flex items-center gap-1.5\">\n            <Repeat2 className=\"size-[18px]\" strokeWidth={1.75} aria-hidden=\"true\" />\n            <span className=\"tabular-nums\">{formatCount(stats.reposts ?? 0)}</span>\n            <span className=\"sr-only\">reposts</span>\n          </span>\n          <LikeAction likes={stats.likes ?? 0} defaultLiked={defaultLiked} onLike={onLike} reduced={reduced} showCount />\n          {!isCompact && (\n            <span className=\"flex items-center gap-1.5\">\n              <ChartNoAxesColumn className=\"size-[18px]\" strokeWidth={1.75} aria-hidden=\"true\" />\n              <span className=\"tabular-nums\">{formatCount(stats.views ?? 0)}</span>\n              <span className=\"sr-only\">views</span>\n            </span>\n          )}\n        </footer>\n      )}\n    </article>\n  )\n}\n\nexport interface TweetGridItem extends TweetCardProps {\n  /** Stable key. Falls back to the index. */\n  id?: string\n}\n\nexport interface TweetGridProps {\n  /** Posts to lay out. */\n  tweets: TweetGridItem[]\n  /** Maximum number of columns. Fewer are shown in narrow containers. Default: 3 */\n  columns?: number\n  /** Auto-scroll each column vertically like a marquee. Default: false */\n  scroll?: boolean\n  /** Scroll speed multiplier. Higher = faster. Default: 1 */\n  speed?: number\n  /** Scroll every other column in the opposite direction. Default: true */\n  alternate?: boolean\n  /** Pause a column while it is hovered. Default: true */\n  pauseOnHover?: boolean\n  /** Fade the top and bottom edges while scrolling. Default: true */\n  fade?: boolean\n  /** Height of the wall in px when scrolling. Default: 560 */\n  height?: number\n  /** Gap between cards in px. Default: 16 */\n  gap?: number\n  /** Variant applied to every card unless a tweet sets its own. Default: \"default\" */\n  variant?: TweetCardVariant\n  className?: string\n}\n\n// Columns appear as the container grows: 1 → 2 (36rem) → 3 (48rem) → 4 (64rem)\nconst columnVisibility = [\"flex\", \"hidden @xl:flex\", \"hidden @3xl:flex\", \"hidden @5xl:flex\"]\n\nexport function TweetGrid({\n  tweets,\n  columns = 3,\n  scroll = false,\n  speed = 1,\n  alternate = true,\n  pauseOnHover = true,\n  fade = true,\n  height = 560,\n  gap = 16,\n  variant = \"default\",\n  className,\n}: TweetGridProps) {\n  const reduced = useReducedMotion()\n  const cols = Math.min(4, Math.max(1, Math.round(columns)))\n\n  const card = (t: TweetGridItem, i: number, hidden = false, key?: string) => {\n    const { id, ...rest } = t\n    return (\n      <div key={key ?? id ?? i} aria-hidden={hidden || undefined} className=\"break-inside-avoid\" style={{ marginBottom: scroll && !reduced ? 0 : gap }} {...(hidden ? { inert: true } : {})}>\n        <TweetCard variant={variant} {...rest} />\n      </div>\n    )\n  }\n\n  if (!scroll || reduced) {\n    return (\n      <div className={cn(\"@container w-full\", className)}>\n        <div\n          className=\"[column-count:1] @xl:[column-count:min(2,var(--tg-cols))] @3xl:[column-count:min(3,var(--tg-cols))] @5xl:[column-count:var(--tg-cols)]\"\n          style={{ \"--tg-cols\": cols, columnGap: gap } as React.CSSProperties}\n        >\n          {tweets.map((t, i) => card(t, i))}\n        </div>\n      </div>\n    )\n  }\n\n  const buckets: { tweet: TweetGridItem; index: number }[][] = Array.from({ length: cols }, () => [])\n  tweets.forEach((tweet, index) => buckets[index % cols].push({ tweet, index }))\n\n  return (\n    <div className={cn(\"@container w-full\", className)}>\n      <div\n        className=\"flex overflow-hidden\"\n        style={{\n          gap,\n          height,\n          // Alpha mask for edge fading, not a color gradient\n          maskImage: fade ? \"linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent)\" : undefined,\n        }}\n      >\n        {buckets.map((bucket, c) => {\n          // Repeat short columns so one copy is always taller than the viewport\n          const repeats = Math.max(1, Math.ceil(4 / Math.max(1, bucket.length)))\n          const unit = Array.from({ length: repeats }, (_, r) => bucket.map((b) => ({ ...b, r }))).flat()\n          const duration = Math.max(8, unit.length * 9) / Math.max(0.1, speed)\n          const reverse = alternate && c % 2 === 1\n          return (\n            <div key={c} className={cn(\"group/col min-w-0 flex-1 flex-col\", columnVisibility[c])}>\n              <div\n                className={cn(\"flex flex-col\", pauseOnHover && \"group-hover/col:[animation-play-state:paused]\")}\n                style={{ animation: `tw-tweet-scroll ${duration}s linear infinite${reverse ? \" reverse\" : \"\"}` }}\n              >\n                {[0, 1].map((copy) => (\n                  <div key={copy} aria-hidden={copy === 1 || undefined} className=\"flex flex-col\" style={{ gap, paddingBottom: gap }}>\n                    {unit.map(({ tweet, index, r }) => card(tweet, index, copy === 1 || r > 0, `${index}-${r}`))}\n                  </div>\n                ))}\n              </div>\n            </div>\n          )\n        })}\n      </div>\n      <style>{`@keyframes tw-tweet-scroll { to { transform: translateY(-50%) } }`}</style>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs, live playground and every prop: https://trytweenly.vercel.app/docs/components/tweet-card",
  "type": "registry:component"
}