Skip to content
synccn

Code Block

New

Highlighted code with file tabs, copy and marked lines.

1import { Button } from "@/components/ui/button";2import { toast } from "@/components/ui/toast";34export default function App() {5  return (6    <Button onClick={() => toast.success("Saved")}>7      Save changes8    </Button>9  );10}

Installation

$ pnpm dlx shadcn@latest add @synccn/code-block

First time in this project? Connect synccn with one command.

Usage

import { CodeBlock } from "@/components/ui/code-block";<CodeBlock files={[{ name: "app.jsx", code, highlight: [3] }]} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

CodeBlock

Syntax-highlighted code with file tabs, copy, line numbers and highlighted lines. files: [{ name, code, highlight?: number[] }]. Uses the tiny sugar-high highlighter.

  • filesrequired
    CodeFile[]

    One tab per file.

  • lineNumbers
    boolean

    Default true

    Show line numbers.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

npm packages

Accessibility

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: tab, tablist
  • ARIA attributes: aria-label, aria-selected