# Card

A box pencilled around a block of content, with a ruled-off footer: plain, lifted off a hatched shadow, or washed with hatching, with a media slot and a pressable, selectable mode.

Docs: https://ballpoint.st9wd.com/docs/card

```bash
npx shadcn@latest add @ballpoint/card
```

```tsx
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle } from "@/components/ui/card"

<Card variant="lifted">
  <CardMedia>
    <img src="/refill.jpg" alt="" />
  </CardMedia>
  <CardHeader>
    <CardTitle>Ink refill</CardTitle>
    <CardDescription>Medium point, blue.</CardDescription>
  </CardHeader>
  <CardContent>Fits most clicky pens.</CardContent>
  <CardFooter>…</CardFooter>
</Card>
```

Props:

- `variant`: `"outline" | "lifted" | "wash"` (default `"outline"`). The pencilled box alone; the box standing off a hatched shadow; or the box hatched lightly across.
- `size`: `"default" | "sm"` (default `"default"`). Inner spacing.
- `interactive`: `boolean` (default `false`). The whole card is something to press: it rises on hover and focus, and gets a focus pass of the pen.
- `selected`: `boolean` (default `false`). Goes over the outline in full ink, for a card that has been picked.
- `render`: `ReactElement`. Render as another element: a link (`<a href>`) or a button, for an interactive card.
- `shadow`: `"hatch" | "solid" | "none"`. What a lifted card stands on. Defaults to "hatch" for the lifted variant, and to none otherwise.
- `fill`: `"hatch" | "shade" | "scribble" | "flat"`. How a washed card is coloured in. Defaults to hatch for the wash variant.
- `CardMedia`: `component`. A picture or drawing across the top, edge to edge inside the box, ruled off underneath.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `weight`, `speed` (see Pen settings).

## Example

```tsx
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";

export default function CardDemo() {
  return (
    <div className="grid w-full gap-10 md:grid-cols-2">
      <Card variant="lifted" seed="card-a">
        <CardHeader>
          <CardTitle>Ink refill</CardTitle>
          <CardDescription>Medium point, blue. Writes about two kilometres.</CardDescription>
          <CardAction>
            <Badge variant="secondary" seed="card-badge">
              In stock
            </Badge>
          </CardAction>
        </CardHeader>
        <CardContent>
          <p className="text-ink-2">Fits most clicky pens. Comes in a paper sleeve, not plastic.</p>
        </CardContent>
        <CardFooter>
          <Button size="sm" seed="card-buy">
            Add to basket
          </Button>
          <Button size="sm" variant="ghost" seed="card-save">
            Save for later
          </Button>
        </CardFooter>
      </Card>
      <Card size="sm" radius={12} seed="card-b">
        <CardHeader>
          <CardTitle>Rounded, smaller</CardTitle>
          <CardDescription>size=&quot;sm&quot; with a 12px radius.</CardDescription>
        </CardHeader>
        <CardContent>
          <p className="text-ink-2">Cards take the same pen settings as everything else.</p>
        </CardContent>
      </Card>
    </div>
  );
}
```

## Variants

Pencilled, lifted off a hatched shadow, or washed with hatching.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";

const kinds = [
  { variant: "outline", note: "Just the pencilled box. The default, and the quietest." },
  { variant: "lifted", note: "Stands off a hatched shadow, like a button does." },
  { variant: "wash", note: "Hatched lightly across, like a note." },
] as const;

export default function CardVariants() {
  return (
    <div className="grid w-full gap-10 sm:grid-cols-3">
      {kinds.map(({ variant, note }) => (
        <Card key={variant} variant={variant} size="sm" seed={`cv-${variant}`}>
          <CardHeader>
            <CardTitle className="font-mono text-base">{variant}</CardTitle>
            <CardDescription>{note}</CardDescription>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-ink-3">variant=&quot;{variant}&quot;</p>
          </CardContent>
        </Card>
      ))}
      <Card variant="lifted" shadow="solid" size="sm" seed="cv-solid" className="sm:col-span-3 sm:mx-auto sm:w-1/2">
        <CardHeader>
          <CardTitle className="font-mono text-base">lifted, solid</CardTitle>
          <CardDescription>shadow=&quot;solid&quot; blacks the shadow in.</CardDescription>
        </CardHeader>
      </Card>
    </div>
  );
}
```

## With a picture

CardMedia runs a photo or drawing edge to edge across the top, ruled off from the text.

```tsx
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardMedia, CardTitle } from "@/components/ui/card";
import { InkIcon, type IconName } from "@/components/ui/ink-icons";

const goods: { name: string; note: string; price: string; icon: IconName; tag?: string }[] = [
  { name: "Cream notebook", note: "A5, 96 pages, lies flat.", price: "£8", icon: "notebook", tag: "New" },
  { name: "Blue ballpoint", note: "Medium point, refillable.", price: "£3", icon: "pen" },
  { name: "Morning coffee", note: "For the long first page.", price: "£4", icon: "coffee" },
];

export default function CardMediaExample() {
  return (
    <div className="grid w-full gap-10 sm:grid-cols-3">
      {goods.map((item) => (
        <Card key={item.name} size="sm" seed={`cm-${item.name}`}>
          {/* Anything goes up here: a photo, an illustration, an icon. It runs edge to edge. */}
          <CardMedia className="h-32 items-center justify-center bg-ink-5/30 text-ink-2">
            <InkIcon name={item.icon} className="size-14" />
            {item.tag && (
              <Badge className="absolute top-3 left-3" seed={`cm-b-${item.name}`}>
                {item.tag}
              </Badge>
            )}
          </CardMedia>
          <CardHeader>
            <CardTitle>{item.name}</CardTitle>
            <CardDescription>{item.note}</CardDescription>
          </CardHeader>
          <CardContent className="text-2xl font-bold tabular-nums">{item.price}</CardContent>
          <CardFooter>
            <Button size="sm" variant="outline" className="w-full" seed={`cm-buy-${item.name}`}>
              Add
            </Button>
          </CardFooter>
        </Card>
      ))}
    </div>
  );
}
```

## Pricing

Plans side by side; the one to pick is lifted and badged.

```tsx
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { InkGlyph } from "@/lib/ink-glyphs";

