# Fetch Cursor

A small badge that trails the pointer while something the person clicked is fetching: a spinner that turns into a drawn tick or cross when it settles. It shows the wait where they're looking, a moment behind the pointer. With reduced motion nothing follows the pointer; the cursor becomes the system's progress cursor.

- Beta: ready to use; its API can still change in a minor release.
- Category: Feedback

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

## Best practices

- Do: Use it while something the person clicked is fetching, like pressing a contact and waiting for its workspace, so the wait shows where they're looking.
- Do: Set `state` to `busy` when the fetch starts, `done` or `error` when it settles, then `idle` to put it away.
- Do: Render one per page. It draws into the body, so one copy serves every click on the page.
- Do: Give it a `label`, like "Loading contacts", unless the page already announces the fetch. Without one it is decorative.
- Don't: Use it for a wait the person didn't start, like a background sync. Show a `Spinner` or `Skeleton` where the content will appear.
- Don't: Make anything else follow the pointer, like a contact preview. A preview anchors to what it's about, in a `HoverCard`.

## Related

- [Spinner](./spinner.md)
- [Skeleton](./skeleton.md)
- [Progress](./progress.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { Button, FetchCursor, RefreshCwIcon, type StatusMarkState } from "@leap-crm/design-system";
```

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

```tsx
const wait = (ms: number) =>
  new Promise<void>(resolve => {
    setTimeout(resolve, ms);
  });

const labels: Partial<Record<StatusMarkState, string>> = {
  busy: "Refreshing contacts",
  done: "Contacts refreshed",
  error: "Couldn't refresh contacts",
};

function Fetching({ outcome }: { outcome: "done" | "error" }) {
  const [state, setState] = useState<StatusMarkState>("idle");
  const fetchContacts = async () => {
    setState("busy");
    await wait(1200);
    setState(outcome);
    setTimeout(() => setState("idle"), 1400);
  };
  return (
    <>
      <Button
        intent="outline"
        icon={<RefreshCwIcon />}
        onClick={() => {
          void fetchContacts();
        }}
      >
        {outcome === "done" ? "Refresh contacts" : "Refresh (fails)"}
      </Button>
      <FetchCursor state={state} label={labels[state]} />
    </>
  );
}
```

### Fetching after a click

Press a button and move the pointer: the badge follows it while the fetch runs (1.2 s here), then draws its result and leaves. Set state to busy when the fetch starts, done or error when it settles, and idle to put it away. One per page is enough; it renders into the body.

```tsx
<div className="flex gap-3">
  <Fetching outcome="done" />
  <Fetching outcome="error" />
</div>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `state` (required) | `"idle" \| "busy" \| "done" \| "error"` |  | busy while the fetch runs; done or error once it settles, then idle to put it away. Idle shows nothing. |
| `label` | `string` |  | What screen readers hear while it shows, like "Loading contacts". Leave it out when the page already announces the fetch. |
