# Pull request

One card through a pull request's life: its commits on two lanes, its conflicts, its diff, and the product's one action; and the composer's pull request chip.

Live variants: https://design.arcadia.is/components/pull-request

```tsx
import {
  PullRequestCard, PullRequestChip, pullRequestStateWord, pullRequestChipWord,
  shortHash,
} from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import { PullRequestCard, PullRequestChip } from "@arcadia/ui";

function InChat() {
  const [resolved, setResolved] = useState(false);
  return (
    <div {...sx("pull-request-column", PullRequestPage.column)}>
      <PullRequestCard number={128} title="Refresh the session on start" state="open" head={HEAD} base={BASE}
        commits={resolved ? COMMITS : CONFLICTED} diff={DIFF} conflicts={resolved ? undefined : CONFLICTS}
        action={resolved ? undefined : { label: "Resolve conflicts", onClick: () => setResolved(true) }} />
      <div {...sx("pull-request-chips", PullRequestPage.chips)}>
        <PullRequestChip number={128} state="open" conflicts={resolved ? 0 : 3} />
      </div>
    </div>
  );
}
```

## Accessibility

The card is one group named by its number, its state and its conflicts, such as "Pull request 128, Open, 3 conflicts with main". Its commits are a list, each read as its message, hash, author, time and tag, and a conflicting commit says its count in words. The pill names its state and swaps one glyph for the next; the spinner stands beside the word Resolving or Creating.

The checks chip names every check that did not pass. The only control of the card's own is the product's action, a Button that keeps its name and shows the focus ring. The chip is a button only when the product gives it an onClick, and it keeps the ring and its name in both forms. Under forced colours the lanes, the nodes and the merge ring take the system's inks, and the words carry every state without them; under reduced motion the card and its new commits arrive at once, and the spinner and the running dot stand still.

## API reference

### PullRequestCard

- `number` (`number`, required): The pull request's number, drawn after a hash.
- `title` (`string`, required): Its title, one line; a longer one ends with an ellipsis, the whole title on hover.
- `state` (`"creating" | "draft" | "open" | "resolving" | "merged" | "closed"`, required): Its state: the pill at the header's end says it and the graph draws it.
- `head` (`string`, required): The branch it comes from.
- `base` (`string`, required): The branch it merges into.
- `commits` (`readonly PullRequestCommit[]`, required): Its commits, oldest first as the graph reads; a commit on the base carries `branch={base}`.
- `diff` (`{ additions: number; deletions: number }`): The change's lines, from git's diff stat.
- `conflicts` (`{ count?: number; by?: string; files: readonly string[] }`): Its conflicts with the base, when there are any.
- `action` (`{ label: string; onClick: () => void }`): The card's one action, offered while the pull request is open or a draft ("Ready for review").
- `ended` (`{ at?: string; branchDeleted?: boolean }`): How it merged or closed: when, and whether the head branch was deleted.
- `checks` (`ReactNode`): Its checks on the head commit, at the end of the merge row: the kit's ChecksChip, or a ChecksPopover that opens them.
- `stateLabel` (`string`): The pill's word for the state, when the product's own differs from the kit's.
- `leading` (`IconName | ReactNode`): A status glyph name or node before the title: it starts on the card's text edge, and the title after it stands on the commits' text.
- `rootStyle` (`RootStyle`): Where the card sits; its width is the product's.

Rest props go to `HTMLAttributes<HTMLDivElement>`.

### PullRequestChip

- `number` (`number`, required): The pull request's number, drawn after a hash.
- `state` (`"creating" | "draft" | "open" | "resolving" | "merged" | "closed"`, required): Its state.
- `conflicts` (`number`, default `0`): Its conflicts while it is open or a draft: the chip says them instead of its state.
- `stateLabel` (`string`): The state's word, when the product's own differs from the kit's.
- `onClick` (`() => void`): Opens the card, as a composer's chip does. Renders a button; without it, a chip of words.
- `rootStyle` (`RootStyle`): Where the chip sits.

Rest props go to `HTMLAttributes<HTMLSpanElement>`.
