shadcn.io is not affiliated with official shadcn/ui
Saved Draft Top Bar Banner Block for React
A top bar for a writing tool that reports its autosave with a green dot and a ticking time, and a Restore previous button that swaps in place to Restored with an Undo.
Installation
Overview
A top bar for React with Base UI, the status line of an editor. Anvilwell's strip sits between the page's rails on a faint tint: at the start a green dot, "Draft saved" in medium weight and how long ago, "12 seconds ago", which ticks every second and turns into minutes; at the end an underlined "Restore previous" button. Pressing it swaps, in the same place, to "Restored · Undo" and moves focus to Undo; pressing Undo swaps it back. Either press restarts the saved time and a polite status line says what happened. The two states share one grid cell, so nothing moves. It is not a notice, so it has no close; it is 44 pixels tall on a desktop and two lines at most on a phone. It follows your theme and is built from Guides and Status.
FAQ
How does the time tick without causing trouble?
The first save is a little old (12 seconds), and the age is worked out in the browser after the first render, so the server's markup is the same every time. Until then the line holds the room of "12 seconds ago" invisibly, so nothing shifts when it fills in. It is a time element with a machine-readable dateTime, updated once a second from Intl.RelativeTimeFormat: seconds first, then minutes. It is not inside a live region, so a screen reader is not told every second.
What do Restore previous and Undo do?
Nothing in the block saves a document: they flip a state and are the two places to call your own code. In restore bring back the previous version and, in undo, the latest one. Both reset the saved time to now (the document has just been saved again) and set the status line's text.
Where does focus go after Restore previous?
The button you pressed is replaced by the other state's, so focus is moved for you: to Undo after a restore, and back to Restore previous after an Undo. The hidden state is invisible and inert, so it can't be reached by Tab or read by a screen reader. Focus is moved in an effect after the change is on screen.
What does a screen reader hear?
The strip is a labelled "Draft status" region. A polite status line, empty until the first press, says "Previous version restored." or "Undone. Your latest draft is back." The ticking age is deliberately outside it.
Related
- Pro
Live Indicator Banner
Live statusA heartbeat callout for a monitoring tool: a framed status dot that sends out one ring on each poll, an all-systems-operational heading, a line with how long ago it checked and the p95 latency, and a status-page link.
- 1,248Pro
Data Sync Live Banner
Live statusA sync callout for a data warehouse: one run plays on load, a counter rolling up to 1,248 records over a thin progress bar, then "Warehouse synced" with a countdown to the next run.
- Pro
Toast Pill Banner
PillsA saved-settings toast pill for a settings panel: a success check, a message, an Undo button wearing a ring that drains over six seconds, and a dismiss button.
- Pro
Workspace Top Bar Banner
Utility barsA top bar for a team workspace manager that says which workspace you are in, with your role as a badge and a Switch menu of workspaces behind a divider.
- Pro
Top Bar Banner
Top barsA slim announcement strip for a writing app's release: one centred line with the version, the news and an underlined link, and a ghost button that folds the strip away.
- 3Pro
An unsaved-changes pill for a form builder: a rolling count of changes, a small Save button and a ghost Discard, settling on a saved or discarded message.