{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "code-block",
  "title": "Code Block",
  "description": "Code, terminal output, logs and diffs: header with title and actions, copy button, line numbers, wrapping, added/removed/highlighted lines, and a small size for tool output",
  "dependencies": [
    "lucide-react",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@boldkit/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/code-block.tsx",
      "content": "import * as React from 'react'\nimport { cva, type VariantProps } from 'class-variance-authority'\nimport { Check, Copy } from 'lucide-react'\nimport { cn } from '@/lib/utils'\n\n/*\n * CodeBlock — code, terminal output, logs and diffs. A bordered slab with a\n * hard shadow; `size=\"sm\"` drops to a 2px border and 2px shadow for tool\n * output nested inside a Trace.\n *\n * Highlighting is out of scope: pass plain text (split into numbered lines\n * when `lineNumbers` is on) or your own highlighter's markup.\n */\n\nconst codeBlockVariants = cva(\n  'group/code-block relative flex w-full min-w-0 flex-col overflow-hidden border-foreground bg-background text-foreground',\n  {\n    variants: {\n      variant: {\n        default: '',\n        destructive:\n          '[&_[data-slot=code-block-header]]:bg-destructive [&_[data-slot=code-block-header]]:text-destructive-foreground',\n      },\n      size: {\n        default: 'border-3 text-sm shadow-[4px_4px_0px_hsl(var(--shadow-color))]',\n        sm: 'border-2 text-xs shadow-[2px_2px_0px_hsl(var(--shadow-color))]',\n      },\n    },\n    defaultVariants: { variant: 'default', size: 'default' },\n  }\n)\n\nexport interface CodeBlockProps\n  extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof codeBlockVariants> {}\n\nconst CodeBlock = React.forwardRef<HTMLDivElement, CodeBlockProps>(\n  ({ className, variant = 'default', size = 'default', ...props }, ref) => (\n    <div\n      ref={ref}\n      data-slot=\"code-block\"\n      data-variant={variant}\n      data-size={size}\n      className={cn(codeBlockVariants({ variant, size }), className)}\n      {...props}\n    />\n  )\n)\nCodeBlock.displayName = 'CodeBlock'\n\nconst CodeBlockHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n  ({ className, ...props }, ref) => (\n    <div\n      ref={ref}\n      data-slot=\"code-block-header\"\n      className={cn(\n        'flex min-w-0 shrink-0 items-center gap-2 border-b-3 border-foreground bg-muted px-3 py-1.5 group-data-[size=sm]/code-block:border-b-2 group-data-[size=sm]/code-block:px-2 group-data-[size=sm]/code-block:py-1',\n        className\n      )}\n      {...props}\n    />\n  )\n)\nCodeBlockHeader.displayName = 'CodeBlockHeader'\n\nconst CodeBlockTitle = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n  ({ className, ...props }, ref) => (\n    <div\n      ref={ref}\n      data-slot=\"code-block-title\"\n      className={cn(\n        'flex min-w-0 items-center gap-2 truncate text-xs font-bold uppercase tracking-wider [&_svg]:size-3.5 [&_svg]:shrink-0',\n        className\n      )}\n      {...props}\n    />\n  )\n)\nCodeBlockTitle.displayName = 'CodeBlockTitle'\n\n/**\n * Inside a header: sits at the end of the row. Placed directly in the\n * CodeBlock: floats over the top-right corner and appears on hover/focus\n * (always visible on touch screens).\n */\nconst CodeBlockActions = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n  ({ className, ...props }, ref) => (\n    <div\n      ref={ref}\n      data-slot=\"code-block-actions\"\n      className={cn(\n        'ms-auto flex shrink-0 items-center gap-1.5',\n        '[[data-slot=code-block]>&]:absolute [[data-slot=code-block]>&]:right-2 [[data-slot=code-block]>&]:top-2 [[data-slot=code-block]>&]:z-10 [[data-slot=code-block]>&]:opacity-0 [[data-slot=code-block]>&]:transition-opacity [[data-slot=code-block]>&]:group-hover/code-block:opacity-100 [[data-slot=code-block]>&]:group-focus-within/code-block:opacity-100 [[data-slot=code-block]>&]:pointer-coarse:opacity-100',\n        className\n      )}\n      {...props}\n    />\n  )\n)\nCodeBlockActions.displayName = 'CodeBlockActions'\n\nexport interface CodeBlockCopyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  /** The text written to the clipboard. */\n  value: string\n}\n\nconst CodeBlockCopyButton = React.forwardRef<HTMLButtonElement, CodeBlockCopyButtonProps>(\n  ({ value, className, onClick, ...props }, ref) => {\n    const [copied, setCopied] = React.useState(false)\n\n    React.useEffect(() => {\n      if (!copied) return\n      const timeout = setTimeout(() => setCopied(false), 2000)\n      return () => clearTimeout(timeout)\n    }, [copied])\n\n    return (\n      <>\n        <button\n          ref={ref}\n          type=\"button\"\n          data-slot=\"code-block-copy-button\"\n          data-copied={copied || undefined}\n          aria-label={copied ? 'Copied' : 'Copy code'}\n          className={cn(\n            'inline-flex size-7 shrink-0 items-center justify-center border-2 border-foreground bg-background text-foreground shadow-[2px_2px_0px_hsl(var(--shadow-color))] bk-interactive hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none active:translate-x-[2px] active:translate-y-[2px] active:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 data-[copied]:bg-success data-[copied]:text-success-foreground [&_svg]:size-3.5',\n            className\n          )}\n          onClick={(event) => {\n            onClick?.(event)\n            if (event.defaultPrevented || !navigator.clipboard) return\n            navigator.clipboard\n              .writeText(value)\n              .then(() => setCopied(true))\n              .catch(() => {})\n          }}\n          {...props}\n        >\n          {copied ? (\n            <Check key=\"check\" aria-hidden=\"true\" className=\"animate-pop\" strokeWidth={3} />\n          ) : (\n            <Copy key=\"copy\" aria-hidden=\"true\" strokeWidth={2.5} />\n          )}\n        </button>\n        <span aria-live=\"polite\" className=\"sr-only\">\n          {copied ? 'Copied' : ''}\n        </span>\n      </>\n    )\n  }\n)\nCodeBlockCopyButton.displayName = 'CodeBlockCopyButton'\n\nexport interface CodeBlockContentProps extends React.HTMLAttributes<HTMLPreElement> {\n  /** Wrap long lines instead of scrolling horizontally. */\n  wrap?: boolean\n  /** Number each line. A string child is split into lines for you. */\n  lineNumbers?: boolean\n  /** Number of the first line. */\n  startLine?: number\n}\n\nconst CodeBlockContent = React.forwardRef<HTMLPreElement, CodeBlockContentProps>(\n  (\n    { className, children, style, wrap = false, lineNumbers = false, startLine = 1, ...props },\n    ref\n  ) => (\n    <pre\n      ref={ref}\n      data-slot=\"code-block-content\"\n      data-wrap={wrap || undefined}\n      data-numbered={lineNumbers || undefined}\n      dir=\"ltr\"\n      tabIndex={0}\n      style={{ counterReset: `line ${startLine - 1}`, ...style }}\n      className={cn(\n        'bk-scrollbar min-h-0 min-w-0 overflow-auto p-4 text-start font-mono leading-relaxed outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring group-data-[size=sm]/code-block:p-2.5 data-[wrap]:whitespace-pre-wrap data-[wrap]:break-words',\n        className\n      )}\n      {...props}\n    >\n      <code\n        data-slot=\"code-block-code\"\n        className=\"grid min-w-max content-start [[data-numbered]>&]:grid-cols-[auto_1fr] [[data-wrap]>&]:min-w-0\"\n      >\n        {lineNumbers && typeof children === 'string'\n          ? children\n              .replace(/\\n$/, '')\n              .split('\\n')\n              .map((line, index) => <CodeBlockLine key={index}>{line}</CodeBlockLine>)\n          : children}\n      </code>\n    </pre>\n  )\n)\nCodeBlockContent.displayName = 'CodeBlockContent'\n\nconst codeBlockLineVariants = cva(\n  // The negative margin + padding lets the diff bar and tint run edge to edge.\n  'relative -mx-4 block border-l-4 border-transparent px-4 group-data-[size=sm]/code-block:-mx-2.5 group-data-[size=sm]/code-block:px-2.5 [[data-numbered]_&]:col-span-2 [[data-numbered]_&]:grid [[data-numbered]_&]:grid-cols-subgrid [[data-numbered]_&]:[counter-increment:line] [[data-numbered]_&]:before:mr-4 [[data-numbered]_&]:before:select-none [[data-numbered]_&]:before:text-right [[data-numbered]_&]:before:font-bold [[data-numbered]_&]:before:text-muted-foreground [[data-numbered]_&]:before:content-[counter(line)]',\n  {\n    variants: {\n      variant: {\n        default: '',\n        added: 'border-success bg-success/20',\n        removed: 'border-destructive bg-destructive/15',\n        highlighted: 'border-accent bg-accent/25',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  }\n)\n\nexport interface CodeBlockLineProps\n  extends React.HTMLAttributes<HTMLSpanElement>, VariantProps<typeof codeBlockLineVariants> {}\n\nconst CodeBlockLine = React.forwardRef<HTMLSpanElement, CodeBlockLineProps>(\n  ({ className, variant = 'default', children, ...props }, ref) => {\n    // An empty line holds a newline so a copied selection keeps blank lines.\n    const empty =\n      children === undefined ||\n      children === null ||\n      children === '' ||\n      (Array.isArray(children) && children.length === 0)\n\n    return (\n      <span\n        ref={ref}\n        data-slot=\"code-block-line\"\n        data-variant={variant}\n        className={cn(codeBlockLineVariants({ variant }), className)}\n        {...props}\n      >\n        {(variant === 'added' || variant === 'removed') && (\n          <span className=\"sr-only select-none\">\n            {variant === 'added' ? 'Added: ' : 'Removed: '}\n          </span>\n        )}\n        <span data-slot=\"code-block-line-content\" className=\"min-w-0\">\n          {empty ? '\\n' : children}\n        </span>\n      </span>\n    )\n  }\n)\nCodeBlockLine.displayName = 'CodeBlockLine'\n\nconst CodeBlockFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n  ({ className, ...props }, ref) => (\n    <div\n      ref={ref}\n      data-slot=\"code-block-footer\"\n      className={cn(\n        'flex min-w-0 shrink-0 items-center gap-2 border-t-3 border-foreground bg-muted px-3 py-1.5 text-xs font-bold uppercase tracking-wider group-data-[size=sm]/code-block:border-t-2',\n        className\n      )}\n      {...props}\n    />\n  )\n)\nCodeBlockFooter.displayName = 'CodeBlockFooter'\n\nexport {\n  CodeBlock,\n  CodeBlockHeader,\n  CodeBlockTitle,\n  CodeBlockActions,\n  CodeBlockCopyButton,\n  CodeBlockContent,\n  CodeBlockLine,\n  CodeBlockFooter,\n}\n",
      "type": "registry:ui",
      "target": "components/ui/code-block.tsx"
    }
  ],
  "type": "registry:ui"
}