{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swipe-actions-demo",
  "title": "Swipe Actions Demo",
  "description": "A worked example of Swipe Actions: List rows that swipe aside to reveal what can be done with them, the way a mail inbox does. Every action is also in a menu.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/swipe-actions.json"
  ],
  "files": [
    {
      "path": "components/demos/swipe-actions-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Archive, Mail, MailOpen, Trash2 } from \"lucide-react\"\n\nimport {\n  SwipeActions,\n  SwipeActionsItem,\n} from \"@/registry/default/swipe-actions/swipe-actions\"\n\ntype Message = {\n  id: string\n  from: string\n  subject: string\n  preview: string\n  time: string\n  unread: boolean\n}\n\nconst inbox: Message[] = [\n  {\n    id: \"lease\",\n    from: \"Marta Alves\",\n    subject: \"Lease renewal for flat 3B\",\n    preview: \"The new terms start in March. I attached the signed copy.\",\n    time: \"9:41\",\n    unread: true,\n  },\n  {\n    id: \"dentist\",\n    from: \"Riverside Dental\",\n    subject: \"Your appointment on Thursday\",\n    preview: \"Reply C to confirm or call us to move it.\",\n    time: \"8:15\",\n    unread: true,\n  },\n  {\n    id: \"photos\",\n    from: \"Tomás Reyes\",\n    subject: \"Photos from Sunday\",\n    preview: \"Forty-two of them. The one with the dog is the best.\",\n    time: \"Yesterday\",\n    unread: false,\n  },\n  {\n    id: \"library\",\n    from: \"City Library\",\n    subject: \"Two books due next week\",\n    preview: \"You can renew them online up to three times.\",\n    time: \"Mon\",\n    unread: false,\n  },\n]\n\nexport function SwipeActionsDemo() {\n  const [messages, setMessages] = React.useState(inbox)\n  const [last, setLast] = React.useState<{\n    verb: string\n    message: Message\n    index: number\n  } | null>(null)\n\n  const remove = (message: Message, verb: string) => {\n    const index = messages.findIndex((item) => item.id === message.id)\n    setLast({ verb, message, index })\n    setMessages(messages.filter((item) => item.id !== message.id))\n  }\n\n  const toggleRead = (message: Message) =>\n    setMessages((current) =>\n      current.map((item) =>\n        item.id === message.id ? { ...item, unread: !item.unread } : item\n      )\n    )\n\n  return (\n    <div className=\"w-full max-w-[26rem]\">\n      <SwipeActions label=\"Inbox\">\n        {messages.map((message) => (\n          <SwipeActionsItem\n            key={message.id}\n            label={message.subject}\n            leading={[\n              {\n                label: message.unread ? \"Read\" : \"Unread\",\n                icon: message.unread ? <MailOpen /> : <Mail />,\n                tone: \"primary\",\n                onSelect: () => toggleRead(message),\n              },\n            ]}\n            trailing={[\n              {\n                label: \"Delete\",\n                icon: <Trash2 />,\n                tone: \"destructive\",\n                onSelect: () => remove(message, \"Deleted\"),\n              },\n              {\n                label: \"Archive\",\n                icon: <Archive />,\n                onSelect: () => remove(message, \"Archived\"),\n              },\n            ]}\n          >\n            <div className=\"grid gap-0.5 px-4 py-3\">\n              <div className=\"flex items-baseline gap-2\">\n                <span\n                  aria-hidden=\"true\"\n                  className={\n                    message.unread\n                      ? \"bg-primary size-2 shrink-0 self-center rounded-full\"\n                      : \"size-2 shrink-0\"\n                  }\n                />\n                <span\n                  className={\n                    message.unread\n                      ? \"min-w-0 flex-1 truncate text-sm font-semibold\"\n                      : \"min-w-0 flex-1 truncate text-sm font-medium\"\n                  }\n                >\n                  {message.from}\n                  {message.unread ? (\n                    <span className=\"sr-only\">, unread</span>\n                  ) : null}\n                </span>\n                <span className=\"text-muted-foreground shrink-0 text-xs\">\n                  {message.time}\n                </span>\n              </div>\n              <p className=\"truncate pl-4 text-sm\">{message.subject}</p>\n              <p className=\"text-muted-foreground truncate pl-4 text-xs\">\n                {message.preview}\n              </p>\n            </div>\n          </SwipeActionsItem>\n        ))}\n      </SwipeActions>\n\n      {messages.length === 0 ? (\n        <p className=\"text-muted-foreground mt-3 text-sm\">Inbox is empty.</p>\n      ) : null}\n\n      <div\n        className=\"mt-3 flex min-h-8 items-center justify-between gap-3 text-sm\"\n        role=\"status\"\n      >\n        {last ? (\n          <>\n            <span className=\"text-muted-foreground truncate\">\n              {last.verb} “{last.message.subject}”\n            </span>\n            <button\n              type=\"button\"\n              className=\"text-primary focus-visible:ring-ring shrink-0 rounded-sm font-medium underline-offset-4 hover:underline focus-visible:ring-2 focus-visible:outline-none\"\n              onClick={() => {\n                setMessages((current) => {\n                  const next = [...current]\n                  next.splice(last.index, 0, last.message)\n                  return next\n                })\n                setLast(null)\n              }}\n            >\n              Undo\n            </button>\n          </>\n        ) : (\n          <span className=\"text-muted-foreground\">\n            Swipe a message, or use its More actions button.\n          </span>\n        )}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}