{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "grid-card",
  "type": "registry:ui",
  "title": "Grid Card",
  "description": "The grid-card primitive.",
  "dependencies": [
    "lucide-react@^1.49.0"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/badge.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/grid-card.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/grid-card.tsx",
      "content": "import type { ReactNode } from 'react';\nimport { Folder } from 'lucide-react';\nimport { cn } from '../lib/utils';\nimport { Badge } from './badge';\n\n/** What fills the square: a picture (cover), an icon (centred on a quiet surface), or any node (a mockup thumbnail). */\n/** folder: what is inside, up to 4 of its pictures as a mosaic (1 fills, 2 split, 3 = one large and two small, 4 = 2x2); with none, a\n *  folder icon. count is for the app's meta line (\"11 files\"), never drawn on the picture. */\nexport type GridCardMedia = { image: { src: string; alt: string } } | { icon: ReactNode } | { node: ReactNode } | { folder: { previews: { src: string; alt: string }[]; count?: number } };\n\nexport interface GridCardProps {\n  /** One or two lines; the card's link (or button) text. */\n  title: ReactNode;\n  /** A sentence or two under the title, clamped to three lines. */\n  description?: ReactNode;\n  /** One quiet line pinned to the foot of the card: a kind, a date, a count. */\n  meta?: ReactNode;\n  /** The square at the top (beside the text on a narrow grid). Omitted: text only. */\n  media?: GridCardMedia;\n  /** A string becomes a neutral Badge over the media; pass a Badge for another tone. */\n  badge?: ReactNode;\n  /** A short label floating over the picture's top left, such as a date. Shown only with media. */\n  pill?: ReactNode;\n  /** card: framed, a row beside its square below @md. tile: frameless, always the square over the text, for dense grids of\n   *  files and folders (a CardGrid size small or large); the description, or else the meta, is the line under the title. */\n  look?: 'card' | 'tile';\n  /** Where the card goes. Give `href` or `onClick`, not both. */\n  href?: string;\n  /** For a card that opens something in place (a side panel, a sheet). */\n  onClick?: () => void;\n  /** Renders the title link, for a router's Link. Default: a plain <a>. */\n  link?: (props: { href: string; className: string; children: ReactNode }) => ReactNode;\n  className?: string;\n}\n\nconst plainLink: NonNullable<GridCardProps['link']> = ({ href, className, children }) => <a href={href} className={className}>{children}</a>;\n// The title link or button stretches over the whole card, so the card is one target and nothing interactive nests in it.\nconst STRETCH = \"text-left outline-none after:absolute after:inset-0 after:rounded-kh-lg after:content-['']\";\n\nconst MOSAIC = ['', 'grid-cols-1', 'grid-cols-2', 'grid-cols-2 grid-rows-2 [&>:first-child]:row-span-2', 'grid-cols-2 grid-rows-2'];\n\n/** The card's square on its own, for an app tile that draws its own frame (a /ws DocTile): picture, icon, node or folder mosaic. */\nexport function GridCardSquare({ media }: { media: GridCardMedia }) {\n  return <Square media={media} />;\n}\n\nfunction Square({ media }: { media: GridCardMedia }) {\n  if ('folder' in media) {\n    const shown = media.folder.previews.filter((x) => x.src).slice(0, 4);\n    if (shown.length === 0) return <Square media={{ icon: <Folder aria-hidden strokeWidth={1.5} /> }} />;\n    return (\n      <span className={cn('grid size-full gap-0.5 bg-(--kh-bubble)', MOSAIC[shown.length])}>\n        {shown.map((x, i) => <img key={i} src={x.src} alt={x.alt} loading=\"lazy\" decoding=\"async\" className=\"size-full min-h-0 object-cover\" />)}\n      </span>\n    );\n  }\n  if ('image' in media) return <img src={media.image.src} alt={media.image.alt} loading=\"lazy\" decoding=\"async\" className=\"size-full object-cover\" />;\n  if ('icon' in media) return <span className=\"flex size-full items-center justify-center bg-(--kh-bubble) text-kh-ink-2 in-data-[kh-mode=dark]:text-kh-muted [&_svg]:size-10 @md:[&_svg]:size-[38%]\">{media.icon}</span>;\n  // The node is sized to the square (a thumbnail must scale to fit, at 4.5rem in a row as at full width).\n  return <span aria-hidden className=\"pointer-events-none block size-full overflow-hidden [&>*]:size-full\">{media.node}</span>;\n}\n\n/**\n * One card for every grid of things (projects, tasks, library items, templates): a square media slot, title, description and a\n * meta line pinned to the foot. In a CardGrid every card in a row has the same height, so the gaps stay even. Below @md (the\n * grid's width) it lays out as a row: a small square beside the text. The whole card is one link or button, with hover, press\n * and focus states.\n */\nconst PILL = 'absolute left-2 top-2 rounded-kh-pill bg-kh-surface/90 px-2 py-0.5 text-kh-caption font-medium tabular-nums text-kh-ink-2 shadow-kh-1 backdrop-blur';\nconst badgeOf = (badge: ReactNode) => (typeof badge === 'string' ? <Badge>{badge}</Badge> : badge);\n\nexport function GridCard({ title, description, meta, media, badge, pill, look = 'card', href, onClick, link = plainLink, className }: GridCardProps) {\n  const label = href\n    ? link({ href, className: STRETCH, children: title })\n    : <button type=\"button\" onClick={onClick} className={STRETCH}>{title}</button>;\n  if (look === 'tile') {\n    const line = description ?? meta;\n    return (\n      <article\n        className={cn(\n          // A container, so a tile narrower than 9rem (three on a phone) sets its text a step smaller instead of breaking words.\n          '@container/tile group relative flex h-full w-full min-w-0 flex-col rounded-kh-lg p-1.5 pb-2.5 hover:bg-kh-surface',\n          'transition-[transform,box-shadow,background-color] duration-(--kh-dur) ease-out hover:-translate-y-0.5 hover:shadow-kh-2 active:translate-y-0 active:shadow-kh-1 motion-reduce:transform-none',\n          'has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-(--kh-focus)',\n          className,\n        )}\n      >\n        {media && (\n          <div className=\"relative aspect-square overflow-hidden rounded-kh bg-kh-surface-2\">\n            <Square media={media} />\n            {pill && <span className={PILL}>{pill}</span>}\n            {badge && <span className=\"absolute right-2 top-2\">{badgeOf(badge)}</span>}\n          </div>\n        )}\n        <div className=\"flex min-w-0 flex-col gap-1 px-0.5 pt-2.5\">\n          <h3 className=\"line-clamp-2 text-kh-small font-semibold leading-snug text-kh-ink hyphens-auto break-words @[9rem]/tile:text-kh-body\">{label}</h3>\n          {line && <p className=\"line-clamp-2 text-kh-caption leading-snug text-kh-muted @[9rem]/tile:text-kh-small\">{line}</p>}\n          {!media && badge && <span className=\"pt-1\">{badgeOf(badge)}</span>}\n        </div>\n      </article>\n    );\n  }\n  return (\n    <article\n      className={cn(\n        'group relative flex h-full w-full min-w-0 flex-row gap-3 overflow-hidden rounded-kh-lg border border-kh-line bg-kh-surface p-3 @md:flex-col @md:gap-0 @md:p-0',\n        'transition-[transform,box-shadow] duration-(--kh-dur) ease-out hover:-translate-y-0.5 hover:shadow-kh-2 active:translate-y-0 active:shadow-kh-1 motion-reduce:transform-none',\n        'has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-(--kh-focus)',\n        className,\n      )}\n    >\n      {media && (\n        <div className=\"relative aspect-square w-18 shrink-0 overflow-hidden rounded-kh bg-kh-surface-2 @md:w-full @md:rounded-none @md:border-b @md:border-kh-line\">\n          <Square media={media} />\n          {pill && <span className={cn(PILL, 'hidden @md:inline')}>{pill}</span>}\n          {badge && <div className=\"absolute right-2 top-2 hidden @md:block\">{badgeOf(badge)}</div>}\n        </div>\n      )}\n      <div className=\"flex min-w-0 flex-1 flex-col gap-1 @md:p-4\">\n        <h3 className=\"line-clamp-2 text-kh-body font-medium text-kh-ink [overflow-wrap:anywhere]\">{label}</h3>\n        {description && <p className=\"line-clamp-3 text-kh-small text-kh-muted\">{description}</p>}\n        {(meta || badge) && (\n          <div className={cn('mt-auto flex min-w-0 items-center gap-2 pt-1 text-kh-caption text-kh-muted', !meta && media && '@md:hidden')}>\n            {meta && <span className=\"min-w-0 truncate\">{meta}</span>}\n            {badge && <span className={cn('ml-auto shrink-0', media && '@md:hidden')}>{badgeOf(badge)}</span>}\n          </div>\n        )}\n      </div>\n    </article>\n  );\n}\n\nconst GRID = {\n  // One column of rows on a phone, then 2, 3 and 4 columns (from @5xl, so an app's content beside a sidebar at 1440 gets 4).\n  default: 'gap-3 @md:grid-cols-2 @md:gap-4 @3xl:grid-cols-3 @5xl:grid-cols-4',\n  // Tiles of files: three on a phone, about seven beside a sidebar at 1440.\n  small: 'grid-cols-3 gap-2.5 @md:grid-cols-[repeat(auto-fill,minmax(9.25rem,1fr))] @md:gap-3',\n  // Tiles of folders and pictures (Felix on /ws: \"Make these bigger, less total per row\"): two on a phone, about five at 1440.\n  large: 'grid-cols-2 gap-2.5 @md:grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] @md:gap-4',\n};\n\n/** The grid for GridCards; rows share a height. size small and large are for tiles (GridCard look=\"tile\"). */\nexport function CardGrid({ children, label, size = 'default', className }: { children: ReactNode; label?: string; size?: keyof typeof GRID; className?: string }) {\n  return (\n    <div className=\"@container min-w-0\">\n      <ul aria-label={label} className={cn('grid', GRID[size], className)}>\n        {children}\n      </ul>\n    </div>\n  );\n}\n\n/** One cell of a CardGrid; it stretches, so the card inside fills the row's height. */\nexport const CardGridItem = ({ children }: { children: ReactNode }) => <li className=\"flex min-w-0\">{children}</li>;\n"
    }
  ]
}
