Skip to Content
BBRICKSv0.7.4
KitForms

SaveBar

Sticky bar over an editor that changes a draft copy; only while the draft differs. saveDisabled keeps Save off while the draft cannot be saved (a field is invalid) but Discard still works.

import { SaveBar } from '@ergasti/bricks';

Examples

Save bar

Appears with "Unsaved changes" once dirty; saveDisabled turns Save off while the draft has an error, and Discard keeps working.

Code
import { useState } from 'react';
import { SaveBar } from '@ergasti/bricks';

function Draft() {
  const [name, setName] = useState('Top sellers');
  const [saved, setSaved] = useState('Top sellers');
  const [saving, setSaving] = useState(false);
  const invalid = name.trim() === '';
  return (
    <div style={{ maxWidth: 460, display: 'grid', gap: 10 }}>
      <label>Group name <input value={name} onChange={(event) => setName(event.target.value)} style={{ width: '100%' }} /></label>
      {invalid && <small>Give the group a name.</small>}
      <SaveBar
        dirty={name !== saved}
        saving={saving}
        saveDisabled={invalid}
        onSave={() => { setSaving(true); window.setTimeout(() => { setSaved(name); setSaving(false); }, 600); }}
        onDiscard={() => setName(saved)}
      />
    </div>
  );
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key saveBar, or with the component's own prop where it has one. A {name} is a value the component fills in.

saveBar
KeyEnglishArabic
unsavedUnsaved changesتغييرات مش محفوظة
discardDiscardتجاهل
saveSaveحفظ
savingSaving…جاري الحفظ…

Design guidance

How the BRICKS design system uses SaveBar. Written in docs/content/components/SaveBar.md; the props above are read from the code, which wins where the two disagree.

A sticky dark bar that appears over an editor while its draft differs from what is saved, with Discard and Save; use it for pages that edit a copy of settings and save in one go.

It renders only when dirty. It sticks 10px from the top of its scroll container, in the inverse colours (dark ink, white text), with "Unsaved changes" at the start and the two buttons at the end. saveDisabled keeps Save off while a field is invalid, but Discard still works; saving disables both and shows "Saving…".

Anatomy

  1. Region: div.kit-savebar[role=region], sticky, z-index 20, flex, padding 10px 12px (16px start), --radius-lg, --color-text-primary background, shadow, slide-in.
  2. Status text: .kit-savebar-t[role=status], 13px / 600, "Unsaved changes"; names the region.
  3. Discard: kit-btn kit-btn--on-dark.
  4. Save: kit-btn (white); "Saving…" while saving.

Variants

None; behaviour is driven by state props.

States

StateTriggerLook
Cleandirty={false}Not rendered.
DirtydirtyBar with Discard and Save.
Save disabledsaveDisabledSave off, Discard on.
SavingsavingBoth off, Save reads "Saving…".
Focus-visible—Inverse focus ring.

Usage

const [draft, setDraft] = useState(saved);
const dirty = !isEqual(draft, saved);

<SaveBar dirty={dirty} saving={save.pending} saveDisabled={draft.name.trim() === ''}
  onSave={() => save.run(draft)} onDiscard={() => setDraft(saved)} />
<Card title="Gift rules">
  <GiftRulesCard value={draft.rules} onChange={(rules) => setDraft({ ...draft, rules })} />
</Card>
// With a field error shown by the editor
<FormField label="Group name" error={draft.name.trim() === '' ? 'Give the group a name.' : undefined}>
  <input value={draft.name} onChange={(e) => setDraft({ ...draft, name: e.target.value })} />
</FormField>
<SaveBar dirty saveDisabled={draft.name.trim() === ''} onSave={save} onDiscard={reset} />

Where it appears

  • Not drawn in the v3 mocks (their settings are read-only). Shown in the v3 kit gallery over an editable form; available for editable settings pages (gift rules, PR Portal settings).

Guidelines

Do

  • Render it at the top of the editor's scroll container so it sticks.
  • Show the reason Save is off next to the field, not in the bar.

Don't

  • Don't use it for forms in a modal; those have their own footer buttons.
  • Don't auto-save and show the bar at the same time.

RTL and Arabic

  • Text at the inline start, buttons at the end, mirrored in RTL.
  • Copy: "تغييرات مش محفوظة", "تجاهل", "حفظ", "جاري الحفظ…".

Tokens

--color-text-primary, --color-text-inverted, --radius-lg, --focus-ring-inverse.

Accessibility

  • A region named by its text; only the text is role="status", so the buttons are never read as part of a message. The bar renders nothing until dirty, so the status mounts with its text: screen readers may not read "Unsaved changes" when it first appears. The region is reachable by landmark navigation and by Tab (its buttons).
  • Native disabled buttons; inverse focus ring on the dark bar.
  • Slide-in animation is removed under prefers-reduced-motion.

Found in the source

  • Roles in the markup: region, status.
  • ARIA attributes set: aria-labelledby.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: FormField · SearchBox · Segmented · SelectBox

Source

src/kit/SaveBar.tsx (line 10) on GitHub.

On this page