Navigation
Collapsing Menubar
A menubar that folds into a burger on narrow widths: the threshold comes from the block's own width, not the window size.
- menubar
- responsive
- container-query
- 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/menubar-005?lang=en
Файл
Правка
Вид
Справка
Menu
Файл
Правка
Вид
Справка
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 "menubar-005" (Collapsing Menubar) 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/menubar-005.json
Registry item: https://vibeui.ru/r/menubar-005.json
Installs to: components/vibeui/menubar-005.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 menubar that folds into a burger on narrow widths: the threshold comes from the block's own width, not the window size.
A menubar with two faces: a wide row of sections and a burger when space runs out. A container query does the switching, so the component behaves the same on a phone and in a narrow desktop column. Zero dependencies, one file, no client JS.
## 3. How to use it
import { Menubar005 } from "@/components/vibeui/menubar-005"
<Menubar005
burgerLabel="Menu"
menus={[{ label: "File", items: ["New project", "Open…"] }]}
/>
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-menubar-005-* palette — do not swap it for your theme tokens (bg-background, border-border and the like)
- the container query instead of a media query: the component must react to its own width, or a narrow column keeps the wide row
- the layout rule on the inner [data-part="shell"] rather than the root: @container does not apply to the container itself
- display:none on the hidden face: a row hidden with opacity stays in the tab order and in the accessibility tree
- the shared name attribute on the wide view's <details> — it is how sections close one another
- the section headings inside the burger: without them the list becomes two dozen identical rows
## 6. You may change
- the menus array: sections and their items
- burgerLabel — the collapsed button's caption
- the switching threshold in the container query
- the accent through the accent prop — it colours the focus ring
## 7. Rules
- Both faces live in the markup, so the items are listed twice: with a very long menu that shows up in page weight.
- Escape does not close a <details>: that is the element's behaviour, not a bug.
- The 30rem threshold is tuned to the sample labels: longer names need a larger threshold.
- 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/menubar-005.jsonhttps://vibeui.ru/r/menubar-005.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-menubar-005-*. Серверный: хуков нет, состояние держат <details>. Широкий и узкий виды лежат в разметке одновременно, лишний убирается display:none — так он не попадает ни в порядок табуляции, ни в дерево доступности. Порог переключения задан контейнерным запросом на внутреннем [data-part="shell"], потому что правило внутри @container не действует на сам контейнер. Разделы в широком виде закрывают друг друга через общий атрибут name.
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 Menubar005Menu = {
label: string
items: string[]
}
export type Menubar005Props = {
menus?: Menubar005Menu[]
burgerLabel?: string
accent?: string
className?: string
style?: CSSProperties
}
// Идея компонента: строка меню, которая на узкой ширине сворачивается в одну
// кнопку-бургер. Порог считается от собственной ширины блока (@container), а не
// от окна: тот же компонент в узкой колонке ведёт себя как на телефоне. Оба вида
// живут в разметке одновременно, и лишний убирается display:none — так он не
// попадает ни в порядок табуляции, ни в дерево доступности.
const STYLES = `
:where([data-vibeui-block="menubar-005"]){
--vibeui-menubar-005-bg:oklch(1 0 0);
--vibeui-menubar-005-fg:oklch(0.24 0.014 265);
--vibeui-menubar-005-muted:oklch(0.58 0.014 265);
--vibeui-menubar-005-border:oklch(0.9 0.006 265);
--vibeui-menubar-005-hover:oklch(0.55 0.02 265 / 10%);
--vibeui-menubar-005-accent:oklch(0.55 0.2 262);
--vibeui-menubar-005-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
container-type:inline-size;
}
[data-vibeui-block="menubar-005"]{
width:100%;max-width:36rem;box-sizing:border-box;
font-family:var(--vibeui-menubar-005-font);color:var(--vibeui-menubar-005-fg);
}
[data-vibeui-block="menubar-005"] [data-part="shell"]{
box-sizing:border-box;padding:0.25rem;
background:var(--vibeui-menubar-005-bg);
border:1px solid var(--vibeui-menubar-005-border);border-radius:0.625rem;
}
[data-vibeui-block="menubar-005"] [data-part="wide"]{display:none;align-items:center;gap:0.125rem}
[data-vibeui-block="menubar-005"] [data-part="narrow"]{display:block}
/* Порог берётся от ширины блока: в узкой колонке остаётся бургер. */
@container (min-width: 30rem){
[data-vibeui-block="menubar-005"] [data-part="wide"]{display:flex}
[data-vibeui-block="menubar-005"] [data-part="narrow"]{display:none}
}
[data-vibeui-block="menubar-005"] [data-part="slot"]{position:relative}
[data-vibeui-block="menubar-005"] [data-part="trigger"]{
list-style:none;cursor:pointer;display:flex;align-items:center;gap:0.5rem;
height:1.875rem;padding:0 0.625rem;border-radius:0.4375rem;font-size:0.8125rem;
}
[data-vibeui-block="menubar-005"] [data-part="trigger"]::-webkit-details-marker{display:none}
[data-vibeui-block="menubar-005"] [data-part="trigger"]:hover{background:var(--vibeui-menubar-005-hover)}
[data-vibeui-block="menubar-005"] [data-part="trigger"]:focus-visible{outline:2px solid var(--vibeui-menubar-005-accent);outline-offset:-2px}
[data-vibeui-block="menubar-005"] [data-part="slot"][open] > [data-part="trigger"]{background:var(--vibeui-menubar-005-hover)}
[data-vibeui-block="menubar-005"] [data-part="menu"]{
position:absolute;top:calc(100% + 0.375rem);left:0;z-index:30;
min-width:12rem;padding:0.25rem;box-sizing:border-box;margin:0;list-style:none;
background:var(--vibeui-menubar-005-bg);
border:1px solid var(--vibeui-menubar-005-border);border-radius:0.625rem;
box-shadow:0 16px 36px -18px oklch(0.2 0.03 265 / 45%);
}
[data-vibeui-block="menubar-005"] [data-part="item"]{
display:block;width:100%;min-height:1.875rem;padding:0.3125rem 0.5rem;box-sizing:border-box;
appearance:none;border:0;background:none;cursor:pointer;border-radius:0.4375rem;
font:inherit;font-size:0.8125rem;color:inherit;text-align:left;
}
[data-vibeui-block="menubar-005"] [data-part="item"]:hover{background:var(--vibeui-menubar-005-hover)}
[data-vibeui-block="menubar-005"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-menubar-005-accent);outline-offset:-2px}
/* Бургер: три полоски, которые складываются в крест при раскрытии. */
[data-vibeui-block="menubar-005"] [data-part="bars"]{
display:grid;gap:0.1875rem;width:1rem;
}
[data-vibeui-block="menubar-005"] [data-part="bars"] i{
display:block;height:1.5px;background:currentColor;border-radius:1px;
transition:transform .18s ease,opacity .18s ease;
}
[data-vibeui-block="menubar-005"] [data-part="narrow"][open] [data-part="bars"] i:first-child{transform:translateY(0.3125rem) rotate(45deg)}
[data-vibeui-block="menubar-005"] [data-part="narrow"][open] [data-part="bars"] i:nth-child(2){opacity:0}
[data-vibeui-block="menubar-005"] [data-part="narrow"][open] [data-part="bars"] i:last-child{transform:translateY(-0.3125rem) rotate(-45deg)}
[data-vibeui-block="menubar-005"] [data-part="sheet"]{
margin:0.375rem 0 0;padding:0.25rem 0 0;list-style:none;
border-top:1px solid var(--vibeui-menubar-005-border);
}
[data-vibeui-block="menubar-005"] [data-part="subsheet"]{margin:0;padding:0;list-style:none}
[data-vibeui-block="menubar-005"] [data-part="section"]{
padding:0.5rem 0.5rem 0.1875rem;font-size:0.6875rem;letter-spacing:0.04em;
text-transform:uppercase;color:var(--vibeui-menubar-005-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="menubar-005"] *{animation:none!important;transition:none!important}}
`
const DEFAULT_MENUS: Menubar005Menu[] = [
{
label: "Файл",
items: ["Новый проект", "Открыть…", "Сохранить", "Экспорт"],
},
{
label: "Правка",
items: ["Отменить", "Повторить", "Найти в проекте"],
},
{
label: "Вид",
items: ["Сетка", "Боковая панель", "Во весь экран"],
},
{
label: "Справка",
items: ["Горячие клавиши", "Документация"],
},
]
/**
* Строка меню, сворачивающаяся в бургер на узкой ширине блока.
* Один файл, ноль зависимостей, собственная палитра, клиентского JS нет.
*/
export function Menubar005({
menus = DEFAULT_MENUS,
burgerLabel = "Меню",
accent,
className,
style,
}: Menubar005Props) {
const palette = {
...(accent ? { "--vibeui-menubar-005-accent": accent } : null),
...style,
} as CSSProperties
return (
<>
<style href="vibeui-menubar-005" precedence="medium">
{STYLES}
</style>
<div
data-vibeui-block="menubar-005"
className={className}
style={palette}
>
<div data-part="shell">
<div data-part="wide" role="menubar" aria-label="Меню приложения">
{menus.map((menu) => (
<details
key={menu.label}
data-part="slot"
name="vibeui-menubar-005"
>
<summary data-part="trigger" role="menuitem">
{menu.label}
</summary>
<ul data-part="menu" role="menu" aria-label={menu.label}>
{menu.items.map((item) => (
<li key={item} role="none">
<button type="button" data-part="item" role="menuitem">
{item}
</button>
</li>
))}
</ul>
</details>
))}
</div>
<details data-part="narrow">
<summary data-part="trigger">
<span data-part="bars" aria-hidden="true">
<i />
<i />
<i />
</span>
{burgerLabel}
</summary>
<ul data-part="sheet">
{menus.map((menu) => (
<li key={menu.label}>
<p data-part="section">{menu.label}</p>
<ul data-part="subsheet">
{menu.items.map((item) => (
<li key={item}>
<button type="button" data-part="item">
{item}
</button>
</li>
))}
</ul>
</li>
))}
</ul>
</details>
</div>
</div>
</>
)
}