[!NOTE] Compound component — an opinionated composition of Helix primitives.
Import
import { SaveIndicator } from "@timelycare/helix-ui"
Usage
<Field>
<div className="flex items-center gap-3">
<FieldLabel htmlFor="visit-notes">Visit notes</FieldLabel>
{status && <SaveIndicator status={status} savedAt={savedAt} />}
</div>
<Textarea id="visit-notes" value={notes} onChange={onNotesChange} />
</Field>
Save after a pause in typing, about a second, and set status to "saving", then "saved" with the time it landed. "Saved at 2:41 PM" answers the question the person actually has, which is whether the last thing they typed is safe. A bare "Saved" looks the same a second later or ten minutes later.
If a save fails, set "retrying" while you try again: a warning icon and "Unsaved changes — retrying", in full-strength text so it stands out from the muted states. If saving stops for good, take the indicator away and put a warning Alert above the field:
<Alert variant="warning">
<TriangleAlert />
<AlertDescription>
Autosave has stopped and your recent changes aren't saved. Copy your notes somewhere safe, then reload the visit.
</AlertDescription>
</Alert>
The indicator is a polite live region, so mount it at the first save and only change status after that. "Saved at …" and "Unsaved changes — retrying" are read out; "Saving…" is not, so a save on every pause doesn't talk over someone who is still typing.