Navigation

Checkable Menubar

A View menu whose items hold state instead of firing actions: checkable toggles and mutually exclusive options marked with a dot.

  • menubar
  • checkbox
  • state
  • popover

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/menubar-004?lang=en

включено: 1 · Обычная
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-004" (Checkable 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-004.json

Registry item: https://vibeui.ru/r/menubar-004.json
Installs to: components/vibeui/menubar-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 View menu whose items hold state instead of firing actions: checkable toggles and mutually exclusive options marked with a dot.

A menu of stateful items: checks for independent settings, dots for mutually exclusive options, and the current state visible right in the menubar. Zero dependencies, one file, its own palette.

## 3. How to use it
import { Menubar004 } from "@/components/vibeui/menubar-004"

<Menubar004
  toggles={[{ id: "grid", label: "Grid", keys: "⌘'" }]}
  defaultOn={["grid"]}
  defaultChoice="cozy"
/>

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-004-* palette — do not swap it for your theme tokens (bg-accent, text-muted-foreground and the like)
- role="menuitemcheckbox" and role="menuitemradio" together with aria-checked: without them a screen reader announces a plain command and the state is lost
- the fixed-width mark column: drawing the check in place of the text makes the labels jump on every toggle
- popover="auto": a click inside does not close the menu while Escape and an outside click do — exactly what settings need
- different marks for a toggle and an option: a check means "on", a dot means "chosen from a set"
- the group headings above the items — they tell independent settings apart from a single choice

## 6. You may change
- the toggles and choices arrays: labels, ids and shortcuts
- the initial state through defaultOn and defaultChoice
- the accent through the accent prop — it colours the check, the dot and the focus ring
- the summary text beside the section button

## 7. Rules
- The state lives inside the component: to lift it up, replace useState with props and your own handlers.
- Settings are not persisted across reloads: storing them is the caller's job.
- Without anchor positioning support the menu opens centred: check your target browsers.
- 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-004.json
https://vibeui.ru/r/menubar-004.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-menubar-004-*. Клиентский: "use client" ради состояния переключателей. Меню — popover="auto", поэтому Escape и клик мимо достаются от браузера, а клик внутри его не закрывает — это и нужно для пунктов-переключателей. Пункты помечены role="menuitemcheckbox" и role="menuitemradio" с aria-checked. Отметка живёт в отдельной колонке фиксированной ширины, поэтому подписи не разъезжаются при включении.

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 { CSSProperties } from "react"

export type Menubar004Toggle = {
  id: string
  label: string
  keys?: string
}

export type Menubar004Choice = {
  id: string
  label: string
}

export type Menubar004Props = {
  toggles?: Menubar004Toggle[]
  choices?: Menubar004Choice[]
  defaultOn?: string[]
  defaultChoice?: string
  accent?: string
  className?: string
  style?: CSSProperties
}

