# SaveBar

A persistent save and discard panel for forms with an unsaved draft.

Connect Flood once using [the installation guide](https://flood.md/docs/installation). Then import the components you use; no per-component add command is needed.

## Example

```tsx
"use client";

import { FloodRoot, SaveBar } from "@flood-md/react";
import "@flood-md/react/styles.css";

export function Example() {
  return (
    <FloodRoot>
      <SaveBar form="project-settings" state="dirty" />
    </FloodRoot>
  );
}
```

## Design notes

- Use the default viewport placement when the end of a long form may be out of view. Place the bar near the view root, outside transformed or clipped containers. Reserve enough bottom clearance in the scroll owner for the last field. Use inline placement within an overlay or a constrained panel.
- Pass the target form ID when rendering outside that form. Save and Discard use native submit and reset, so the form owns validation, persistence, controlled field reset and navigation guards.
- Drive state from the real draft and request. Change to clean after successful save or reset. Keep the draft on error, supply a useful state label and allow retry. If saving or resetting hides the focused bar, return focus to a persistent form control.

## API reference

| Prop | Values | Default |
| --- | --- | --- |
| `state` | `"clean" \| "dirty" \| "saving" \| "error"` | `Required` |
| `form` | `string` | `—` |
| `placement` | `"viewport" \| "inline"` | `"viewport"` |
| `saveDisabled` | `boolean` | `false` |
| `announce` | `boolean` | `—` |
| `labels` | `{     group?: string;     save?: string;     discard?: string;     state?: Partial<Record<Exclude<SaveBarState, "clean">, string>>;   }` | `—` |
| `Native HTML props` | `Omit<HTMLAttributes<HTMLDivElement>, "children" \| "role">` | `Forwarded` |
