# Code block

Highlighted code with line numbers, a filename tab and a copy key. No highlighting dependency.

[View Code block on CyberSpec](https://www.cyberspec.dev/components/sidebar/code-block)

## Component

Code block belongs to the Data group in the CyberSpec catalog. It uses @ui-sdk/react/button.

## Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/code-block.json
```

## Example

```tsx
"use client"

import { CodeBlock } from "@/components/ui/code-block"

const snippet = `
import { Cyber } from "@/components/ui/cyber"
import { Meter } from "@/components/ui/meter"

// Heat at or past 85 trips the CRIT tag.
export function DeckStatus({ heat }: { heat: number }) {
  return (
    <Cyber accent={{ l: 0.66, c: 0.23, h: 24 }}>
      <Meter label="Deck memory" value={10} max={50} />
      <Meter label="Heat" value={heat} high={85} />
    </Cyber>
  )
}
`

export default function CodeBlockDemo() {
  return (
    <>
      <CodeBlock filename="deck-status.tsx" language="tsx" code={snippet} />
    </>
  )
}
```

## Install this example

```sh
bunx --bun shadcn@latest add https://www.cyberspec.dev/r/code-block-demo.json
```

## Resources

- [Interactive Code block preview](https://www.cyberspec.dev/preview/code-block)
- [Component catalog](https://www.cyberspec.dev/components.md)
- [Code block source code](https://github.com/agnelnieves/cyberspec/blob/main/registry/cyber/ui/code-block.tsx)
- [Shadcn registry item](https://www.cyberspec.dev/r/code-block.json)
