Navigation
Clipboard Menu
A clipboard context menu with real state: paste is disabled while the buffer is empty, a cut card disappears and comes back on paste.
- contextmenu
- clipboard
- state
- board
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/contextmenu-004?lang=en
Board
- Бриф клиента
- Сценарий ролика
- Смета на съёмку
Буфер:пуст
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 "contextmenu-004" (Clipboard Menu) 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/contextmenu-004.json
Registry item: https://vibeui.ru/r/contextmenu-004.json
Installs to: components/vibeui/contextmenu-004.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 clipboard context menu with real state: paste is disabled while the buffer is empty, a cut card disappears and comes back on paste.
A cut-copy-paste context menu whose buffer state is real: an empty buffer greys out paste, cutting removes the card. One file, zero dependencies.
## 3. How to use it
import { Contextmenu004 } from "@/components/vibeui/contextmenu-004"
<Contextmenu004
title="Board"
cards={["Client brief", "Budget"]}
/>
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-contextmenu-004-* palette: the component must look the same in any project
- disabling paste on an empty buffer — an entry that silently does nothing reads as a bug
- keeping the disabled entry visible: hiding it changes the menu height and explains nothing
- the buffer line with role=status: otherwise a cut card is only noticed by its absence
- pasting relative to the target of the call — paste without a destination means nothing
- the component's own light surface: on the dark catalog card dark text disappears
## 6. You may change
- the board heading through title
- the cards through cards
- the marker and focus colour through accent
- the entry captions and shortcuts directly in the markup
## 7. Rules
- This is the component's own buffer, not the system one: reach for navigator.clipboard to use the real thing.
- aria-disabled does not block the click: the guard in the handler is required, and it is there.
- A copy gets a "— copy" suffix: in production the name should come from the server or duplicates pile up.
- 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/contextmenu-004.jsonhttps://vibeui.ru/r/contextmenu-004.jsonОдин файл, ноль зависимостей, палитра --vibeui-contextmenu-004-*. Клиентский: список карточек, содержимое буфера и текущая цель живут в useState. Меню — HTML popover у курсора через переменные x/y, вызывается правым кликом и кнопкой на карточке. Пункт «вставить» помечен aria-disabled при пустом буфере и остаётся видимым: спрятанный пункт не объясняет, почему действие недоступно. Вставка кладёт копию сразу после карточки, на которой вызвали меню, — буфер без места назначения бессмысленен. Содержимое буфера показано строкой с role=status под списком.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties, MouseEvent } from "react"
export type Contextmenu004Props = Omit<
ComponentPropsWithoutRef<"section">,
"children" | "title"
> & {
title?: string
cards?: string[]
accent?: string
}
// Идея компонента: контекстное меню буфера обмена, где «вставить» действительно
// выключено, пока копировать нечего. Пункт без состояния врёт: пользователь
// жмёт «вставить», ничего не происходит, и он винит себя. Здесь буфер живёт в
// состоянии компонента, его содержимое написано в шапке меню, а вырезанная
// карточка исчезает из списка — вставка возвращает её на новое место.
const STYLES = `
:where([data-vibeui-block="contextmenu-004"]){
--vibeui-contextmenu-004-bg:oklch(1 0 0);
--vibeui-contextmenu-004-fg:oklch(0.24 0.014 265);
--vibeui-contextmenu-004-muted:oklch(0.55 0.014 265);
--vibeui-contextmenu-004-border:oklch(0.9 0.006 265);
--vibeui-contextmenu-004-hover:oklch(0.96 0.004 265);
--vibeui-contextmenu-004-accent:oklch(0.58 0.17 300);
--vibeui-contextmenu-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-contextmenu-004-x:50%;
--vibeui-contextmenu-004-y:50%;
}
[data-vibeui-block="contextmenu-004"]{
display:flex;flex-direction:column;gap:0.5rem;
width:100%;max-width:21rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-contextmenu-004-bg);color:var(--vibeui-contextmenu-004-fg);
border:1px solid var(--vibeui-contextmenu-004-border);border-radius:1rem;
font-family:var(--vibeui-contextmenu-004-font);
}
[data-vibeui-block="contextmenu-004"] [data-part="title"]{margin:0;font-size:0.875rem;font-weight:650}
[data-vibeui-block="contextmenu-004"] [data-part="list"]{
display:flex;flex-direction:column;gap:0.375rem;margin:0;padding:0;list-style:none;
}
[data-vibeui-block="contextmenu-004"] [data-part="card"]{
display:flex;align-items:center;gap:0.5rem;
padding:0.5rem 0.625rem;box-sizing:border-box;
border:1px solid var(--vibeui-contextmenu-004-border);border-radius:0.625rem;
font-size:0.8125rem;touch-action:manipulation;
transition:border-color .14s ease;
}
[data-vibeui-block="contextmenu-004"] [data-part="card"][data-active="true"]{border-color:var(--vibeui-contextmenu-004-accent)}
[data-vibeui-block="contextmenu-004"] [data-part="grip"]{
flex:none;width:0.375rem;height:1rem;border-radius:9999px;
background:color-mix(in oklab,var(--vibeui-contextmenu-004-accent) 45%,transparent);
}
[data-vibeui-block="contextmenu-004"] [data-part="menu-button"]{
appearance:none;cursor:pointer;margin-left:auto;flex:none;
height:1.5rem;padding:0 0.4375rem;
border:1px solid var(--vibeui-contextmenu-004-border);border-radius:0.4375rem;
background:none;color:var(--vibeui-contextmenu-004-muted);font:inherit;font-size:0.6875rem;
}
[data-vibeui-block="contextmenu-004"] [data-part="menu-button"]:hover{background:var(--vibeui-contextmenu-004-hover)}
[data-vibeui-block="contextmenu-004"] [data-part="menu-button"]:focus-visible{outline:2px solid var(--vibeui-contextmenu-004-accent);outline-offset:1px}
[data-vibeui-block="contextmenu-004"] [data-part="buffer"]{
display:flex;align-items:center;gap:0.375rem;
margin:0;font-size:0.6875rem;color:var(--vibeui-contextmenu-004-muted);
}
[data-vibeui-block="contextmenu-004"] [data-part="chip"]{
padding:0.125rem 0.4375rem;border-radius:9999px;
background:var(--vibeui-contextmenu-004-hover);color:var(--vibeui-contextmenu-004-fg);
font-weight:600;
}
[data-vibeui-block="contextmenu-004"] [data-part="menu"]{
position:fixed;margin:0;padding:0.3125rem;
top:var(--vibeui-contextmenu-004-y);left:var(--vibeui-contextmenu-004-x);
min-width:12.5rem;box-sizing:border-box;
background:var(--vibeui-contextmenu-004-bg);color:var(--vibeui-contextmenu-004-fg);
border:1px solid var(--vibeui-contextmenu-004-border);border-radius:0.75rem;
box-shadow:0 18px 40px -20px oklch(0.2 0.03 265 / 50%);
font-family:var(--vibeui-contextmenu-004-font);
}
[data-vibeui-block="contextmenu-004"] [data-part="head"]{
padding:0.375rem 0.5rem 0.3125rem;margin-bottom:0.25rem;
border-bottom:1px solid var(--vibeui-contextmenu-004-border);
font-size:0.6875rem;color:var(--vibeui-contextmenu-004-muted);
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="contextmenu-004"] [data-part="item"]{
display:flex;align-items:center;justify-content:space-between;gap:1.25rem;
width:100%;box-sizing:border-box;
appearance:none;border:0;background:none;cursor:pointer;
padding:0.4375rem 0.5rem;border-radius:0.5rem;
font:inherit;font-size:0.8125rem;color:inherit;text-align:left;
transition:background-color .14s ease;
}
[data-vibeui-block="contextmenu-004"] [data-part="item"]:hover{background:var(--vibeui-contextmenu-004-hover)}
[data-vibeui-block="contextmenu-004"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-contextmenu-004-accent);outline-offset:-2px}
/* Выключенный пункт остаётся видимым и фокусируемым: он объясняет, почему нельзя. */
[data-vibeui-block="contextmenu-004"] [data-part="item"][aria-disabled="true"]{
color:var(--vibeui-contextmenu-004-muted);cursor:not-allowed;
}
[data-vibeui-block="contextmenu-004"] [data-part="item"][aria-disabled="true"]:hover{background:none}
[data-vibeui-block="contextmenu-004"] [data-part="keys"]{font-size:0.6875rem;color:var(--vibeui-contextmenu-004-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="contextmenu-004"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_CARDS = ["Бриф клиента", "Сценарий ролика", "Смета на съёмку"]
/**
* Контекстное меню буфера обмена: вырезать, копировать и вставить с состоянием.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Contextmenu004({
title = "Доска",
cards = DEFAULT_CARDS,
accent,
className,
style,
...props
}: Contextmenu004Props) {
const menu = useRef<HTMLDivElement>(null)
const [list, setList] = useState(cards)
const [buffer, setBuffer] = useState<string | null>(null)
const [target, setTarget] = useState<string | null>(null)
const [spot, setSpot] = useState<{ x: string; y: string } | null>(null)
const openAt = (x: number, y: number, card: string) => {
setTarget(card)
setSpot({ x: `${Math.round(x)}px`, y: `${Math.round(y)}px` })
menu.current?.showPopover()
requestAnimationFrame(() =>
menu.current?.querySelector<HTMLElement>('[data-part="item"]')?.focus(),
)
}
const close = () => menu.current?.hidePopover()
const cut = () => {
if (target) {
setBuffer(target)
setList((current) => current.filter((card) => card !== target))
}
close()
}
const copy = () => {
setBuffer(target)
close()
}
const paste = () => {
if (!buffer || !target) {
return
}
setList((current) => {
const at = current.indexOf(target)
const next = [...current]
next.splice(at + 1, 0, `${buffer} — копия`)
return next
})
close()
}
const palette = {
...(accent ? { "--vibeui-contextmenu-004-accent": accent } : null),
...(spot
? {
"--vibeui-contextmenu-004-x": spot.x,
"--vibeui-contextmenu-004-y": spot.y,
}
: null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-contextmenu-004" precedence="medium">
{STYLES}
</style>
<section
{...props}
data-vibeui-block="contextmenu-004"
aria-label={title}
className={className}
style={palette}
>
<h3 data-part="title">{title}</h3>
<ul data-part="list">
{list.map((card) => (
<li
key={card}
data-part="card"
data-active={target === card || undefined}
onContextMenu={(event: MouseEvent<HTMLLIElement>) => {
event.preventDefault()
openAt(event.clientX, event.clientY, card)
}}
>
<span data-part="grip" aria-hidden="true" />
{card}
<button
type="button"
data-part="menu-button"
aria-haspopup="menu"
aria-label={`Меню: ${card}`}
onClick={(event) => {
const box = event.currentTarget.getBoundingClientRect()
openAt(box.left, box.bottom + 4, card)
}}
>
меню
</button>
</li>
))}
</ul>
<p data-part="buffer" role="status">
Буфер:
<span data-part="chip">{buffer ?? "пуст"}</span>
</p>
<div
ref={menu}
data-part="menu"
popover="auto"
role="menu"
aria-label={target ? `Правка: ${target}` : "Правка"}
onKeyDown={(event) => {
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") {
return
}
event.preventDefault()
const items = Array.from(
menu.current?.querySelectorAll<HTMLElement>(
'[data-part="item"]',
) ?? [],
)
if (items.length === 0) {
return
}
const delta = event.key === "ArrowDown" ? 1 : -1
const from = items.indexOf(document.activeElement as HTMLElement)
items[(from + delta + items.length) % items.length].focus()
}}
>
<div data-part="head">{target}</div>
<button type="button" role="menuitem" data-part="item" onClick={cut}>
Вырезать
<span data-part="keys">⌘X</span>
</button>
<button type="button" role="menuitem" data-part="item" onClick={copy}>
Копировать
<span data-part="keys">⌘C</span>
</button>
<button
type="button"
role="menuitem"
data-part="item"
aria-disabled={buffer === null}
onClick={paste}
>
Вставить
<span data-part="keys">
{buffer === null ? "буфер пуст" : "⌘V"}
</span>
</button>
</div>
</section>
</>
)
}