const plans = [
  { name: "Pencil", price: "£0", note: "To try it out.", features: ["One notebook", "Cream paper"] },
  { name: "Ballpoint", price: "£6", note: "For everyday writing.", features: ["Unlimited notebooks", "Every pen and paper", "Night side"], popular: true },
  { name: "Fountain", price: "£18", note: "For a whole team.", features: ["Everything in Ballpoint", "Shared notebooks", "Margin notes for all"] },
];

export default function CardPricing() {
  return (
    <div className="grid w-full items-stretch gap-10 sm:grid-cols-3">
      {plans.map((plan) => (
        <Card key={plan.name} variant={plan.popular ? "lifted" : "outline"} size="sm" seed={`cp-${plan.name}`}>
          {plan.popular && (
            <Badge className="absolute -top-3 right-4 z-10" seed="cp-popular">
              Popular
            </Badge>
          )}
          <CardHeader>
            <CardTitle>{plan.name}</CardTitle>
            <CardDescription>{plan.note}</CardDescription>
          </CardHeader>
          <CardContent className="flex flex-1 flex-col gap-4">
            <p>
              <span className="text-4xl font-bold tabular-nums">{plan.price}</span>
              <span className="text-ink-3"> / month</span>
            </p>
            <ul className="flex flex-col gap-2 text-ink-2">
              {plan.features.map((feature) => (
                <li key={feature} className="flex items-center gap-2">
                  <InkGlyph name="check" className="size-4 shrink-0 text-ink" />
                  {feature}
                </li>
              ))}
            </ul>
          </CardContent>
          <CardFooter>
            <Button variant={plan.popular ? "default" : "outline"} className="w-full" seed={`cp-buy-${plan.name}`}>
              Choose {plan.name}
            </Button>
          </CardFooter>
        </Card>
      ))}
    </div>
  );
}
```

## Cards you press

interactive cards rise on hover; selected goes over the box in full ink. Here each is a radio button, through render.

```tsx
"use client";

import { useState } from "react";
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { InkIcon, type IconName } from "@/components/ui/ink-icons";

const options: { value: string; title: string; note: string; icon: IconName }[] = [
  { value: "note", title: "A note", note: "A line or two, in the margin.", icon: "edit" },
  { value: "letter", title: "A letter", note: "Ruled paper, a margin, a signature.", icon: "mail" },
  { value: "sketch", title: "A sketch", note: "Squared paper, for plans.", icon: "ruler" },
];

export default function CardPick() {
  const [picked, setPicked] = useState("letter");
  return (
    <div role="radiogroup" aria-label="What to write" className="grid w-full gap-8 sm:grid-cols-3">
      {options.map((option) => (
        <Card
          key={option.value}
          interactive
          selected={picked === option.value}
          variant={picked === option.value ? "wash" : "outline"}
          size="sm"
          seed={`pick-${option.value}`}
          render={<button type="button" role="radio" aria-checked={picked === option.value} onClick={() => setPicked(option.value)} />}
          className="text-left"
        >
          <CardHeader>
            <InkIcon name={option.icon} className="mb-2 size-6" />
            <CardTitle>{option.title}</CardTitle>
            <CardDescription>{option.note}</CardDescription>
          </CardHeader>
        </Card>
      ))}
    </div>
  );
}
```

## Login form

A card holding a form, with a full-width action and a quiet link underneath.

```tsx
"use client";

import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function CardForm() {
  return (
    <Card className="w-full max-w-sm" seed="cf-card">
      <CardHeader>
        <CardTitle>Sign in</CardTitle>
        <CardDescription>Use the email you booked with.</CardDescription>
      </CardHeader>
      <CardContent>
        <form id="cf-form" onSubmit={(event) => event.preventDefault()}>
          <FieldGroup>
            <Field>
              <FieldLabel htmlFor="cf-email">Email</FieldLabel>
              <Input id="cf-email" type="email" placeholder="you@example.com" seed="cf-email" />
            </Field>
            <Field>
              <FieldLabel htmlFor="cf-password">Password</FieldLabel>
              <Input id="cf-password" type="password" seed="cf-password" />
            </Field>
          </FieldGroup>
        </form>
      </CardContent>
      <CardFooter>
        <div className="flex w-full flex-col items-center gap-3">
          <Button type="submit" form="cf-form" className="w-full" seed="cf-submit">
            Sign in
          </Button>
          <Button variant="link" seed="cf-forgot">
            Forgot your password?
          </Button>
        </div>
      </CardFooter>
    </Card>
  );
}
```

## Stats

Small cards in a grid, for numbers with a note.

```tsx
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";

const stats = [
  ["Pages written", "1,284", "+12% this month"],
  ["Ink used", "62 ml", "About half a refill"],
  ["Doodles", "389", "Mostly in margins"],
] as const;

export default function CardStats() {
  return (
    <div className="grid w-full gap-6 sm:grid-cols-3">
      {stats.map(([label, value, note]) => (
        <Card key={label} size="sm" seed={`cs-${label}`}>
          <CardHeader>
            <CardDescription>{label}</CardDescription>
            <CardTitle className="text-3xl tabular-nums">{value}</CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-ink-3">{note}</p>
          </CardContent>
        </Card>
      ))}
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
