Display
Code Block
A code block with copy: a long command wraps with a hanging indent instead of demanding horizontal scrolling.
- code
- copy
- install
- mono
Preview
1440pxHost theme
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/code-001?lang=en
npx shadcn@latest add https://vibeui.ru/r/button-001.jsonShow the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "code-001" (Code Block) 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/code-001.json
Registry item: https://vibeui.ru/r/code-001.json
Installs to: components/vibeui/code-001.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 code block with copy: a long command wraps with a hanging indent instead of demanding horizontal scrolling.
A dark code block: a heading with the language, a copy button that reports back and wrapping instead of scrolling. Zero dependencies, one file.
## 3. How to use it
import { Code001 } from "@/components/vibeui/code-001"
<Code001 title="Install" code="npx shadcn@latest add ..." />
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-code-001-* palette — do not swap it for your theme tokens
- wrapping long commands: horizontal scrolling hides half the line
- the hanging indent — it shows the line is a single one
- the copy report inside the button rather than a toast
- the monospaced face: dashes and dots matter in commands
- no syntax highlighting: a command does not need it and a library costs weight
## 6. You may change
- code, title and language
- the onCopy handler
- the block colours for your dark theme
- the block width
## 7. Rules
- navigator.clipboard needs a secure context: over http the button stays silent.
- For highlighted multi-line code use a dedicated library — this block is about commands.
- Line numbers are omitted: they get in the way of selecting and copying.
- 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/code-001.jsonhttps://vibeui.ru/r/code-001.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-code-001-*. Клиентский: "use client" ради копирования. Перенос строк сделан парой white-space: pre-wrap и overflow-wrap: anywhere, а продолжение сдвинуто отрицательным text-indent. Подсветки синтаксиса нет намеренно: она стоит библиотеки.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useEffect, useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"
export type Code001Props = Omit<
ComponentPropsWithoutRef<"figure">,
"children" | "title"
> & {
title?: string
code?: string
language?: string
onCopy?: () => void
}
// Идея компонента: блок кода с копированием и переносом длинных строк.
// Команда установки не должна требовать горизонтальной прокрутки: её читают
// целиком, поэтому строки переносятся с отступом продолжения. Подсветку
// синтаксиса компонент не делает — она стоит библиотеки, а команде не нужна.
const STYLES = `
:where([data-vibeui-block="code-001"]){
--vibeui-code-001-bg:oklch(0.22 0.02 265);
--vibeui-code-001-fg:oklch(0.94 0.006 265);
--vibeui-code-001-muted:oklch(0.72 0.014 265);
--vibeui-code-001-border:oklch(1 0 0 / 12%);
--vibeui-code-001-done:oklch(0.8 0.14 152);
--vibeui-code-001-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
--vibeui-code-001-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="code-001"]{
display:flex;flex-direction:column;
width:100%;max-width:26rem;box-sizing:border-box;margin:0;overflow:hidden;
border-radius:0.875rem;
background:var(--vibeui-code-001-bg);color:var(--vibeui-code-001-fg);
font-family:var(--vibeui-code-001-font);
}
[data-vibeui-block="code-001"] [data-part="head"]{
display:flex;align-items:center;justify-content:space-between;gap:0.75rem;
padding:0.5rem 0.5rem 0.5rem 0.875rem;
border-bottom:1px solid var(--vibeui-code-001-border);
font-size:0.75rem;color:var(--vibeui-code-001-muted);
}
[data-vibeui-block="code-001"] button{
appearance:none;border:0;cursor:pointer;
height:1.75rem;padding:0 0.625rem;border-radius:0.4375rem;
background:oklch(1 0 0 / 10%);color:var(--vibeui-code-001-fg);
font:inherit;font-size:0.75rem;font-weight:650;
}
[data-vibeui-block="code-001"] button:hover{background:oklch(1 0 0 / 16%)}
[data-vibeui-block="code-001"] button:focus-visible{outline:2px solid var(--vibeui-code-001-done);outline-offset:2px}
[data-vibeui-block="code-001"] button[data-done="true"]{color:var(--vibeui-code-001-done)}
/* Перенос с отступом продолжения: команду читают целиком, а не прокручивают. */
[data-vibeui-block="code-001"] pre{
margin:0;padding:0.875rem;
font-family:var(--vibeui-code-001-mono);font-size:0.8125rem;line-height:1.55;
white-space:pre-wrap;overflow-wrap:anywhere;
text-indent:-1.25rem;padding-left:2.125rem;
}
[data-vibeui-block="code-001"] code{font:inherit}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="code-001"] *{animation:none!important;transition:none!important}}
`
/**
* Блок кода с копированием: длинные команды переносятся, а не прокручиваются.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Code001({
title = "Установка",
code = "npx shadcn@latest add https://vibeui.ru/r/button-001.json",
language = "bash",
onCopy,
className,
style,
...props
}: Code001Props) {
const [done, setDone] = useState(false)
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
useEffect(
() => () => {
if (timer.current) clearTimeout(timer.current)
},
[],
)
const copy = async () => {
try {
await navigator.clipboard.writeText(code)
} catch {
// Буфер недоступен: молча выходим, ложное «скопировано» хуже молчания.
return
}
setDone(true)
onCopy?.()
if (timer.current) clearTimeout(timer.current)
timer.current = setTimeout(() => setDone(false), 2000)
}
return (
<>
<style href="vibeui-code-001" precedence="medium">
{STYLES}
</style>
<figure
{...props}
data-vibeui-block="code-001"
className={className}
style={style as CSSProperties}
>
<figcaption data-part="head">
<span>
{title} · {language}
</span>
<button type="button" data-done={done} onClick={copy}>
<span aria-live="polite">
{done ? "Скопировано" : "Копировать"}
</span>
</button>
</figcaption>
<pre>
<code>{code}</code>
</pre>
</figure>
</>
)
}