{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs-lazy-panels",
  "title": "Tabs Lazy Panels",
  "description": "Tabs that render a panel only when its tab is first opened and then keep it mounted, so input and scroll survive tab trips, or throw it away when keepAlive is off.",
  "registryDependencies": [
    "tabs"
  ],
  "files": [
    {
      "path": "registry/patterns/tabs-lazy-panels/tabs-lazy-panels.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from \"@/components/ui/tabs\"\n\nexport interface LazyTab {\n  value: string\n  label: string\n  /** Rendered only after the tab has been opened once. */\n  render: () => React.ReactNode\n}\n\nexport interface TabsLazyPanelsProps {\n  tabs: LazyTab[]\n  /** Keep a panel mounted (hidden) after it has been visited. Default true. */\n  keepAlive?: boolean\n}\n\n/**\n * Tabs that do no work for panels nobody opens. A panel's content is created\n * the first time its tab is selected; with `keepAlive` (the default) it then\n * stays mounted so scroll position, form input and fetched data survive a trip\n * to another tab, and without it the panel is thrown away when left.\n */\nexport function TabsLazyPanels({\n  tabs,\n  keepAlive = true,\n}: TabsLazyPanelsProps) {\n  const [active, setActive] = React.useState(tabs[0]?.value)\n  const [visited, setVisited] = React.useState<string[]>(\n    tabs[0] ? [tabs[0].value] : []\n  )\n\n  return (\n    <Tabs\n      value={active}\n      onValueChange={(next) => {\n        setActive(next)\n        setVisited((all) => (all.includes(next) ? all : [...all, next]))\n      }}\n    >\n      <TabsList>\n        {tabs.map((t) => (\n          <TabsTrigger key={t.value} value={t.value}>\n            {t.label}\n          </TabsTrigger>\n        ))}\n      </TabsList>\n      {tabs.map((t) => (\n        <TabsContent\n          key={t.value}\n          value={t.value}\n          forceMount={keepAlive && visited.includes(t.value) ? true : undefined}\n          hidden={active !== t.value}\n        >\n          {visited.includes(t.value) && (keepAlive || active === t.value)\n            ? t.render()\n            : null}\n        </TabsContent>\n      ))}\n    </Tabs>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}