// Идея компонента: меню «Вид», в котором пункты не запускают действие, а держат
// состояние. Переключатели помечены role="menuitemcheckbox", взаимоисключающие
// варианты — role="menuitemradio"; галочка и точка стоят в отдельной колонке,
// поэтому подписи выровнены независимо от того, включён пункт или нет.
const STYLES = `
:where([data-vibeui-block="menubar-004"]){
--vibeui-menubar-004-bg:oklch(1 0 0);
--vibeui-menubar-004-fg:oklch(0.24 0.014 265);
--vibeui-menubar-004-muted:oklch(0.58 0.014 265);
--vibeui-menubar-004-border:oklch(0.9 0.006 265);
--vibeui-menubar-004-hover:oklch(0.55 0.02 265 / 10%);
--vibeui-menubar-004-accent:oklch(0.55 0.2 262);
--vibeui-menubar-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="menubar-004"]{
box-sizing:border-box;width:100%;max-width:30rem;padding:0.25rem;
display:flex;align-items:center;gap:0.125rem;
background:var(--vibeui-menubar-004-bg);color:var(--vibeui-menubar-004-fg);
border:1px solid var(--vibeui-menubar-004-border);border-radius:0.625rem;
font-family:var(--vibeui-menubar-004-font);
}
[data-vibeui-block="menubar-004"] [data-part="slot"]{position:relative}
[data-vibeui-block="menubar-004"] [data-part="trigger"]{
appearance:none;border:0;background:none;cursor:pointer;
height:1.875rem;padding:0 0.625rem;border-radius:0.4375rem;
font:inherit;font-size:0.8125rem;color:inherit;
}
[data-vibeui-block="menubar-004"] [data-part="trigger"]:hover{background:var(--vibeui-menubar-004-hover)}
[data-vibeui-block="menubar-004"] [data-part="trigger"]:focus-visible{outline:2px solid var(--vibeui-menubar-004-accent);outline-offset:-2px}
[data-vibeui-block="menubar-004"] [data-part="slot"]:has([data-part="menu"]:popover-open) [data-part="trigger"]{background:var(--vibeui-menubar-004-hover)}
[data-vibeui-block="menubar-004"] [data-part="menu"]{
position:fixed;inset:auto;margin:0;
min-width:14rem;padding:0.25rem;box-sizing:border-box;
background:var(--vibeui-menubar-004-bg);color:var(--vibeui-menubar-004-fg);
border:1px solid var(--vibeui-menubar-004-border);border-radius:0.625rem;
font-family:var(--vibeui-menubar-004-font);
box-shadow:0 16px 36px -18px oklch(0.2 0.03 265 / 45%);
}
@supports (anchor-name: --a){
[data-vibeui-block="menubar-004"] [data-part="trigger"]{anchor-name:var(--vibeui-menubar-004-anchor)}
[data-vibeui-block="menubar-004"] [data-part="menu"]{
position-anchor:var(--vibeui-menubar-004-anchor);
position-area:bottom span-right;margin-top:0.375rem;
position-try-fallbacks:flip-block,flip-inline;
}
}
/* Колонка отметки фиксированной ширины: подписи не разъезжаются при включении. */
[data-vibeui-block="menubar-004"] [data-part="item"]{
display:grid;grid-template-columns:1rem 1fr auto;align-items:center;gap:0.5rem;
width:100%;min-height:1.875rem;padding:0 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-004"] [data-part="item"]:hover{background:var(--vibeui-menubar-004-hover)}
[data-vibeui-block="menubar-004"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-menubar-004-accent);outline-offset:-2px}
[data-vibeui-block="menubar-004"] [data-part="mark"]{
width:1rem;height:1rem;display:grid;place-items:center;
font-size:0.75rem;line-height:1;color:var(--vibeui-menubar-004-accent);
}
[data-vibeui-block="menubar-004"] [data-part="keys"]{font-size:0.6875rem;color:var(--vibeui-menubar-004-muted)}
[data-vibeui-block="menubar-004"] [data-part="group"]{
padding:0.375rem 0.5rem 0.1875rem;font-size:0.6875rem;letter-spacing:0.04em;
text-transform:uppercase;color:var(--vibeui-menubar-004-muted);
}
[data-vibeui-block="menubar-004"] [data-part="rule"]{
height:1px;margin:0.25rem 0.375rem;background:var(--vibeui-menubar-004-border);
}
[data-vibeui-block="menubar-004"] [data-part="state"]{
margin-left:auto;padding-right:0.375rem;font-size:0.6875rem;color:var(--vibeui-menubar-004-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="menubar-004"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_TOGGLES: Menubar004Toggle[] = [
  { id: "grid", label: "Сетка", keys: "⌘'" },
  { id: "rulers", label: "Линейки", keys: "⌘R" },
  { id: "outlines", label: "Контуры блоков" },
]

const DEFAULT_CHOICES: Menubar004Choice[] = [
  { id: "compact", label: "Компактная" },
  { id: "cozy", label: "Обычная" },
  { id: "wide", label: "Просторная" },
]

/**
 * Меню с пунктами-переключателями и взаимоисключающими вариантами.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Menubar004({
  toggles = DEFAULT_TOGGLES,
  choices = DEFAULT_CHOICES,
  defaultOn = ["grid"],
  defaultChoice = "cozy",
  accent,
  className,
  style,
}: Menubar004Props) {
  const [on, setOn] = useState<string[]>(defaultOn)
  const [choice, setChoice] = useState(defaultChoice)

  const palette = {
    ...(accent ? { "--vibeui-menubar-004-accent": accent } : null),
    ...style,
  } as CSSProperties

  const anchor = {
    "--vibeui-menubar-004-anchor": "--vibeui-menubar-004-view",
  } as CSSProperties

  return (
    <>
      <style href="vibeui-menubar-004" precedence="medium">
        {STYLES}
      </style>
      <div
        data-vibeui-block="menubar-004"
        role="menubar"
        aria-label="Меню приложения"
        className={className}
        style={palette}
      >
        <span data-part="slot" style={anchor}>
          <button
            type="button"
            data-part="trigger"
            role="menuitem"
            aria-haspopup="menu"
            popoverTarget="vibeui-menubar-004-menu"
          >
            Вид
          </button>
          <div
            id="vibeui-menubar-004-menu"
            data-part="menu"
            popover="auto"
            role="menu"
            aria-label="Вид"
          >
            <p data-part="group">Показывать</p>
            {toggles.map((toggle) => {
              const checked = on.includes(toggle.id)

              return (
                <button
                  key={toggle.id}
                  type="button"
                  data-part="item"
                  role="menuitemcheckbox"
                  aria-checked={checked}
                  onClick={() =>
                    setOn((current) =>
                      checked
                        ? current.filter((id) => id !== toggle.id)
                        : [...current, toggle.id],
                    )
                  }
                >
                  <span data-part="mark" aria-hidden="true">
                    {checked ? "✓" : ""}
                  </span>
                  <span>{toggle.label}</span>
                  {toggle.keys ? (
                    <span data-part="keys">{toggle.keys}</span>
                  ) : null}
                </button>
              )
            })}
            <div data-part="rule" />
            <p data-part="group">Плотность</p>
            {choices.map((option) => (
              <button
                key={option.id}
                type="button"
                data-part="item"
                role="menuitemradio"
                aria-checked={choice === option.id}
                onClick={() => setChoice(option.id)}
              >
                <span data-part="mark" aria-hidden="true">
                  {choice === option.id ? "●" : ""}
                </span>
                <span>{option.label}</span>
                <span />
              </button>
            ))}
          </div>
        </span>
        <span data-part="state">
          включено: {on.length} ·{" "}
          {choices.find((it) => it.id === choice)?.label}
        </span>
      </div>
    </>
  )
}