{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "files": [
    {
      "content": "\"use client\";\n\nimport { useInfiniteQuery } from \"@tanstack/react-query\";\nimport { Collection } from \"react-aria-components\";\nimport { Label } from \"~/registry/ui/label\";\nimport { Listbox } from \"~/registry/ui/list-box\";\nimport { Popover } from \"~/registry/ui/popover\";\nimport { Select } from \"~/registry/ui/select\";\nimport { Spinner } from \"~/registry/ui/spinner\";\n\nexport interface PokemonListResponse {\n  count: number;\n  next: string | null;\n  previous: string | null;\n  results: {\n    name: string;\n    url: string;\n  }[];\n}\n\nexport function SelectInfiniteScrollDemo() {\n  const query = useInfiniteQuery({\n    queryKey: [\"pokemons\"],\n    queryFn: async ({ pageParam, signal }) => {\n      const { limit, offset } = pageParam;\n      const res = await fetch(\n        `https://pokeapi.co/api/v2/pokemon?limit=${limit}&offset=${offset}`,\n        {\n          signal,\n        }\n      );\n      const data = (await res.json()) as PokemonListResponse;\n      return data;\n    },\n    initialPageParam: {\n      offset: 0,\n      limit: 40,\n    },\n    getNextPageParam: (lastPage, _allPages, lastPageParam) => {\n      if (lastPage.next) {\n        return {\n          offset: lastPageParam.offset + lastPageParam.limit,\n          limit: lastPageParam.limit,\n        };\n      }\n    },\n    getPreviousPageParam: (firstPage, _allPages, firstPageParam) => {\n      if (firstPage.previous) {\n        return {\n          offset: firstPageParam.offset - firstPageParam.limit,\n          limit: firstPageParam.limit,\n        };\n      }\n    },\n  });\n\n  const items = query.data?.pages.flatMap((page) => page.results) || [];\n\n  return (\n    <Select.Root aria-label=\"Pokémons\" placeholder=\"Select a Pokémon\">\n      <Label>Choose a Pokémon</Label>\n\n      <Select.Trigger className=\"w-45\">\n        <Select.Value className=\"capitalize\" />\n      </Select.Trigger>\n      <Popover.Content>\n        <Listbox.Root\n          renderEmptyState={() => (\n            <Listbox.Empty>\n              {query.isFetched ? (\n                \"No Pokémons found.\"\n              ) : (\n                <>\n                  <Spinner />\n                  <span className=\"sr-only\">Loading more...</span>\n                </>\n              )}\n            </Listbox.Empty>\n          )}\n        >\n          <Collection items={items}>\n            {(item) => (\n              <Listbox.Item className=\"capitalize\" id={item.name}>\n                {item.name}\n              </Listbox.Item>\n            )}\n          </Collection>\n          <Listbox.LoadMoreItem\n            isLoading={query.isFetchingNextPage}\n            onLoadMore={query.fetchNextPage}\n          >\n            <Spinner />\n            <span className=\"sr-only\">Loading more...</span>\n          </Listbox.LoadMoreItem>\n        </Listbox.Root>\n      </Popover.Content>\n    </Select.Root>\n  );\n}\n",
      "path": "src/registry/examples/select/select-infinite-scroll-demo.tsx",
      "type": "registry:example"
    }
  ],
  "name": "select-infinite-scroll-demo",
  "registryDependencies": [
    "@kanpeki/select",
    "@kanpeki/label",
    "@kanpeki/list-box",
    "@kanpeki/popover",
    "@kanpeki/spinner",
    "@tanstack/react-query"
  ],
  "type": "registry:example"
}