{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chain-badge",
  "title": "Chain Badge",
  "description": "Static chain chip: chain icon plus name for a chainId, with the name read from the wagmi config ('Chain <id>' for unknown chains). Icon-only mode keeps an accessible label. Also exports ChainIcon, the web3icons network logo, a skeleton (skullet) while it loads and a '?' for unknown chains, which other 0xui components reuse.",
  "dependencies": [
    "wagmi",
    "@web3icons/react",
    "skullet"
  ],
  "registryDependencies": [
    "avatar"
  ],
  "files": [
    {
      "path": "registry/default/components/chain-badge.tsx",
      "content": "// Docs: https://0xui.io/components/chain-badge.md\nimport { NetworkIcon } from \"@web3icons/react/dynamic\";\nimport { useEffect, useState, type ComponentProps, type ComponentType } from \"react\";\nimport { SkeletonBox } from \"skullet/react\";\nimport { useChains } from \"wagmi\";\nimport { Avatar, AvatarFallback } from \"@/components/ui/avatar\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ChainIconVariant = \"background\" | \"branded\" | \"mono\";\n\nexport type ChainIconProps = {\n  chainId: number;\n  className?: string;\n  /** Icon style. */\n  variant?: ChainIconVariant;\n  /** Icon color. Only applies when variant is \"mono\". */\n  monoColor?: string;\n};\n\n/** Chain logo from web3icons, with a \"?\" placeholder for unknown chains. */\nexport function ChainIcon({\n  chainId,\n  className,\n  variant = \"background\",\n  monoColor,\n}: ChainIconProps) {\n  return (\n    <NetworkIcon\n      key={chainId}\n      chainId={chainId}\n      variant={variant}\n      color={variant === \"mono\" ? monoColor : undefined}\n      className={cn(\"size-6 rounded-full\", className)}\n      fallback={<ChainIconFallback className={className} />}\n    />\n  );\n}\n\n/**\n * web3icons shows this both while an icon loads and when it has none. So it\n * starts as a skeleton and settles on the \"?\" only if no icon has turned up.\n */\nfunction ChainIconFallback({ className }: { className?: string }) {\n  const [settled, setSettled] = useState(false);\n  useEffect(() => {\n    const timer = setTimeout(() => setSettled(true), 800);\n    return () => clearTimeout(timer);\n  }, []);\n\n  return (\n    <Avatar className={cn(\"size-6\", className)}>\n      {settled ? (\n        <AvatarFallback className=\"text-xs\">?</AvatarFallback>\n      ) : (\n        <SkeletonBox width=\"100%\" height=\"100%\" radius=\"9999px\" />\n      )}\n    </Avatar>\n  );\n}\n\nexport type ChainBadgeProps = Omit<ComponentProps<\"span\">, \"children\"> & {\n  chainId: number;\n  /** Display name. Defaults to the chain's name in the wagmi config, or \"Chain <id>\". */\n  name?: string;\n  /** Hide the name visually. It stays available to screen readers and as a tooltip. */\n  iconOnly?: boolean;\n  /** Icon style. */\n  variant?: ChainIconVariant;\n  /** Custom chain icon. Pass false to hide. */\n  chainIcon?: ComponentType<ChainIconProps> | false;\n};\n\n/** Static chain chip: icon and name. For switching chains, use ChainSelector. */\nexport function ChainBadge({\n  chainId,\n  name,\n  iconOnly = false,\n  variant = \"background\",\n  chainIcon,\n  className,\n  ...props\n}: ChainBadgeProps) {\n  const chains = useChains();\n  const label =\n    name ?? chains.find((c) => c.id === chainId)?.name ?? `Chain ${chainId}`;\n  const Icon = chainIcon === false ? null : (chainIcon ?? ChainIcon);\n\n  return (\n    <span\n      title={iconOnly ? label : undefined}\n      className={cn(\n        \"inline-flex items-center gap-1.5 rounded-full border py-0.5 pr-2.5 pl-0.5 text-sm\",\n        iconOnly && \"p-0.5\",\n        !Icon && \"pl-2.5\",\n        className\n      )}\n      {...props}\n    >\n      {Icon && <Icon chainId={chainId} variant={variant} className=\"size-5\" />}\n      <span className={cn(iconOnly && \"sr-only\")}>{label}</span>\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/chain-badge.md",
  "categories": [
    "network"
  ],
  "type": "registry:component"
}