# Card

The stream-level container, drawn as a code window, never casting a shadow; a window variant adds a title bar.

Live variants: https://design.arcadia.is/components/card

```tsx
import {
  Card, CardHeader, CardTitle, CardMeta, CardBody, CardRows, CardFooter,
  CardCorner,
} from "@arcadia/ui";
```

## When to use

- An object that stands on its own: a plan, a form, a run's output
- A run's diff, its files as rows under one header
- A related group of stream events in one turn

## When not to use

- Rows that need no frame of their own: use `ListRow`
- Something that floats over the page: use `Dialog`, `Popover` or a menu
- Settings with a name, a state and a control: use `SettingsRow` in `SettingsGroup`

## In context

In Act, a conversation draws a run's code change as one card, its header counting the files and each row naming one with its added and removed lines.

```tsx
import { Card, CardHeader, CardMeta, CardRows, ListRow } from "@arcadia/ui";

function Changes() {
  const files = [
    ["settings-dialog.tsx", "src/settings", 9, 2],
    ["settings.css", "src/settings", 4, 1],
    ["index.ts", "src", 1, 0],
  ] as const;
  return (
    <Card>
      <CardHeader>
        3 files changed
        <CardMeta>
          <span {...sx("cmp-add", cmp.add)}>+14</span> <span {...sx("cmp-del", cmp.del)}>−3</span>
        </CardMeta>
      </CardHeader>
      <CardRows>
        {files.map(([name, dir, add, del]) => (
          <ListRow
            key={name}
            leading="file-code"
            label={name}
            description={dir}
            emphasis
            meta={<>
              <span {...sx("cmp-add", cmp.add)}>+{add}</span>
              {del > 0 && <span {...sx("cmp-del", cmp.del)}>−{del}</span>}
            </>}
          />
        ))}
      </CardRows>
    </Card>
  )
```

## Usage

```tsx
import { Card, CardBody, CardHeader, CardMeta, CardTitle } from "@arcadia/ui";

<Card>
  <CardHeader icon="terminal" divided>
    Ran <CardTitle>make test</CardTitle>
    <CardMeta>1.2s</CardMeta>
  </CardHeader>
  <CardBody>12 passed, 0 failed</CardBody>
</Card>
```

A resting card uses `--bg-card` and the card shadow. A card drawn under the pointer (`lifted`) uses the elevated fill and a floating shadow. Put rows in `CardRows` (ListRows inset 6px), prose in `CardBody` (a long body may keep a few lines behind `clamp`), a title and meta in `CardHeader`, and actions in `CardFooter`.

## Examples

### Interactive header

With `interactive`, the whole header is one button: a disclosure, or a way to open the plan. Don't nest other buttons in it; a static header with `CardMeta` can hold them instead.

```tsx
import { useState } from "react";
import { Card, CardBody, CardHeader, CardTitle } from "@arcadia/ui";

function Plan() {
  const [open, setOpen] = useState(true);
  return (
    <Card>
      <CardHeader
        icon="plan"
        interactive
        divided={open}
        aria-expanded={open}
        onClick={() => setOpen(!open)}
      >
        Plan
        <CardTitle>Settings dialog</CardTitle>
      </CardHeader>
      {open && (
        <CardBody {...sx("cmp-prose", cmp.prose)}>
          Move every preference into one dialog with a sidebar of sections, and keep the
          shortcut list searchable.
        </CardBody>
      )}
    </Card>
  );
}
```

### A form

`render` turns the card into the `<form>` itself, so the footer's buttons submit and reset it natively.

```tsx
import {
  Button, Card, CardBody, CardFooter, CardHeader, CardTitle, Field, Input,
} from "@arcadia/ui";

<Card render={<form onSubmit={(e) => e.preventDefault()} />}>
  <CardHeader icon="settings" divided>
    <CardTitle>Profile</CardTitle>
  </CardHeader>
  <CardBody {...sx("cmp-form", cmp.form)}>
    <Field label="Display name">
      <Input name="name" defaultValue="Ada Lovelace" autoComplete="name" />
    </Field>
  </CardBody>
  <CardFooter>
    <Button size="sm" type="reset">Reset</Button>
    <Button size="sm" variant="primary" type="submit">Save</Button>
  </CardFooter>
</Card>
```

### Window

`variant="window"` makes the first header a title bar: the file in mono (its name in text-1, the folder in text-3), stats and actions at the end and always shown, and a hairline below. A file and its diff read as one object.

```tsx
import { Card, CardBody, CardHeader, CardMeta, CardTitle } from "@arcadia/ui";

function Window() {
  return (
    <Card variant="window">
      <CardHeader>
        <CardTitle>receipt.ts</CardTitle>
        src/lib
        <CardMeta><span {...sx("cmp-add", cmp.add)}>+2</span> <span {...sx("cmp-del", cmp.del)}>−1</span></CardMeta>
      </CardHeader>
      <CardBody>
        <pre {...sx(null, cmp.code, styles.signature)}><code>{[
          "export function receiptFor({",
          "  subtotalMinor,",
          "  feeMinor = 0,",
          "  currency,",
          "}: Receipt) {",
          "  return subtotalMinor",
          "    + feeMinor;",
          "}",
        ].join("\n")}</code></pre>
      </CardBody>
    </Card>
  );
}
```

### Moving a card

While a card is moved, `drag="ghost"` fades it where it stood and `drag="slot"` draws a dashed frame where it will land, between the cards at rest. Give the slot the moved card's parts: they hold its height and are not drawn, heard or reached by Tab. The same move by keyboard draws the same two. A product that draws the card under the pointer too gives that copy `lifted`.

