{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "code-block",
  "title": "Code block",
  "description": "A named focusable pre with native scrolling, an optional language header and exact-value CopyButton. The command variant wraps naturally and places a configurable copy action beside the command.",
  "registryDependencies": [
    "@waimakers/utils",
    "@waimakers/theme",
    "@waimakers/copy-button"
  ],
  "files": [
    {
      "path": "src/components/ui/code-block.tsx",
      "content": "import type { ComponentProps } from \"react\";\nimport { cn, focusRing } from \"../../lib/utils\";\nimport { CopyButton, type CopyButtonProps } from \"./copy-button\";\n\ntype CodeBlockCopyProps = Pick<\n  CopyButtonProps,\n  \"children\" | \"variant\" | \"size\" | \"onCopied\" | \"onCopyFailed\" | \"aria-label\"\n>;\n\nfunction CodeBlock({\n  code,\n  label,\n  language,\n  copy = false,\n  variant = \"default\",\n  copyButtonProps,\n  className,\n  ...props\n}: Omit<ComponentProps<\"pre\">, \"children\"> & {\n  code: string;\n  label: string;\n  language?: string;\n  copy?: boolean;\n  variant?: \"default\" | \"command\";\n  copyButtonProps?: CodeBlockCopyProps;\n}) {\n  if (variant === \"command\") {\n    const hasCopyLabel = copyButtonProps?.children !== undefined;\n    return (\n      <div\n        data-slot=\"code-block\"\n        data-variant=\"command\"\n        className=\"group/code-block @container/command relative flex w-full min-w-0 flex-col gap-3 overflow-hidden rounded-md bg-muted p-3 text-sm\"\n      >\n        {language && <span className=\"text-xs text-muted-foreground\">{language}</span>}\n        <div\n          className={cn(\n            \"flex min-w-0 items-center gap-3\",\n            hasCopyLabel && \"flex-col items-stretch @lg/command:flex-row @lg/command:items-center\",\n          )}\n        >\n          <pre\n            data-slot=\"code-block-content\"\n            role=\"region\"\n            aria-label={label}\n            tabIndex={0}\n            className={cn(\n              \"max-h-80 w-full min-w-0 flex-1 overflow-auto rounded-md py-0.5 font-mono text-sm leading-relaxed whitespace-pre-wrap @lg/command:w-auto text-foreground [overflow-wrap:anywhere]\",\n              focusRing,\n              className,\n            )}\n            {...props}\n          >\n            <code data-slot=\"code-block-code\">\n              {code.split(/(\\s+)/u).map((part, index) =>\n                /^\\s*$/u.test(part) ? (\n                  part\n                ) : (\n                  <span\n                    key={index}\n                    className=\"inline-block max-w-full align-bottom [overflow-wrap:anywhere]\"\n                  >\n                    {part}\n                  </span>\n                ),\n              )}\n            </code>\n          </pre>\n          {copy && (\n            <div className={cn(\"shrink-0\", hasCopyLabel && \"self-start @lg/command:self-auto\")}>\n              <CodeBlockCopy code={code} label={label} buttonProps={copyButtonProps} />\n            </div>\n          )}\n        </div>\n      </div>\n    );\n  }\n  return (\n    <div\n      data-slot=\"code-block\"\n      className=\"group/code-block relative flex w-full min-w-0 flex-col overflow-hidden rounded-md bg-muted text-sm\"\n    >\n      <pre\n        data-slot=\"code-block-content\"\n        role=\"region\"\n        aria-label={label}\n        tabIndex={0}\n        className={cn(\n          \"max-h-80 overflow-auto rounded-md p-4 font-mono text-sm text-foreground\",\n          (copy || language) && \"pt-14\",\n          focusRing,\n          className,\n        )}\n        {...props}\n      >\n        <code data-slot=\"code-block-code\">{code}</code>\n      </pre>\n      {(language || copy) && (\n        <div\n          data-slot=\"code-block-header\"\n          className=\"absolute inset-x-0 top-0 flex h-12 items-center justify-between gap-4 rounded-t-md bg-muted px-4\"\n        >\n          <span className=\"text-xs text-muted-foreground\">{language}</span>\n          {copy && <CodeBlockCopy code={code} label={label} buttonProps={copyButtonProps} />}\n        </div>\n      )}\n    </div>\n  );\n}\nfunction CodeBlockCopy({\n  code,\n  label,\n  buttonProps,\n}: {\n  code: string;\n  label: string;\n  buttonProps?: CodeBlockCopyProps;\n}) {\n  return (\n    <CopyButton\n      value={code}\n      label={label}\n      variant=\"ghost\"\n      size=\"sm\"\n      className={buttonProps?.children === undefined ? \"size-9 p-0\" : undefined}\n      {...buttonProps}\n    />\n  );\n}\nexport { CodeBlock };\n",
      "type": "registry:ui",
      "target": "components/ui/code-block.tsx"
    }
  ],
  "type": "registry:ui"
}