Documentation

Code

Syntax highlighting, file labels, expandable source, and copyable commands with package manager tabs.

tsxapp/welcome.tsx
import { Button } from "@/components/ui/button";

export default function Welcome() {
  return (
    <section className="space-y-6">
      <header>
        <h1>Make it your own</h1>
        <p>Components that live in your project.</p>
      </header>

      <Button>Get started</Button>
      <Button variant="outline">Learn more</Button>
    </section>
  );
}
bunx knot-ui add code

Installation

Initialize your project once, then add Code. The CLI copies the source and installs its dependencies.

bunx knot-ui initbunx knot-ui add code

Usage

tsxapp/page.tsx
import { Code } from "@/components/ui/code";

export default function Example() {
  return (
    <div className="space-y-5">
      <Code
        language="tsx"
        filename="app/page.tsx"
        code={'export default function Page() { return <h1>Hello</h1>; }'}
      />
      <Code language="bash" code="bunx knot-ui add button" />
    </div>
  );
}

Command tabs

Bun CLI commands automatically get npm, pnpm, and yarn alternatives. Supply a commands object when each package manager needs a specific command. Copying includes only the active command.

tsx
<Code
  language="bash"
  code="bunx knot-ui add code"
  commands={{
    bun: "bunx knot-ui add code",
    npm: "npx knot-ui add code",
    pnpm: "pnpm dlx knot-ui add code",
    yarn: "yarn dlx knot-ui add code",
  }}
/>

Props

Component properties
PropTypeDefaultDescription
codestringRequiredThe source or command text to display and copy.
languagestring"text"The syntax language. Supports TSX, JSX, TypeScript, JavaScript, Bash, JSON, HTML, and CSS.
filenamestring—An optional file path shown in the header.
commandsPartial<Record<"bun" | "npm" | "pnpm" | "yarn", string>>—Explicit commands for package manager tabs.
theme"dark" | "light""dark"The code panel color theme.
lineNumberbooleanfalseShows line numbers beside source code.
classNamestring—Additional classes for the container.

Source with more than twelve lines collapses into an expandable panel. Unknown languages display as plain text.