{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "undo-button-demo",
  "title": "Undo Button Demo",
  "description": "A worked example of Undo Button: An action that looks done at once and only commits after a few seconds. Until then the button is Undo.",
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/undo-button.json"
  ],
  "files": [
    {
      "path": "components/demos/undo-button-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { UndoButton } from \"@/registry/default/undo-button/undo-button\"\n\nconst drafts = [\n  { id: \"launch\", title: \"Launch checklist\", edited: \"Edited yesterday\" },\n  { id: \"retro\", title: \"Sprint retro notes\", edited: \"Edited 3 days ago\" },\n  {\n    id: \"hiring\",\n    title: \"Interview loop questions\",\n    edited: \"Edited last week\",\n  },\n]\n\nexport function UndoButtonDemo() {\n  const [items, setItems] = React.useState(drafts)\n  const [leaving, setLeaving] = React.useState<string[]>([])\n\n  return (\n    <div className=\"bg-background border-border w-full max-w-[30rem] rounded-[1.25rem] border p-4 shadow-sm\">\n      <div className=\"flex items-baseline justify-between px-2 pb-2\">\n        <h3 className=\"text-sm font-semibold\">Drafts</h3>\n        <span className=\"text-muted-foreground text-xs\">\n          Hover the button to hold the clock\n        </span>\n      </div>\n\n      {items.length ? (\n        <ul className=\"divide-border divide-y\">\n          {items.map((item) => {\n            const deleting = leaving.includes(item.id)\n\n            return (\n              <li\n                key={item.id}\n                className=\"flex items-center gap-3 px-2 py-3\"\n                data-deleting={deleting || undefined}\n              >\n                <div className=\"min-w-0 flex-1\">\n                  <p\n                    className={\n                      deleting\n                        ? \"text-muted-foreground truncate text-sm line-through\"\n                        : \"truncate text-sm font-medium\"\n                    }\n                  >\n                    {item.title}\n                  </p>\n                  <p className=\"text-muted-foreground text-xs\">\n                    {deleting ? \"Deleting\" : item.edited}\n                  </p>\n                </div>\n                <UndoButton\n                  aria-label={deleting ? undefined : `Delete ${item.title}`}\n                  message={`Deleted ${item.title}`}\n                  onAction={() => setLeaving((ids) => [...ids, item.id])}\n                  onUndo={() =>\n                    setLeaving((ids) => ids.filter((id) => id !== item.id))\n                  }\n                  onCommit={() => {\n                    setLeaving((ids) => ids.filter((id) => id !== item.id))\n                    setItems((list) => list.filter((d) => d.id !== item.id))\n                  }}\n                />\n              </li>\n            )\n          })}\n        </ul>\n      ) : (\n        <div className=\"flex flex-col items-center gap-3 px-2 py-8 text-center\">\n          <p className=\"text-muted-foreground text-sm\">No drafts left.</p>\n          <button\n            type=\"button\"\n            className=\"border-border hover:bg-muted focus-visible:ring-ring/50 min-h-9 rounded-[var(--radius)] border px-3 text-sm outline-none focus-visible:ring-4\"\n            onClick={() => setItems(drafts)}\n          >\n            Bring them back\n          </button>\n        </div>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}