{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "autosave-note-with-status",
  "title": "Autosaving Note",
  "description": "A note that saves itself a moment after you stop typing, shows Saving, Saved at a time or a retryable error, and saves immediately when you leave the page or press the button. Use this when losing a draft is worse than saving too often.",
  "registryDependencies": [
    "textarea",
    "label",
    "button",
    "@tealmac/form-autosave"
  ],
  "files": [
    {
      "path": "registry/patterns/autosave-note-with-status/autosave-note-with-status.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport { AutosaveIndicator, useAutosave } from \"@/components/ui/form-autosave\"\nimport { Label } from \"@/components/ui/label\"\nimport { Textarea } from \"@/components/ui/textarea\"\n\nexport interface AutosaveNoteWithStatusProps {\n  initial?: string\n  /** Persist the note. Reject to show a retryable error. */\n  save?: (text: string) => Promise<void>\n  delay?: number\n}\n\nconst demoSave = async () => {\n  await new Promise((r) => setTimeout(r, 300))\n}\n\nexport function AutosaveNoteWithStatus({\n  initial = \"\",\n  save = demoSave,\n  delay = 800,\n}: AutosaveNoteWithStatusProps) {\n  const [text, setText] = React.useState(initial)\n  const autosave = useAutosave({ value: text, onSave: save, delay })\n\n  return (\n    <div className=\"flex w-full max-w-md flex-col gap-2\">\n      <div className=\"flex items-center justify-between\">\n        <Label htmlFor=\"anws-note\">Meeting notes</Label>\n        <AutosaveIndicator {...autosave} onRetry={autosave.retry} />\n      </div>\n      <Textarea\n        id=\"anws-note\"\n        rows={6}\n        value={text}\n        onChange={(e) => setText(e.target.value)}\n        onBlur={() => void autosave.flush()}\n      />\n      <Button\n        type=\"button\"\n        variant=\"outline\"\n        size=\"sm\"\n        className=\"self-end\"\n        disabled={autosave.status === \"saving\"}\n        onClick={() => void autosave.flush()}\n      >\n        Save now\n      </Button>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}