# Opportunity Card

An opportunity in a contact's column of the opportunity workspace: the matter type with its stage dot, the staff on it and its matter number. Selected, the border and title take the stage colour and the details open below. The card is one button; the staff avatars beside it stay their own control.

- Beta: ready to use; its API can still change in a minor release.
- Category: Patterns · Workspace & pipeline

```tsx
import { OpportunityCard } from "@leap-crm/design-system";
```

## Best practices

- Do: Pass the same `stage` the `Pipeline` shows (label, icon and tone), so the card and the pipeline read the same.
- Do: Move the selection in one render: clear `selected` on one card and set it on the next together, so the closing details and the opening ones trade height and the column holds still.
- Do: Set `conflictCheck` while a conflict check is still required. The shield is drawn and also said in the card's accessible name.
- Do: Put the rows a lawyer needs on the selected card, like Created, Created by and Last updated, in `details`. The matter number and age fade out while the card is selected.
- Don't: Put a button or link in `details` or beside the title. The card's button covers the whole card; only the staff avatars sit above it as their own control.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space | Select the card: it is one button. |

## Related

- [Card](./card.md)
- [Pipeline](./pipeline.md)
- [Workspace Table](./workspace-table.md)

## Examples

What the examples import:

```tsx
import { BookOpenCheck, Calendar, DoorClosedLocked, FileSignature, MessageCircleMore, ShieldCheck } from "lucide-react";
import { useState } from "react";
import { Button, OpportunityCard, type OpportunityCardStage } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const stages: OpportunityCardStage[] = [
  { label: "Enquiry", icon: <MessageCircleMore />, tone: "info" },
  { label: "Qualifying", icon: <ShieldCheck />, tone: "warning" },
  { label: "Scheduled", icon: <Calendar />, tone: "success" },
  { label: "Agreement", icon: <FileSignature />, tone: "teal" },
  { label: "Active", icon: <BookOpenCheck />, tone: "purple" },
  { label: "Closed", icon: <DoorClosedLocked />, tone: "default" },
];

const staff = [
  { id: "1", name: "Sam Brooks", initials: "SB" },
  { id: "2", name: "Mia Grant", initials: "MG" },
];

const details = [
  { label: "Created", value: "11 hours ago" },
  { label: "Created by", value: "Firm Pilot" },
  { label: "Last updated", value: "Just now" },
];

const card = {
  title: "Divorce",
  reference: "CRM/1042",
  age: "11 hours ago",
  staff,
  details,
  conflictCheck: true,
};

function Column() {
  const [selected, setSelected] = useState("Scheduled");
  return (
    <div className="flex w-72 flex-col gap-2">
      {stages.slice(0, 3).map(stage => (
        <OpportunityCard
          key={stage.label}
          {...card}
          title={
            stage.label === "Enquiry"
              ? "Family Law – Property Settlement"
              : card.title
          }
          stage={stage}
          selected={selected === stage.label}
          onSelect={() => setSelected(stage.label)}
        />
      ))}
    </div>
  );
}

const moreDetails = [
  ...details,
  { label: "Source", value: "Website enquiry" },
  { label: "Referred by", value: "Harbour Lending" },
  { label: "Value", value: "$12,400" },
];

function ComingAndGoing() {
  const [open, setOpen] = useState(true);
  const [withNext, setWithNext] = useState(false);
  const shown = withNext
    ? [...moreDetails, { label: "Next step", value: "Book a consult" }]
    : moreDetails;
  return (
    <div className="flex flex-col gap-3">
      <div className="flex gap-2">
        <Button
          intent="outline"
          size="sm"
          onClick={() => setOpen(value => !value)}
        >
          {open ? "Deselect" : "Select"}
        </Button>
        <Button
          intent="ghost"
          size="sm"
          aria-pressed={withNext}
          onClick={() => setWithNext(value => !value)}
        >
          Next step
        </Button>
      </div>
      <div className="flex w-72 flex-col gap-2">
        <OpportunityCard
          {...card}
          stage={stages[3]!}
          details={shown}
          selected={open}
          onSelect={() => setOpen(true)}
        />
        <OpportunityCard {...card} title="Will and estate" stage={stages[0]!} />
      </div>
    </div>
  );
}
```

### In a column

Press a card to select it: the border and title take its stage colour and Created, Created by and Last updated open below. Hover for the subtle fill; Tab for the focus border and halo. A long matter type truncates and shows in full on hover.

```tsx
<Column />
```

### Details coming and going

Selecting the card opens its space on the resize curve and the details cascade in, a beat apart, all in place in about 300 ms however many there are. A detail added while it's open opens its own row and turns in; one removed fades before its row closes. Deselecting fades them together, then the card closes up. With reduced motion they fade, with no cascade.

```tsx
<ComingAndGoing />
```

### Every stage

The stage dot carries the stage fill and icon; selected, the stage colour edges the card.

```tsx
<div className="grid grid-cols-[repeat(2,18rem)] gap-3">
  {stages.map(stage => (
    <OpportunityCard
      key={`${stage.label}-rest`}
      {...card}
      stage={stage}
    />
  ))}
  {stages.map(stage => (
    <OpportunityCard
      key={`${stage.label}-selected`}
      {...card}
      stage={stage}
      selected
    />
  ))}
</div>
```

### Without a conflict check or staff

The shield shows only while a conflict check is still required.

```tsx
<div className="w-72">
  <OpportunityCard
    title="Wills and estates"
    stage={stages[0] ?? { label: "Enquiry", icon: null, tone: "info" }}
    reference="CRM/1043"
    age="2 days ago"
  />
</div>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` (required) | `string` |  | The matter type, like "Divorce". |
| `stage` (required) | `{ label: string; /** A 12 px icon in the stage colour, as on the Pipeline. */ icon: ReactNode; tone: StageTone; }` |  | The pipeline stage: its label, icon and tone, as on the Pipeline. |
| `reference` | `string` |  | The LEAP matter number, like "CRM/1042". |
| `age` | `ReactNode` |  | How long ago it was opened, already formatted, like "11 hours ago". |
| `staff` | `AvatarItem[]` | `[]` | The staff on it, as small avatars. |
| `conflictCheck` | `boolean` | `false` | Shows the shield: a conflict check is still required. |
| `selected` | `boolean` | `false` | Selected: the border and title take the stage colour and the details open below. |
| `details` | `unknown` | `[]` | Rows shown while selected, like Created, Created by and Last updated. |
| `onSelect` | `() => void` |  | Selects the opportunity in the workspace. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
