{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "explorer-link",
  "title": "Explorer Link",
  "description": "Link to an address, transaction or block on a chain's block explorer, taken from chain.blockExplorers in the wagmi config (current chain by default, or chainId). Opens in a new tab with rel=noopener and a screen-reader note. Default text is 'View on <explorer>'. Renders plain text when the chain has no explorer. Exports useExplorerLink.",
  "dependencies": [
    "wagmi",
    "lucide-react"
  ],
  "registryDependencies": [
    "@0xui/0xui-utils"
  ],
  "files": [
    {
      "path": "registry/default/components/explorer-link.tsx",
      "content": "// Docs: https://0xui.io/components/explorer-link.md\nimport { ExternalLinkIcon } from \"lucide-react\";\nimport type { ComponentProps, ComponentType, ReactNode } from \"react\";\nimport { useChainId, useChains } from \"wagmi\";\nimport { getExplorerUrl, type ExplorerTarget } from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ExplorerLinkProps = Omit<ComponentProps<\"a\">, \"href\" | \"children\"> &\n  ExplorerTarget & {\n    /** Chain whose explorer to link to. Defaults to the current chain. */\n    chainId?: number;\n    /** Link text. Defaults to \"View on <explorer name>\". */\n    children?: ReactNode;\n    /** Custom external-link icon. Pass false to hide. */\n    icon?: ComponentType<{ className?: string }> | false;\n  };\n\n/** Resolve the explorer URL and name for an address, transaction or block. */\nexport function useExplorerLink(target: ExplorerTarget, chainId?: number) {\n  const currentChainId = useChainId();\n  const chains = useChains();\n  const chain = chains.find((c) => c.id === (chainId ?? currentChainId));\n  return {\n    href: getExplorerUrl(chain, target),\n    explorerName: chain?.blockExplorers?.default.name,\n  };\n}\n\n/**\n * Link to an address, transaction or block on the chain's block explorer.\n * Renders plain text when the chain has no explorer configured.\n */\nexport function ExplorerLink({\n  address,\n  tx,\n  block,\n  chainId,\n  children,\n  icon,\n  className,\n  ...props\n}: ExplorerLinkProps) {\n  const target = (\n    address ? { address } : tx ? { tx } : { block }\n  ) as ExplorerTarget;\n  const { href, explorerName } = useExplorerLink(target, chainId);\n  const Icon = icon === false ? null : (icon ?? ExternalLinkIcon);\n\n  if (!href) {\n    return <span className={className}>{children}</span>;\n  }\n\n  return (\n    <a\n      href={href}\n      target=\"_blank\"\n      rel=\"noopener noreferrer\"\n      className={cn(\n        \"inline-flex items-center gap-1 underline-offset-4 hover:underline\",\n        className\n      )}\n      {...props}\n    >\n      {children ?? `View on ${explorerName ?? \"explorer\"}`}\n      {Icon && <Icon aria-hidden className=\"size-3.5 shrink-0 opacity-70\" />}\n      <span className=\"sr-only\"> (opens in a new tab)</span>\n    </a>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/explorer-link.md",
  "categories": [
    "identity"
  ],
  "type": "registry:component"
}