SaveBar
Appears at the bottom while there are unsaved changes: save them or put things back. It stays in the page as you scroll, never over a dialog.
import { SaveBar } from '@sypnia/ui/react'
On this page
Unsaved changes
Change the name or the switch, then save or discard.
Project
Its name and whether it keeps daily copies.
Code
import { useState } from 'react';
import { Field, FormSection, Input, SaveBar, Switch, toast, Toaster } from '@sypnia/ui/react';
// Change anything: the bar appears. «Discard» puts the saved values back.
const saved = { name: 'Storefront', backups: true };
export default function Unsaved() {
const [values, setValues] = useState(saved);
const [base, setBase] = useState(saved);
const [busy, setBusy] = useState(false);
const dirty = values.name !== base.name || values.backups !== base.backups;
return (
<>
<div className="sy-form">
<FormSection title="Project" description="Its name and whether it keeps daily copies.">
<Field label="Project name"><Input value={values.name} onChange={(e) => setValues({ ...values, name: e.target.value })} /></Field>
<Switch label="Daily backup" checked={values.backups} onChange={(e) => setValues({ ...values, backups: e.target.checked })} />
</FormSection>
<SaveBar dirty={dirty} busy={busy} onDiscard={() => setValues(base)}
onSave={() => { setBusy(true); setTimeout(() => { setBase(values); setBusy(false); toast('Changes saved', { tone: 'ok' }); }, 1200); }} />
</div>
<Toaster />
</>
);
} When to use it
Use it when
- Settings pages where several changes are saved together.
- Say what changed when it helps: «3 changes in Columns».
Do not use it when
- Forms with their own submit button: the button is enough.
- Settings that apply at once: a toast confirms them.
For everyone
- It is a region named «You have unsaved changes» and its text is a status, read once when it appears.
- On phones the two buttons share the width, two by two.
Props
| SaveBar | Type | Default |
|---|---|---|
dirtyrequired | boolean | |
onDiscardrequired | () => void | |
onSaverequired | () => void | |
busy | boolean | |
messageWhat changed, if it helps: «3 changes in Columns». Defaults to «You have unsaved changes». | ReactNode | |
saveLabel | string |