{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "block-number",
  "title": "Block Number",
  "description": "Live block indicator: status dot plus the latest block number, updated as blocks arrive (useBlockNumber with watch). Doubles as an RPC health check. A skeleton (skullet) stands in for the number while loading. data-phase is loading, live or error, and the dot turns red with 'RPC unavailable' when the RPC fails. Optional explorer link. Exports useLiveBlockNumber.",
  "dependencies": [
    "wagmi",
    "skullet"
  ],
  "registryDependencies": [
    "@0xui/explorer-link",
    "@0xui/morph-text"
  ],
  "files": [
    {
      "path": "registry/default/components/block-number.tsx",
      "content": "// Docs: https://0xui.io/components/block-number.md\nimport { SkeletonBox } from \"skullet/react\";\nimport { useBlockNumber } from \"wagmi\";\nimport { ExplorerLink } from \"@/components/explorer-link\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { cn } from \"@/lib/utils\";\n\nexport type BlockNumberPhase = \"loading\" | \"live\" | \"error\";\n\n/** SkeletonBox is a block by default. This one sits in a line of text. */\nconst inlineBox = { display: \"inline-block\", verticalAlign: \"middle\" } as const;\n\nexport type BlockNumberProps = {\n  /** Chain to watch. Defaults to the current chain. */\n  chainId?: number;\n  /** Keep updating as new blocks arrive. */\n  watch?: boolean;\n  /** Link the number to the block on the explorer. */\n  explorer?: boolean;\n  className?: string;\n};\n\n/** Latest block number and whether the RPC is reachable. */\nexport function useLiveBlockNumber({\n  chainId,\n  watch = true,\n}: Pick<BlockNumberProps, \"chainId\" | \"watch\"> = {}) {\n  const { data, isError, isPending } = useBlockNumber({ chainId, watch });\n  const phase: BlockNumberPhase = isError\n    ? \"error\"\n    : isPending\n      ? \"loading\"\n      : \"live\";\n  return { blockNumber: data, phase };\n}\n\n/**\n * Live block indicator: a status dot plus the latest block number. Doubles\n * as an RPC health check. The dot turns red when the RPC fails.\n */\nexport function BlockNumber({\n  chainId,\n  watch = true,\n  explorer = false,\n  className,\n}: BlockNumberProps) {\n  const { blockNumber, phase } = useLiveBlockNumber({ chainId, watch });\n  const formatted =\n    blockNumber === undefined ? undefined : blockNumber.toLocaleString();\n\n  return (\n    <span\n      data-slot=\"block-number\"\n      data-phase={phase}\n      className={cn(\n        \"inline-flex items-center gap-1.5 text-sm text-muted-foreground tabular-nums\",\n        className\n      )}\n    >\n      <span\n        aria-hidden\n        className={cn(\n          \"size-2 rounded-full\",\n          phase === \"live\" && \"bg-emerald-500\",\n          phase === \"live\" && watch && \"animate-pulse motion-reduce:animate-none\",\n          phase === \"loading\" && \"bg-muted-foreground/40\",\n          phase === \"error\" && \"bg-destructive\"\n        )}\n      />\n      {phase === \"error\" ? (\n        <span>RPC unavailable</span>\n      ) : formatted === undefined ? (\n        <span>\n          {/* About the width of \"21,000,000\". */}\n          <SkeletonBox width=\"10ch\" height=\"1em\" style={inlineBox} />\n          <span className=\"sr-only\">Loading block…</span>\n        </span>\n      ) : explorer ? (\n        <ExplorerLink block={blockNumber!} chainId={chainId} icon={false}>\n          <span className=\"sr-only\">Block </span>\n          <MorphText>{formatted}</MorphText>\n        </ExplorerLink>\n      ) : (\n        <span>\n          <span className=\"sr-only\">Block </span>\n          <MorphText>{formatted}</MorphText>\n        </span>\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/block-number.md",
  "categories": [
    "network"
  ],
  "type": "registry:component"
}