Code Block

Listing Outline

A long listing you can walk through: the outline of declarations on the left, scrollable code on the right, and the target row highlighted through :target.

  • code
  • outline
  • anchor
  • navigation

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/codeblock-019?lang=en

app/actions.ts15 строк
import { db } from '@/lib/db'export async function addToCart(id: string) {  await db.cart.add(id)}export async function removeFromCart(id: string) {  await db.cart.remove(id)}export async function clearCart() {  await db.cart.clear()}export const CART_LIMIT = 50
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "codeblock-019" (Listing Outline) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/codeblock-019.json

Registry item: https://vibeui.ru/r/codeblock-019.json
Installs to: components/vibeui/codeblock-019.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A long listing you can walk through: the outline of declarations on the left, scrollable code on the right, and the target row highlighted through :target.

A listing with an outline of declarations and anchor navigation: the target row lights up through :target. Zero dependencies, no client JS.

## 3. How to use it
import { Codeblock019 } from "@/components/vibeui/codeblock-019"

<Codeblock019
  path="app/actions.ts"
  maxHeight={14}
  idPrefix="actions"
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-codeblock-019-* palette — do not swap it for your theme tokens
- a unique idPrefix per block: identical ids wire the anchors of two listings together
- :target as the source of the highlight — state in the address gives a shareable link to a line
- tabIndex and role=region on the scroller: without them the code cannot be scrolled by keyboard
- scroll-margin on the rows: without it the target sits flush to the edge and reads as clipped
- the layout rules on the inner shell: a container query never applies to the container itself

## 6. You may change
- the listing rows through the lines array and the outline through the outline array
- the file path through path
- the height of the scroll area through maxHeight
- the anchor prefix through idPrefix

## 7. Rules
- Following an anchor changes the page address — the price of a shareable link to a line.
- prefers-reduced-motion drops the smooth scroll: the jump becomes instant, which is right.
- The outline is written by hand and can drift from the code: it never checks the line numbers.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/codeblock-019.json
https://vibeui.ru/r/codeblock-019.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-codeblock-019-*. Серверный: переходы — обычные якоря, состояние живёт в адресе страницы, поэтому ссылкой на строку можно поделиться. У строк есть id с префиксом из пропса idPrefix: два блока на странице с одинаковым префиксом сцепили бы якоря. Область кода прокручивается сама и получает tabIndex с role=region, иначе до неё не добраться с клавиатуры; scroll-margin отодвигает строку-цель от края. Раскладка считается от собственной ширины и лежит на внутреннем [data-part="shell"].

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { CSSProperties } from "react"

export type Codeblock019Mark = {
  line: number
  name: string
  kind: string
}

export type Codeblock019Props = {
  path?: string
  maxHeight?: number
  idPrefix?: string
  lines?: string[]
  outline?: Codeblock019Mark[]
  className?: string
  style?: CSSProperties
}