The ghost, a card at rest, the drop slot and the lifted copy.

```tsx
import { Card, CardBody, CardHeader, CardTitle } from "@arcadia/ui";

<div {...stylex.props(styles.board)}>
  <Card drag="ghost">
    <CardHeader><CardTitle>Move the upload test to the staging runner</CardTitle></CardHeader>
    <CardBody>The fixture server waits for its port before the first test starts.</CardBody>
  </Card>
  <Card>
    <CardHeader><CardTitle>Write the release notes</CardTitle></CardHeader>
  </Card>
  <Card drag="slot">
    <CardHeader><CardTitle>Move the upload test to the staging runner</CardTitle></CardHeader>
    <CardBody>The fixture server waits for its port before the first test starts.</CardBody>
  </Card>
  <Card lifted>
    <CardHeader><CardTitle>Move the upload test to the staging runner</CardTitle></CardHeader>
    <CardBody>The fixture server waits for its port before the first test starts.</CardBody>
  </Card>
</div>
```

### Drop target

With `dropTarget` the frame takes the active edge and the ground steps up: the card a moved one will be dropped onto, rather than beside, says so before it is let go.

The outline appears on the drop target, not on the resting cards.

```tsx
import { Card, CardBody, CardHeader, CardTitle } from "@arcadia/ui";

<div {...stylex.props(styles.board)}>
  <Card dropTarget>
    <CardHeader><CardTitle>Move the upload test to the staging runner</CardTitle></CardHeader>
    <CardBody>A card dropped here joins this one.</CardBody>
  </Card>
  <Card>
    <CardHeader><CardTitle>Write the release notes</CardTitle></CardHeader>
  </Card>
</div>
```

### A long body

`clamp` keeps a few lines of a card's prose, and a ghost button under it opens the rest. The button stands only while the text is longer than the lines kept.

```tsx
import {
  Card, CardBody, CardHeader, CardTitle, FormattedText,
} from "@arcadia/ui";

<Card>
  <CardHeader><CardTitle>Release notes</CardTitle></CardHeader>
  <CardBody clamp={{ lines: 5, more: "Show full description", less: "Show less" }}>
    <FormattedText source={LONG} />
  </CardBody>
</Card>
```

### Levels and variants

`stream` is the default. `level="nested"` marks an independent object inside another surface and takes its corner from the enclosing frame. Here `variant="inset"` sets the test run apart by its ground alone. Forced colours restore the edge. A third frame fails in development even if marked.

```tsx
import {
  Card, CardBody, CardHeader, CardMeta, CardRows, CardTitle, Shimmer,
} from "@arcadia/ui";

<Card>
  <CardHeader icon="task">
    <CardTitle>Audit focus order</CardTitle>
    <CardMeta><Shimmer>Working</Shimmer></CardMeta>
  </CardHeader>
  <CardRows>
    <Card level="nested" variant="inset">
      <CardHeader>Keyboard test run</CardHeader>
      <CardBody><span {...sx(null, cmp.code)}>12 passed, 0 failed</span></CardBody>
    </Card>
  </CardRows>
</Card>
```

## Customising

`rootStyle` takes where the card sits and these knobs; the header, body, rows and footer read them too, so `--card-px` moves every part's padding at once.

- `--card-bg` (`Paint`, default `var(--bg-card)`)
- `--card-border` (`Paint`, default `transparent`)
- `--card-radius` (`Ref<Radius>`)
- `--card-px` (`Ref<Space>`, default `var(--space-3)`)
- `--card-bar-h` (`Ref<Control>`, default `var(--control-lg)`)
- `--card-header-gap` (`Ref<Space>`, default `var(--space-1-5)`)

Rows inside `CardRows` subtract their 6px inset and the border from the card radius, keeping the same corner shape.

## Accessibility

A card is a plain `<div>` with no role; its parts are text and the controls you put in them. The one exception is an `interactive` header, which renders a `<button>`: give it `aria-expanded` when it discloses the body, as above, and keep its text short, because the whole header is its name.

When a card is a section people navigate to, give it a heading or `role="region"` with `aria-labelledby` on its title. Diff counts are colour and text, so "+14 −3" still reads without the colour.

- Enter + Space: Activates an interactive header
- Tab: Moves through the controls inside

## API reference

### Card

- `level` (`"stream" | "nested"`, default `"stream"`)
- `nesting` (`"contained-object"`): A separately framed object that belongs inside another one, not a layout wrapper.
- `variant` (`"default" | "inset" | "window"`, default `"default"`)
- `mono` (`boolean`, default `false`)
- `lifted` (`boolean`)
- `dropTarget` (`boolean`, default `false`)
- `drag` (`"ghost" | "slot"`)
- `rootStyle` (`CardStyle`)

Rest props go to `<div>` props and `render`.

### CardHeader

- `icon` (`IconName`)
- `interactive` (`boolean`, default `false`)
- `divided` (`boolean`, default `false`)

Rest props go to `<div>` props and `render`.

### CardFooter

- `divided` (`boolean`, default `false`)

Rest props go to `<div>` props and `render`.

### CardTitle

- `link` (`boolean`)
- `rootStyle` (`stylex.StyleXStyles<Omit<Layout, "maxWidth"> & { maxWidth?: Layout["maxWidth"] | `${number}%` }>`)

Rest props go to `<span>` props and `render`.

### CardCorner

- `shown` (`boolean`, default `false`)

Rest props go to `<div>` props and `render`.

### CardMeta

No props of its own. Rest props go to `<span>` props and `render`.

### CardBody

No props of its own. Rest props go to `<div>` props and `render`.

### CardRows

No props of its own. Rest props go to `<div>` props and `render`.
