{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "quantity-button-demo",
  "title": "Quantity Button Demo",
  "description": "A worked example of Quantity Button: An Add button that becomes a stepper in the same footprint once there is something to count, and turns back when the last one is removed.",
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/quantity-button.json"
  ],
  "files": [
    {
      "path": "components/demos/quantity-button-demo.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { QuantityButton } from \"@/registry/default/quantity-button/quantity-button\"\n\nconst menu = [\n  {\n    id: \"margherita\",\n    name: \"Margherita pizza\",\n    note: \"Tomato, mozzarella, basil\",\n    price: 11,\n  },\n  {\n    id: \"dal\",\n    name: \"Dal makhani\",\n    note: \"Slow cooked black lentils\",\n    price: 9,\n  },\n  {\n    id: \"lemonade\",\n    name: \"Mint lemonade\",\n    note: \"Up to 4 per order\",\n    price: 3.5,\n    max: 4,\n  },\n]\n\nconst money = new Intl.NumberFormat(\"en-US\", {\n  style: \"currency\",\n  currency: \"USD\",\n})\n\nexport function QuantityButtonDemo() {\n  const [cart, setCart] = React.useState<Record<string, number>>({\n    dal: 2,\n  })\n\n  const total = menu.reduce(\n    (sum, item) => sum + (cart[item.id] ?? 0) * item.price,\n    0\n  )\n  const items = Object.values(cart).reduce((sum, count) => sum + count, 0)\n\n  return (\n    <div className=\"bg-background border-border w-full max-w-[26rem] rounded-[1.25rem] border p-2 shadow-sm\">\n      <ul className=\"divide-border divide-y\">\n        {menu.map((item) => (\n          <li key={item.id} className=\"flex items-center gap-3 p-3\">\n            <div className=\"min-w-0 flex-1\">\n              <p className=\"truncate text-sm font-medium\">{item.name}</p>\n              <p className=\"text-muted-foreground truncate text-xs\">\n                {money.format(item.price)} · {item.note}\n              </p>\n            </div>\n            <QuantityButton\n              label={item.name}\n              max={item.max}\n              value={cart[item.id] ?? 0}\n              onValueChange={async (count) => {\n                // Stands in for the request that updates the basket.\n                await new Promise((resolve) => setTimeout(resolve, 350))\n                setCart((current) => ({ ...current, [item.id]: count }))\n              }}\n            />\n          </li>\n        ))}\n      </ul>\n      <div className=\"bg-muted mt-1 flex items-center justify-between rounded-[0.9rem] px-4 py-3 text-sm\">\n        <span className=\"text-muted-foreground\">\n          {items === 1 ? \"1 item\" : `${items} items`}\n        </span>\n        <span className=\"font-semibold tabular-nums\">\n          {money.format(total)}\n        </span>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}