// Идея компонента: длинный файл, по которому можно ходить. Слева оглавление
// объявлений, справа прокручиваемый листинг; переходы — обычные якоря, поэтому
// работают без JS, а строка-цель подсвечивается через :target.
const STYLES = `
:where([data-vibeui-block="codeblock-019"]){
--vibeui-codeblock-019-bg:oklch(0.19 0.018 240);
--vibeui-codeblock-019-side:oklch(0.23 0.02 240);
--vibeui-codeblock-019-fg:oklch(0.93 0.008 240);
--vibeui-codeblock-019-muted:oklch(0.66 0.016 240);
--vibeui-codeblock-019-gutter:oklch(0.5 0.02 240);
--vibeui-codeblock-019-border:oklch(1 0 0 / 12%);
--vibeui-codeblock-019-accent:oklch(0.82 0.13 200);
--vibeui-codeblock-019-target:oklch(0.6 0.12 200 / 22%);
--vibeui-codeblock-019-height:14rem;
--vibeui-codeblock-019-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
--vibeui-codeblock-019-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
container-type:inline-size;
}
[data-vibeui-block="codeblock-019"]{
display:block;width:100%;max-width:38rem;box-sizing:border-box;margin:0;
overflow:hidden;border:1px solid var(--vibeui-codeblock-019-border);
border-radius:0.75rem;
background:var(--vibeui-codeblock-019-bg);color:var(--vibeui-codeblock-019-fg);
font-family:var(--vibeui-codeblock-019-font);
}
[data-vibeui-block="codeblock-019"] [data-part="shell"]{
display:grid;grid-template-columns:1fr;
}
[data-vibeui-block="codeblock-019"] [data-part="head"]{
display:flex;align-items:center;justify-content:space-between;
gap:0.75rem;padding:0.5rem 0.875rem;
background:var(--vibeui-codeblock-019-side);
border-bottom:1px solid var(--vibeui-codeblock-019-border);
font-family:var(--vibeui-codeblock-019-mono);font-size:0.75rem;
color:var(--vibeui-codeblock-019-muted);
}
[data-vibeui-block="codeblock-019"] nav{
background:var(--vibeui-codeblock-019-side);
border-bottom:1px solid var(--vibeui-codeblock-019-border);
}
[data-vibeui-block="codeblock-019"] ol{
margin:0;padding:0.375rem;list-style:none;
display:flex;flex-wrap:wrap;gap:0.125rem;
}
[data-vibeui-block="codeblock-019"] a{
display:flex;align-items:baseline;gap:0.375rem;
padding:0.25rem 0.5rem;border-radius:0.375rem;
color:var(--vibeui-codeblock-019-muted);text-decoration:none;
font-family:var(--vibeui-codeblock-019-mono);font-size:0.75rem;
transition:background-color .16s ease,color .16s ease;
}
[data-vibeui-block="codeblock-019"] a:hover{
background:oklch(1 0 0 / 8%);color:var(--vibeui-codeblock-019-fg);
}
[data-vibeui-block="codeblock-019"] a:focus-visible{
outline:2px solid var(--vibeui-codeblock-019-accent);outline-offset:2px;
}
[data-vibeui-block="codeblock-019"] [data-part="kind"]{
color:var(--vibeui-codeblock-019-accent);font-size:0.625rem;
text-transform:uppercase;letter-spacing:0.06em;
}
[data-vibeui-block="codeblock-019"] [data-part="at"]{
margin-inline-start:auto;color:var(--vibeui-codeblock-019-gutter);
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="codeblock-019"] [data-part="scroller"]{
max-height:var(--vibeui-codeblock-019-height);overflow:auto;
scroll-behavior:smooth;overscroll-behavior:contain;
}
[data-vibeui-block="codeblock-019"] [data-part="scroller"]:focus-visible{
outline:2px solid var(--vibeui-codeblock-019-accent);outline-offset:-2px;
}
[data-vibeui-block="codeblock-019"] pre{margin:0;padding:0.625rem 0}
[data-vibeui-block="codeblock-019"] code{
display:block;min-width:max-content;
font-family:var(--vibeui-codeblock-019-mono);
font-size:0.8125rem;line-height:1.7;white-space:pre;
counter-reset:line;
}
[data-vibeui-block="codeblock-019"] [data-part="row"]{
display:block;position:relative;padding:0 0.875rem 0 3rem;min-height:1.7em;
scroll-margin-top:0.625rem;
}
[data-vibeui-block="codeblock-019"] [data-part="row"]::before{
counter-increment:line;content:counter(line);
position:absolute;left:0;width:2.25rem;text-align:right;
color:var(--vibeui-codeblock-019-gutter);font-variant-numeric:tabular-nums;
user-select:none;-webkit-user-select:none;pointer-events:none;
}
/* Строка-цель подсвечивается штатным :target: состояние живёт в адресе,
   а не в JS, поэтому ссылкой на строку можно поделиться. */
[data-vibeui-block="codeblock-019"] [data-part="row"]:target{
background:var(--vibeui-codeblock-019-target);
box-shadow:inset 0.1875rem 0 0 var(--vibeui-codeblock-019-accent);
}
@container (min-width: 32rem){
[data-vibeui-block="codeblock-019"] [data-part="shell"]{grid-template-columns:12rem 1fr}
[data-vibeui-block="codeblock-019"] nav{
border-bottom:0;border-right:1px solid var(--vibeui-codeblock-019-border);
}
[data-vibeui-block="codeblock-019"] ol{flex-direction:column;flex-wrap:nowrap}
}
@media (prefers-reduced-motion:reduce){
[data-vibeui-block="codeblock-019"] *{animation:none!important;transition:none!important}
[data-vibeui-block="codeblock-019"] [data-part="scroller"]{scroll-behavior:auto}
}
`

const LINES = [
  "import { db } from '@/lib/db'",
  "",
  "export async function addToCart(id: string) {",
  "  await db.cart.add(id)",
  "}",
  "",
  "export async function removeFromCart(id: string) {",
  "  await db.cart.remove(id)",
  "}",
  "",
  "export async function clearCart() {",
  "  await db.cart.clear()",
  "}",
  "",
  "export const CART_LIMIT = 50",
]

const OUTLINE: Codeblock019Mark[] = [
  { line: 3, name: "addToCart", kind: "fn" },
  { line: 7, name: "removeFromCart", kind: "fn" },
  { line: 11, name: "clearCart", kind: "fn" },
  { line: 15, name: "CART_LIMIT", kind: "const" },
]

/** Длинный листинг с оглавлением объявлений и переходом по якорям. */
export function Codeblock019({
  path = "app/actions.ts",
  maxHeight = 14,
  idPrefix = "codeblock-019",
  lines = LINES,
  outline = OUTLINE,
  className,
  style,
}: Codeblock019Props) {
  const palette = {
    "--vibeui-codeblock-019-height": `${maxHeight}rem`,
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-codeblock-019" precedence="medium">
        {STYLES}
      </style>
      <figure
        data-vibeui-block="codeblock-019"
        className={className}
        style={palette}
      >
        <figcaption data-part="head">
          <span>{path}</span>
          <span>{lines.length} строк</span>
        </figcaption>
        <div data-part="shell">
          <nav aria-label="Оглавление листинга">
            <ol>
              {outline.map((mark) => (
                <li key={mark.name}>
                  <a href={`#${idPrefix}-line-${mark.line}`}>
                    <span data-part="kind">{mark.kind}</span>
                    {mark.name}
                    <span data-part="at">{mark.line}</span>
                  </a>
                </li>
              ))}
            </ol>
          </nav>
          <div
            data-part="scroller"
            tabIndex={0}
            role="region"
            aria-label={`Код файла ${path}`}
          >
            <pre>
              <code>
                {lines.map((line, index) => (
                  <span
                    key={index}
                    data-part="row"
                    id={`${idPrefix}-line-${index + 1}`}
                  >
                    {line}
                  </span>
                ))}
              </code>
            </pre>
          </div>
        </div>
      </figure>
    </>
  )
}