Menu
Context Menu
A right-click menu: it appears where you clicked and closes on selection, Escape or when the pointer leaves.
- menu
- context
- right-click
- desktop
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/menu-002?lang=en
Файл «Каталог.fig»Right-click inside the area
Действие не выбрано
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 "menu-002" (Context 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/menu-002.json
Registry item: https://vibeui.ru/r/menu-002.json
Installs to: components/vibeui/menu-002.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 right-click menu: it appears where you clicked and closes on selection, Escape or when the pointer leaves.
A context menu on right click: it opens at the cursor, closes on selection, Escape and mouse-out, and reports the chosen action. Zero dependencies, one file.
## 3. How to use it
import { Menu002 } from "@/components/vibeui/menu-002"
<Menu002 items={[{ label: "Open" }, { label: "Delete", danger: true }]} />
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-menu-002-* palette — do not swap it for your theme tokens
- coordinates from the event: a cursor position has no anchor CSS could use
- a visible zone where right-click works — otherwise the menu is found by accident
- closing on Escape and mouse-out, not only on selection
- colour on the destructive item's text only
- the same actions duplicated in a normal menu: phones have no right click
## 6. You may change
- the items array
- hint — the zone's caption
- the selection handlers
- the accent through the accent prop
## 7. Rules
- Phones have no context menu at all: the same actions must be reachable another way.
- The menu can overflow the window: add bounds checking for exact placement.
- Only override the browser menu where you replace it: on text and links it is an annoyance.
- 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/menu-002.jsonhttps://vibeui.ru/r/menu-002.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-menu-002-*. Клиентский: "use client". Координаты берутся из события contextmenu, стандартное меню браузера отменяется preventDefault. Меню позиционируется fixed по точке нажатия. Область, на которой работает правая кнопка, обозначена пунктиром и подписью.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useState } from "react"
import type {
ComponentPropsWithoutRef,
CSSProperties,
MouseEvent as ReactMouseEvent,
} from "react"
export type Menu002Item = {
label: string
hint?: string
danger?: boolean
}
export type Menu002Props = Omit<ComponentPropsWithoutRef<"div">, "children"> & {
items?: Menu002Item[]
hint?: string
accent?: string
}
// Идея компонента: контекстное меню по правой кнопке. Оно появляется там, где
// нажали, поэтому координаты считаются от события — их не даст ни popover, ни
// якорное позиционирование. Закрывается выбором, Escape и уходом курсора. На
// телефоне правой кнопки нет, поэтому те же действия обязаны быть где-то ещё.
const STYLES = `
:where([data-vibeui-block="menu-002"]){
--vibeui-menu-002-bg:oklch(1 0 0);
--vibeui-menu-002-fg:oklch(0.24 0.014 265);
--vibeui-menu-002-muted:oklch(0.56 0.014 265);
--vibeui-menu-002-border:oklch(0.9 0.006 265);
--vibeui-menu-002-hover:oklch(0.96 0.004 265);
--vibeui-menu-002-danger:oklch(0.56 0.19 25);
--vibeui-menu-002-accent:oklch(0.55 0.17 265);
--vibeui-menu-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="menu-002"]{
width:100%;max-width:20rem;box-sizing:border-box;
font-family:var(--vibeui-menu-002-font);color:var(--vibeui-menu-002-fg);
}
/* Область, на которой работает правая кнопка: она обязана быть очевидной. */
[data-vibeui-block="menu-002"] [data-part="zone"]{
display:flex;flex-direction:column;align-items:center;justify-content:center;gap:0.375rem;
min-height:7rem;padding:1rem;box-sizing:border-box;text-align:center;
border:1.5px dashed var(--vibeui-menu-002-border);border-radius:0.875rem;
background:var(--vibeui-menu-002-bg);
}
[data-vibeui-block="menu-002"] [data-part="zone-title"]{font-size:0.875rem;font-weight:650}
[data-vibeui-block="menu-002"] [data-part="zone-hint"]{font-size:0.75rem;color:var(--vibeui-menu-002-muted)}
[data-vibeui-block="menu-002"] [data-part="menu"]{
position:fixed;margin:0;padding:0.3125rem;min-width:12rem;
border:1px solid var(--vibeui-menu-002-border);border-radius:0.75rem;
background:var(--vibeui-menu-002-bg);color:inherit;
box-shadow:0 18px 40px -22px oklch(0.2 0.02 265 / 55%);
}
[data-vibeui-block="menu-002"] [data-part="item"]{
display:flex;align-items:center;justify-content:space-between;gap:0.75rem;
width:100%;min-height:2rem;padding:0 0.5rem;
appearance:none;border:0;border-radius:0.5rem;background:transparent;color:inherit;
font:inherit;font-size:0.8125rem;text-align:left;cursor:pointer;
}
[data-vibeui-block="menu-002"] [data-part="item"]:hover{background:var(--vibeui-menu-002-hover)}
[data-vibeui-block="menu-002"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-menu-002-accent);outline-offset:-2px}
[data-vibeui-block="menu-002"] [data-part="item"][data-danger="true"]{color:var(--vibeui-menu-002-danger)}
[data-vibeui-block="menu-002"] kbd{
padding:0.0625rem 0.3125rem;border-radius:0.25rem;
border:1px solid var(--vibeui-menu-002-border);
font-family:inherit;font-size:0.6875rem;color:var(--vibeui-menu-002-muted);
}
[data-vibeui-block="menu-002"] [data-part="picked"]{
margin-top:0.5rem;font-size:0.75rem;color:var(--vibeui-menu-002-muted);text-align:center;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="menu-002"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_ITEMS: Menu002Item[] = [
{ label: "Открыть", hint: "Enter" },
{ label: "Переименовать", hint: "F2" },
{ label: "Копировать путь" },
{ label: "Удалить", hint: "⌫", danger: true },
]
/**
* Контекстное меню по правой кнопке: координаты от события, закрытие по
* выбору, Escape и уходу курсора.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Menu002({
items = DEFAULT_ITEMS,
hint = "Нажмите правой кнопкой по области",
accent,
className,
style,
...props
}: Menu002Props) {
const [point, setPoint] = useState<{ x: number; y: number } | null>(null)
const [picked, setPicked] = useState<string | null>(null)
const palette = {
...(accent ? { "--vibeui-menu-002-accent": accent } : null),
...style,
} as CSSProperties
const open = (event: ReactMouseEvent) => {
event.preventDefault()
setPoint({ x: event.clientX, y: event.clientY })
}
return (
<>
<style href="vibeui-menu-002" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="menu-002"
className={className}
style={palette}
>
<div data-part="zone" onContextMenu={open}>
<span data-part="zone-title">Файл «Каталог.fig»</span>
<span data-part="zone-hint">{hint}</span>
</div>
{point ? (
<div
data-part="menu"
role="menu"
aria-label="Действия с файлом"
style={{ left: point.x, top: point.y }}
onMouseLeave={() => setPoint(null)}
onKeyDown={(event) => {
if (event.key === "Escape") setPoint(null)
}}
>
{items.map((item) => (
<button
key={item.label}
type="button"
role="menuitem"
data-part="item"
data-danger={item.danger}
onClick={() => {
setPicked(item.label)
setPoint(null)
}}
>
{item.label}
{item.hint ? <kbd>{item.hint}</kbd> : null}
</button>
))}
</div>
) : null}
<p data-part="picked" role="status">
{picked ? `Выбрано: ${picked}` : "Действие не выбрано"}
</p>
</div>
</>
)
}