# Grid card

- **[Atoms](/components/)**

One card for every grid of things: a square picture, icon or thumbnail, a title and a meta line. Rows share a height; on a phone each card is a row. For files and folders, look="tile" in a CardGrid size small or large: frameless tiles, three or two on a phone.

## Preview

grid-card.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { GridCard, CardGrid, CardGridItem } from '@/components/klarhimmel/ui/grid-card';

export default function Example() {
  return (
    <Theme theme="brand">
      <CardGrid label="Projects"><CardGridItem><GridCard href="/projects/menu" title="Spring menu" description="New photos and prices." meta="4 tasks" media={{ image: { src: '/menu.jpg', alt: 'The menu page' } }} /></CardGridItem></CardGrid>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add https://ui.klarhimmel.com/r/grid-card.json
  ```
- **Import**

  ```
  import { GridCard, CardGrid, CardGridItem, GridCardSquare } from '@/components/klarhimmel/ui/grid-card';
  ```

- **Files**: grid-card.tsx, in components/klarhimmel/ui/. With it: badge, theme, utils. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Tiles**

  ```
  import { CardGrid, CardGridItem, GridCard } from '@/components/klarhimmel/ui/grid-card';
  import { FileTypeIcon } from '@/components/klarhimmel/ui/file-type-icon';
  
  const pics = ['bike-shop', 'brewery-taproom', 'butcher', 'barber'].map((t) => ({ src: `/thumbs/template-${t}.webp`, alt: '' }));
  
  /** Tiles for a library: folders large (two on a phone), files small (three on a phone, about seven at 1440). */
  export default function GridCardTiles() {
    return (
      <div className="flex w-full flex-col gap-8 p-6">
        <CardGrid label="Folders" size="large">
          <CardGridItem><GridCard look="tile" href="#photos" title="Photos for the site" meta="11 files" media={{ folder: { previews: pics, count: 11 } }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" href="#menu" title="Menus" meta="3 files" media={{ folder: { previews: ['food-truck', 'gelato-shop', 'cobbler'].map((t) => ({ src: `/thumbs/template-${t}.webp`, alt: '' })), count: 3 } }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" href="#press" title="Press" meta="Empty" media={{ folder: { previews: [] } }} /></CardGridItem>
        </CardGrid>
        <CardGrid label="Files" size="small">
          <CardGridItem><GridCard look="tile" href="#a" title="Roastery menu" description="Photo · 2.1 MB" pill="12 Oct" media={{ image: { src: '/thumbs/template-coffee-roaster.webp', alt: 'The roastery menu page' } }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" href="#b" title="Bridal fittings" description="Photo · 1.8 MB" pill="9 Oct" media={{ image: { src: '/thumbs/template-bridal-shop.webp', alt: 'The bridal shop page' } }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" onClick={() => undefined} title="Brand guidelines" description="PDF · 12 pages" pill="2 Oct" media={{ icon: <FileTypeIcon kind="brand_guide" /> }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" href="#c" title="Opening hours" description="Document" media={{ icon: <FileTypeIcon kind="document" /> }} /></CardGridItem>
          <CardGridItem><GridCard look="tile" href="#d" title="The campsite in May" description="Photo · 3.4 MB" media={{ image: { src: '/thumbs/template-campsite.webp', alt: 'The campsite page' } }} /></CardGridItem>
        </CardGrid>
      </div>
    );
  }
  ```

## Props

- **GridCard.title**: One or two lines; the card's link (or button) text.
- **GridCard.description**: A sentence or two under the title, clamped to three lines.
- **GridCard.meta**: One quiet line pinned to the foot of the card: a kind, a date, a count.
- **GridCard.media**: The square at the top (beside the text on a narrow grid). Omitted: text only.
- **GridCard.badge**: A string becomes a neutral Badge over the media; pass a Badge for another tone.
- **GridCard.pill**: A short label floating over the picture's top left, such as a date. Shown only with media.
- **GridCard.look**: card: framed, a row beside its square below
- **GridCard.href**: Where the card goes. Give `href` or `onClick`, not both.
- **GridCard.onClick**: For a card that opens something in place (a side panel, a sheet).
- **GridCard.link**: Renders the title link, for a router's Link. Default: a plain <a>.
- **GridCard.className**: Extra classes, merged after the component's own.
- **CardGrid.children**
- **CardGrid.label**
- **CardGrid.size**
- **CardGrid.className**: Extra classes, merged after the component's own.
- **CardGridItem.children**
- **GridCardSquare.media**: The square: a picture (cover), a centred icon, any node such as a mockup thumbnail, or a folder: up to 4 of its pictures as a mosaic (the folder icon when it has none; count belongs in meta).

[Previous](/components/file-type-icon)

[Next](/components/page-preview-card)
