Updated
Unsaved Changes
ProCustomize
Accent
Height560px
Radius24px
Installation
ProUnsaved Changes is a Pro component
Sign in to see the source, or install it with a license key. The live preview and props above are free to explore.
Install with a key
- Add the Pro registry to
components.json:components.json { "registries": { "@uibrik-pro": { "url": "https://uibrik.com/r/pro/{name}.json", "headers": { "Authorization": "Bearer ${UIBRIK_LICENSE}" } } } } - Put your key in
.env.localand add that file to.gitignore:.env.local UIBRIK_LICENSE=your-license-key - Install it:
Terminal npx shadcn@latest add @uibrik-pro/unsaved-changes
Loading your installation…
Usage
import { UnsavedChanges } from "@/components/uibrik/unsaved-changes/unsaved-changes";<UnsavedChanges accent="#f59e0b" guardLinks beforeUnload height={560} radius={24} onSave={(values, changed) => {}} onDiscard={() => {}}> …</UnsavedChanges>Where to use Unsaved Changes
Settings pages
A dot on every edited field and a counted Save make it clear what will change.
Pairs with Settings Page
Long forms
Marks on the scroll edge point to edits that have scrolled out of view.
Guarding navigation
Leaving with edits shakes the button and scrolls to the first one instead of losing it.
Pairs with Inline Confirm
Props
UnsavedChanges- accent
- Type string
- "#f59e0b"
- Colour of the change dots, the field highlight and the scroll marks.
- guardLinks
- Type boolean
- true
- Stops link clicks while there are edits: the button shakes and the first edit scrolls into view. A second click goes through.
- beforeUnload
- Type boolean
- true
- Asks the browser to confirm closing or reloading the tab while there are edits.
- height
- Type number
- 560
- Height of the panel. The fields scroll inside it.
- radius
- Type number
- 24
- Corner radius of the panel.
- childrenrequired
- Type ReactNode
- –
- The fields. Wrap each in <UnsavedField name label hint?> around a native input, select or textarea with the same name. Edits are found by comparing values with the last save.
- onSave
- Type (values, changed: string[]) => void | Promise<void>
- –
- Runs on Save or Cmd/Ctrl+S with every named value. A promise shows Saving until it settles; a rejection shakes the button and keeps the edits.
- onDiscard
- Type () => void
- –
- Runs after Discard resets the native fields. Reset any controlled fields here.
- useUnsavedChanges()
- Type { count, changed, save, discard, guard }
- –
- Hook for children. Call guard() before a programmatic navigation: it returns true when it stopped it.
- className
- Type string
- –
- Classes for the panel.