Code Block
Height Cap
A code block capped by height rather than by line count: the expansion animates, the cut is shown by a mask, and a hidden checkbox holds the state.
- code
- collapse
- height
- no-js
Preview
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/codeblock-025?lang=en
export type Plan = "free" | "pro" | "team"
const PRICE: Record<Plan, number> = {
free: 0,
pro: 1290,
team: 4900,
}
export function priceOf(plan: Plan, months = 1) {
const base = PRICE[plan] * months
if (months >= 12) {
return Math.round(base * 0.8)
}
return base
}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-025" (Height Cap) 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-025.json
Registry item: https://vibeui.ru/r/codeblock-025.json
Installs to: components/vibeui/codeblock-025.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 capped by height rather than by line count: the expansion animates, the cut is shown by a mask, and a hidden checkbox holds the state.
A code block with a height cap and an expand button: an animated max-height, a fade mask, state on a checkbox. Zero dependencies, no client JS.
## 3. How to use it
import { Codeblock025 } from "@/components/vibeui/codeblock-025"
<Codeblock025
path="lib/pricing.ts"
collapsedHeight={9}
expandedHeight={32}
/>
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-025-* palette — do not swap it for your theme tokens
- the checkbox as the source of state: with useState the block stops working before hydration
- the bottom mask only while collapsed: when open it hides real code
- the changing toggle caption: "Expand" and "Collapse" are different promises
- the focus ring on the label, or keyboard users cannot tell what is being expanded
- the dark surface of the block — light monospaced text is unreadable without it
## 6. You may change
- the block code through code
- the file path through path
- the collapsed height through collapsedHeight
- the expansion limit through expandedHeight
## 7. Rules
- The animation runs between two max-height values: on short code the expansion feels faster.
- An expandedHeight smaller than the content turns on scrolling inside the block — that is normal.
- The height is in rem and follows the page font size: in dense layouts pick it again.
- 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-025.jsonhttps://vibeui.ru/r/codeblock-025.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-codeblock-025-*. Серверный: состояние держит нативный checkbox, корневой селектор :has(input:checked) переводит область кода с высоты свёрнутого блока на предел раскрытия. Обе высоты приходят пропсами и уезжают в CSS-переменные, поэтому анимация max-height идёт между двумя известными значениями, а не до auto. Маска нижнего края включена только в свёрнутом виде, подпись переключателя меняется парой span, спрятанных через :has().
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 Codeblock025Props = {
path?: string
collapsedHeight?: number
expandedHeight?: number
code?: string
className?: string
style?: CSSProperties
}
// Идея компонента: длинный файл, ограниченный по высоте, а не по числу строк.
// Высоту держит max-height, состояние — скрытый чекбокс, поэтому раскрытие
// анимируется и работает без JS; обрыв показан маской, которая гаснет сама.
const STYLES = `
:where([data-vibeui-block="codeblock-025"]){
--vibeui-codeblock-025-bg:oklch(0.2 0.02 320);
--vibeui-codeblock-025-head:oklch(0.24 0.024 320);
--vibeui-codeblock-025-fg:oklch(0.93 0.008 320);
--vibeui-codeblock-025-muted:oklch(0.67 0.018 320);
--vibeui-codeblock-025-border:oklch(1 0 0 / 12%);
--vibeui-codeblock-025-accent:oklch(0.82 0.13 320);
--vibeui-codeblock-025-collapsed:9rem;
--vibeui-codeblock-025-expanded:32rem;
--vibeui-codeblock-025-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
--vibeui-codeblock-025-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="codeblock-025"]{
display:flex;flex-direction:column;
width:100%;max-width:32rem;box-sizing:border-box;margin:0;overflow:hidden;
border:1px solid var(--vibeui-codeblock-025-border);border-radius:0.75rem;
background:var(--vibeui-codeblock-025-bg);color:var(--vibeui-codeblock-025-fg);
font-family:var(--vibeui-codeblock-025-font);
}
[data-vibeui-block="codeblock-025"] [data-part="head"]{
padding:0.5rem 0.875rem;
background:var(--vibeui-codeblock-025-head);
border-bottom:1px solid var(--vibeui-codeblock-025-border);
font-family:var(--vibeui-codeblock-025-mono);font-size:0.75rem;
color:var(--vibeui-codeblock-025-muted);
}
[data-vibeui-block="codeblock-025"] [data-part="body"]{
max-height:var(--vibeui-codeblock-025-collapsed);overflow:hidden;
transition:max-height .32s cubic-bezier(.32,.72,0,1);
}
/* Пока блок свёрнут, низ гаснет: обрыв обязан читаться как «здесь ещё есть
код», иначе кнопка «развернуть» выглядит бессмысленной. */
[data-vibeui-block="codeblock-025"]:not(:has(input:checked)) [data-part="body"]{
mask-image:linear-gradient(to bottom,#000 60%,oklch(0 0 0 / 15%) 100%);
}
[data-vibeui-block="codeblock-025"]:has(input:checked) [data-part="body"]{
max-height:var(--vibeui-codeblock-025-expanded);overflow:auto;
}
[data-vibeui-block="codeblock-025"] pre{margin:0;padding:0.75rem 0.875rem}
[data-vibeui-block="codeblock-025"] code{
display:block;min-width:max-content;
font-family:var(--vibeui-codeblock-025-mono);
font-size:0.8125rem;line-height:1.65;white-space:pre;
}
[data-vibeui-block="codeblock-025"] label{
cursor:pointer;display:flex;align-items:center;justify-content:center;gap:0.375rem;
padding:0.5rem 0.875rem;
border-top:1px solid var(--vibeui-codeblock-025-border);
background:var(--vibeui-codeblock-025-head);
font-size:0.75rem;font-weight:650;color:var(--vibeui-codeblock-025-accent);
transition:background-color .16s ease;
}
[data-vibeui-block="codeblock-025"] label:hover{background:oklch(1 0 0 / 8%)}
[data-vibeui-block="codeblock-025"] label:has(input:focus-visible){
outline:2px solid var(--vibeui-codeblock-025-accent);outline-offset:-2px;
}
[data-vibeui-block="codeblock-025"] label::after{
content:"▾";transition:transform .2s ease;
}
[data-vibeui-block="codeblock-025"] input{
position:absolute;width:1px;height:1px;margin:-1px;padding:0;
border:0;clip-path:inset(50%);overflow:hidden;white-space:nowrap;
}
[data-vibeui-block="codeblock-025"] label:has(input:checked)::after{transform:rotate(180deg)}
[data-vibeui-block="codeblock-025"] label:has(input:checked) [data-part="more"]{display:none}
[data-vibeui-block="codeblock-025"] label:not(:has(input:checked)) [data-part="less"]{display:none}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="codeblock-025"] *{animation:none!important;transition:none!important}}
`
const CODE = `export type Plan = "free" | "pro" | "team"
const PRICE: Record<Plan, number> = {
free: 0,
pro: 1290,
team: 4900,
}
export function priceOf(plan: Plan, months = 1) {
const base = PRICE[plan] * months
if (months >= 12) {
return Math.round(base * 0.8)
}
return base
}`
/** Блок кода с ограничением высоты и кнопкой «развернуть». */
export function Codeblock025({
path = "lib/pricing.ts",
collapsedHeight = 9,
expandedHeight = 32,
code = CODE,
className,
style,
}: Codeblock025Props) {
const palette = {
"--vibeui-codeblock-025-collapsed": `${collapsedHeight}rem`,
"--vibeui-codeblock-025-expanded": `${expandedHeight}rem`,
...style,
} as CSSProperties
return (
<>
<style href="vibeui-codeblock-025" precedence="medium">
{STYLES}
</style>
<figure
data-vibeui-block="codeblock-025"
className={className}
style={palette}
>
<figcaption data-part="head">{path}</figcaption>
<div data-part="body">
<pre>
<code>{code}</code>
</pre>
</div>
<label>
<input type="checkbox" />
<span data-part="more">Развернуть</span>
<span data-part="less">Свернуть</span>
</label>
</figure>
</>
)
}