<!-- generated by scripts/gen-docs.mjs from docs/system/feedback.md. Edit the source and rerun. -->
# Feedback

## Description

What a control shows after you act, and when. Each kind of action has the feedback you expect from it: a change on the page answers at once, a request shows its progress where you started it, and a result you cannot see confirms itself with a toast.

## Tokens

Feedback has no tokens of its own. It times itself with the motion tokens and the constants in `registry/cobalt/lib/motion.ts`: `SPINNER_DELAY_MS` (250), `SPINNER_MINIMUM_MS` (400), `RESULT_HOLD_MS` (1500) and `ERROR_HOLD_MS` (3000).

## Specimens

Six rows of the table below run live on the system's own parts. A sort answers at once, an invite shows its progress on a StateButton and its error under the field, a switch moves back when its save fails, an export ends in a toast, an archive offers Undo and ends in an empty state, and a record loads with skeleton lines or fails in place. Every request goes to a stand-in server that answers in about a second; the Offline toggle above the rows makes each one fail, so every failure path can be seen. The scenes on the introduction page show the same rows inside a working product.

## By action

| When you                                                        | Expect                                                                                   | Use                                                                                    |
| --------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| Sort, filter loaded rows, switch a tab, open a menu, expand     | The change at once. No spinner, no toast                                                 | The control's own state                                                                |
| Copy a link or a value                                          | The glyph turns to a check for a moment                                                  | `IconSwap` on the button; "Could not copy" when the clipboard refuses                  |
| Search or filter against a server                               | The old results stay; they dim only if the answer takes longer than 250ms                | `ListBody` or the table's `status` with `useSlowWait`                                  |
| Open a page or a record for the first time                      | The layout at once, its values as they arrive                                            | `Skeleton` lines at the exact size of the text                                         |
| Turn a setting on or off                                        | The switch moves at once; it moves back with a message if the save fails                 | `Switch` acting at once, the request in the background                                 |
| Save, send, publish or create from a button you stay beside     | Progress on the button, then a short result word                                         | `StateButton` with `useAction`; errors at the field                                    |
| Submit a dialog or sheet that closes when done                  | Progress on its button; after it closes, a toast says what happened                      | `StateButton` in the footer, then `toast()` with a link or Undo                        |
| Remove something you can bring back (archive, hide, unfollow)   | It goes at once, with Undo; nothing is committed until the window ends                   | `useUndoable`: a toast with Undo for 10 seconds, held while hovered or focused         |
| Remove something you cannot bring back                          | A question first, then progress, then the result                                         | `AlertDialog` with a `StateButton` and `AlertDialogError` on failure                   |
| Start work that takes many seconds (export, import, report)     | Progress you can leave, and a message with the result when it is ready                   | `Progress` or a toast with progress, ending in a toast with a Download action          |
| New data arrives while you read                                 | Nothing moves; a count tells you there is more                                           | A "3 new" pill above the list that shows them when pressed                             |
| Edit a form that saves itself                                   | A quiet line says Saving, Saved, or Not saved with Retry                                 | `useAutosave` with `SaveLine`                                                          |
| Write something whose answer is lost (the connection drops)     | It says it could not confirm, and offers Check, never a blind Retry                      | `StateButton` or `SaveLine` with the `unconfirmed` status                              |
| Wait longer than 8 seconds                                      | A line says it is taking longer than usual, with Retry, in room held for it              | `LongWaitNotice`                                                                       |
| Read while the connection is gone                               | A banner says you are offline; what is on screen stays                                   | `OfflineBanner` with `useOnline`                                                       |
| Open a page that cannot load (not found, signed out, failed)    | The page says why in plain words, with one way forward, and takes the title and focus   | `PageProblem`                                                                          |
| Something fails that you did not start (a sync, a lost session) | A message that stays until you act on it                                                 | A toast with no timeout and an action, or an `Empty` with Retry in the place it failed |

## Usage

- `rule/feedback-local-is-instant`: When an action changes only what is already on the page (a sort, a filter of loaded rows, a tab, a copy), show the change at once with no `Spinner` and no `toast()`, because a spinner on a change that took no time claims a wait that did not happen. Evidence: principle heuristic: visibility of system status, the change itself is the feedback; person D39. Check: review of every spinner and toast against the table.
  - Don't: `toast("Sorted by gross assets")`
  - Do: `<DataTable sort={sort} onSortChange={setSort} />`
- `rule/feedback-progress-where-you-acted`: When an action waits on a server, show its progress on the control you pressed, through `StateButton` and `useAction`, because your eyes are already there and the rest of the page keeps working. Evidence: person D39; principle heuristic: visibility of system status, progress at the point of action. Check: review of every request started from a button.
  - Don't: `<Button onClick={save}>Save</Button> {saving && <Spinner />}`
  - Do: `<StateButton status={save.status} onClick={() => void save.run()}>Save</StateButton>`
- `rule/feedback-toast-for-what-you-cannot-see`: When the result of an action happens somewhere you can no longer see, such as after a dialog closes or an export that took more than 2 seconds finishes, confirm it with a `toast()`, and when the result is visible in place, show no toast, because a toast that repeats what is on screen is noise and one that is missing leaves you guessing. Evidence: principle heuristic: visibility of system status; person D39. Check: review of every `toast()` call.
  - Don't: `toast("Saved")` next to a button that already shows Saved
  - Do: `toast("Invitation sent to 3 people")` after the invite dialog closes
- `rule/feedback-undo-over-confirm`: When an action can be undone, do it at once and offer Undo in a toast that lasts 10 seconds, and ask first only when it cannot be undone, because a question before every action trains you to click through questions. Evidence: principle heuristic: user control and freedom, undo is cheaper than a question; person D39. Check: review of every `AlertDialog`.
  - Don't: `<AlertDialogTitle>Archive this list?</AlertDialogTitle>`
  - Do: `toast("List archived", { action: { label: "Undo", onClick: restore }, duration: 10000 })`
- `rule/feedback-live-data-waits`: When new data arrives while you read, hold it behind a count such as "3 new filings" and show it when pressed, because rows that appear above your place move the row you were about to press. Evidence: person D37; principle heuristic: user control and freedom, nothing moves that you did not move. Check: review of every list fed by a timer or a socket.
  - Don't: `setRows((rows) => [incoming, ...rows])`
  - Do: `setPending((pending) => [incoming, ...pending])` with a `Pill` that merges them

## Accessibility

A result word on a `StateButton` is announced through its status region; a toast is announced through the toaster's live region; a count of new items is a `role="status"` line. A failure that needs you stays until you act on it, so a screen reader user has time to reach it.

## Not tokens

- The four timing constants live in `registry/cobalt/lib/motion.ts` beside the motion presets, since they are durations a script reads, not values a stylesheet reads.
