# Status Mark

The toast's loading-then-done, for any control: a resting icon turns into the spinner, and the spinner turns into a tick or a cross that draws itself in. Every 'work, then result' moment uses it, so the motion is the same everywhere.

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

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

## Best practices

- Do: Use it wherever a control does work and then shows the result, like copying a matter number or uploading a document, so every such moment moves the same way.
- Do: Pass the control's resting icon as children, so the mark sits in the icon's place before and after the work.
- Do: Say what happened in the control's text or a live region, like "Copied" or "Upload failed". The mark is decorative, and the tick and cross differ in shape, not only colour.
- Do: Set the colour on the parent, like the success text colour for done. The mark draws in the current text colour.
- Don't: Build this into a `Button` yourself. Pass `showResult` and return a Promise from `onClick`; the button runs the same spinner, tick and cross.
- Don't: Add your own delay before switching from `busy` to `done`. Busy already plays at least one full pass, so a quick job never flashes.

## Related

- [Badge](./badge.md)
- [Spinner](./spinner.md)
- [Priority](./priority.md)
- [Live Indicator](./live-indicator.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { Button, CopyIcon, StatusMark, UploadIcon, 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);
  });

function Cycle({ outcome }: { outcome: "done" | "error" }) {
  const [state, setState] = useState<StatusMarkState>("idle");
  const run = async () => {
    setState("busy");
    await wait(900);
    setState(outcome);
    setTimeout(() => setState("idle"), 1400);
  };
  return (
    <div className="flex items-center gap-3">
      <span
        className={
          outcome === "done"
            ? "text-status-success-text flex"
            : "text-status-error-text flex"
        }
      >
        <StatusMark state={state}>
          <UploadIcon />
        </StatusMark>
      </span>
      <Button intent="outline" size="sm" onClick={run}>
        {outcome === "done" ? "Run and succeed" : "Run and fail"}
      </Button>
    </div>
  );
}
```

### Work, then result

Busy always plays one full pass, so a quick job never flashes. The tick and cross arrive through their own rounded ends at full weight. With reduced motion they crossfade and appear whole.

```tsx
<div className="flex flex-col gap-4">
  <Cycle outcome="done" />
  <Cycle outcome="error" />
</div>
```

### States

Idle shows the icon you pass, or nothing. It draws in the current text colour; the control around it, or a live region, says what happened.

```tsx
<div className="text-neutral-text-secondary flex items-center gap-6">
  <StatusMark state="idle">
    <CopyIcon />
  </StatusMark>
  <StatusMark state="busy" />
  <span className="text-status-success-text flex">
    <StatusMark state="done" />
  </span>
  <span className="text-status-error-text flex">
    <StatusMark state="error" />
  </span>
</div>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `state` (required) | `"idle" \| "busy" \| "done" \| "error"` |  | idle shows the icon you pass; busy the spinner; done a tick and error a cross, each drawing itself in. |
| `children` | `ReactNode` |  | The resting glyph, like a copy or upload icon. Leave it out to show nothing while idle. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
