Code block preview

Interactive preview of the CyberSpec Code block component. Highlighted code with line numbers, a filename tab and a copy key. No highlighting dependency.

About this preview

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.

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

Example

"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

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

Resources

View as Markdown