Rendyn

Component library

189 components

Product blocks

Code Block

Kibo Code Block renders supplied file data and optional controlled file selection.

Interactive exampleReact Tailwind CSS

Practical React example

Present a small set of source files with a file selector and a clear copy action.

Before you copy and paste

Use the composed primitives together under their required provider, where one is present. Copy components/kibo-ui/code-block/index.tsx and its returned support files from the Code tab; preserve the project-relative paths. Install the listed primitives: pnpm dlx shadcn@latest add button select.

Listed package dependencies: @radix-ui/react-use-controllable-state, @shikijs/transformers, lucide-react, react-icons, shiki.

Use the Code tab for the component files and installation instructions, then adapt the imports in this example to your project.

Present a small set of source files with a file selector and a clear copy action

// Usage adapted from Kibo UI's pinned MIT source.
// Copyright (c) 2023 — Present shadcnblocks. See ./LICENSES.md.
"use client";

import type { BundledLanguage } from "@/components/kibo-ui/code-block";
import {
  CodeBlock,
  CodeBlockBody,
  CodeBlockContent,
  CodeBlockCopyButton,
  CodeBlockFilename,
  CodeBlockFiles,
  CodeBlockHeader,
  CodeBlockItem,
  CodeBlockSelect,
  CodeBlockSelectContent,
  CodeBlockSelectItem,
  CodeBlockSelectTrigger,
  CodeBlockSelectValue,
} from "@/components/kibo-ui/code-block";

const code = [
  {
    language: "jsx",
    filename: "MyComponent.jsx",
    code: `function MyComponent(props) {
  return (
    <div>
      <h1>Hello, {props.name}!</h1>
      <p>This is an example React component.</p>
    </div>
  );
}`,
  },
  {
    language: "tsx",
    filename: "MyComponent.tsx",
    code: `function MyComponent(props: { name: string }) {
  return (
    <div>
      <h1>Hello, {props.name}!</h1>
      <p>This is an example React component.</p>
    </div>
  );
}`,
  },
];

const Example = () => (
  <CodeBlock data={code} defaultValue={code[0].language}>
    <CodeBlockHeader>
      <CodeBlockFiles>
        {(item) => (
          <CodeBlockFilename key={item.language} value={item.language}>
            {item.filename}
          </CodeBlockFilename>
        )}
      </CodeBlockFiles>
      <CodeBlockSelect>
        <CodeBlockSelectTrigger>
          <CodeBlockSelectValue />
        </CodeBlockSelectTrigger>
        <CodeBlockSelectContent>
          {(item) => (
            <CodeBlockSelectItem key={item.language} value={item.language}>
              {item.language}
            </CodeBlockSelectItem>
          )}
        </CodeBlockSelectContent>
      </CodeBlockSelect>
      <CodeBlockCopyButton
        onCopy={() => console.log("Copied code to clipboard")}
        onError={() => console.error("Failed to copy code to clipboard")}
      />
    </CodeBlockHeader>
    <CodeBlockBody>
      {(item) => (
        <CodeBlockItem key={item.language} value={item.language}>
          <CodeBlockContent language={item.language as BundledLanguage}>
            {item.code}
          </CodeBlockContent>
        </CodeBlockItem>
      )}
    </CodeBlockBody>
  </CodeBlock>
);

export default Example;

Usage example adapted from Kibo UI's pinned MIT source. Retain the source licence notices when copying.

Give each file a stable identifier and language, and keep the selected file value valid when data changes. Provide only source text that can safely be exposed to the viewer.

Customization

CodeBlockProps.defaultValue
Optional; string.
CodeBlockProps.value
Optional; string.
CodeBlockProps.onValueChange
Optional; (value: string) => void.
CodeBlockProps.data
Required; CodeBlockData[].
CodeBlockFilesProps.children
Required; (item: CodeBlockData) => ReactNode.
CodeBlockFilenameProps.icon
Optional; IconType.
CodeBlockFilenameProps.value
Optional; string.
CodeBlockSelectContentProps.children
Required; (item: CodeBlockData) => ReactNode.
CodeBlockCopyButtonProps.onCopy
Optional; () => void.
CodeBlockCopyButtonProps.onError
Optional; (error: Error) => void.
CodeBlockCopyButtonProps.timeout
Optional; number.
CodeBlockBodyProps.children
Required; (item: CodeBlockData) => ReactNode.
CodeBlockItemProps.value
Required; string.
CodeBlockItemProps.lineNumbers
Optional; boolean.

Integration notes

  • The code viewer does not execute or validate the shown code.
  • Check clipboard failures, long lines and the relationship between selected file and copied text.

Component source: Kibo UI documentation . These examples describe the version imported into Rendyn. Upstream APIs may have changed; retain the source licence notices when adapting the code.

Better with your agent

Give your agent taste.

The best way to use Rendyn is through MCP. Let your agent find the right component, compare previews and bring the source into your project.

All components are free. Sign up only to connect MCP.

Connect to MCP