Autosave status for the header of an editor. It says whether the edits are saving, saved and how long ago, failed with a Retry, waiting offline, or changed by someone else with Review, Keep mine and Keep theirs. You run the save; it shows the state you pass.
On this page
- Prompt editor header
- Agent instructions
- Doc and note editors
- Settings that save on change
- Offline-first forms
Examples
Autosave as you type
Edited elsewhere
Installation
npx knowns-ui@latest add save-statePaste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install Save state from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/save-state
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add save-state
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/status-dot.tsx
- components/ui/knowns/use-floating.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/save-state/save-state.tsx
- components/ui/knowns/save-state/save-state-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/save-state, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "save-state" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- state
"idle"|"saving"|"saved"|"failed"|"offline"|"conflict"- What happened to the edits. Controlled.
- lastSavedAt
number|Date- When the last save landed: Saved 2m ago, and Last saved 2m ago on a failure. Idle with a time reads Saved.
- now
number- Default
Date.now() - Fixes the clock for tests and screenshots. Without it the time refreshes every 30s.
- queued
number- Default
0 - Edits waiting while offline: 3 edits will save when back online.
- error
ReactNode- Why the save failed, in the Retry tooltip.
- conflictBy
string- Who changed it elsewhere: Edited elsewhere by Mai Tran.
- onRetry
() => void- Shows Retry on a failure.
- onReview
() => void- Shows Review on a conflict, to open a compare view.
- onResolve
(choice: "mine" | "theirs") => void- Shows Keep mine and Keep theirs on a conflict.
- variant
"inline"|"pill"- Default
"inline" - Text in a header row, or the status on a hairline pill with the actions beside it.
- size
"sm"|"md"- Default
"md" - 12 or 12.5px text; the actions are 24 or 28px buttons.
| Prop | Type | Default | Description |
|---|---|---|---|
| state | "idle" | "saving" | "saved" | "failed" | "offline" | "conflict" | - | What happened to the edits. Controlled. |
| lastSavedAt | number | Date | - | When the last save landed: Saved 2m ago, and Last saved 2m ago on a failure. Idle with a time reads Saved. |
| now | number | Date.now() | Fixes the clock for tests and screenshots. Without it the time refreshes every 30s. |
| queued | number | 0 | Edits waiting while offline: 3 edits will save when back online. |
| error | ReactNode | - | Why the save failed, in the Retry tooltip. |
| conflictBy | string | - | Who changed it elsewhere: Edited elsewhere by Mai Tran. |
| onRetry | () => void | - | Shows Retry on a failure. |
| onReview | () => void | - | Shows Review on a conflict, to open a compare view. |
| onResolve | (choice: "mine" | "theirs") => void | - | Shows Keep mine and Keep theirs on a conflict. |
| variant | "inline" | "pill" | "inline" | Text in a header row, or the status on a hairline pill with the actions beside it. |
| size | "sm" | "md" | "md" | 12 or 12.5px text; the actions are 24 or 28px buttons. |
Accessibility
- The icon and the label sit in a polite status region, so a change of state is read once. The time after it is outside the region, so it does not speak every 30 seconds.
- The icons are decorative. Each state also has words, so colour is never the only signal.
- Retry, Review, Keep mine and Keep theirs are buttons you reach with Tab. Retry shows its reason on focus as well as on hover.
- With reduced motion the check, the shake and the label rise are gone and the state changes at once.
What it handles
- 01Says what happened to the edits in six states: no changes yet, saving, saved with how long ago, could not save, offline and edited elsewhere.
- 02Keeps the time fresh (Saved 2m ago, 3h ago, yesterday) every 30 seconds without saying it again to a screen reader.
- 03Offers Retry on a failure, with the reason in its tooltip, and Review, Keep mine and Keep theirs on a conflict, each through your callback.
- 04Counts the edits that wait while offline: 3 edits will save when back online.
- 05Sits as plain text in a header row, or on a hairline pill, in two sizes.
- 06Stays controlled: you own the save, it only shows the state you pass.
States
- First render
- The state paints as it is, nothing plays
- none
- Saving and saved while typing
- The words crossfade, the check is still
- 120ms opacity, ease out
- Other label changes
- The new words settle with a 4px rise
- 180ms, ease out
- Saved after a failure, offline or a conflict
- The check draws
- 180ms, ease out
- Saving to failed
- The mark shakes once and its X draws
- 280ms shake, 180ms draw
- Edited elsewhere
- The mark pulses once
- 180ms, ease out
- Time passes
- The time text changes in place
- none
- Reduced motion
- States change at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | The state paints as it is, nothing plays | none |
| Saving and saved while typing | The words crossfade, the check is still | 120ms opacity, ease out |
| Other label changes | The new words settle with a 4px rise | 180ms, ease out |
| Saved after a failure, offline or a conflict | The check draws | 180ms, ease out |
| Saving to failed | The mark shakes once and its X draws | 280ms shake, 180ms draw |
| Edited elsewhere | The mark pulses once | 180ms, ease out |
| Time passes | The time text changes in place | none |
| Reduced motion | States change at once | 0ms |
Works with
When to use
When to use
- Telling people whether their edits in a prompt, doc or settings editor are saved, still saving, failed, waiting offline or changed by someone else.
- An autosave form or editor header where a Save button would be one step too many.
When not to use
- A save that needs a full message and an action, such as a lost session: use Toast.
- The live state of an agent or a run: use Status Dot.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Save State to my app and wire it to my own data.
- I need telling people whether their edits in a prompt, doc or settings editor are saved, still saving, failed, waiting offline or changed by someone else. Set that up with the Knowns UI Save State.
- Which Save State props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "save-state" }) and search_docs({ query: "save state" }).