Navigation

Recent Commands

A palette that answers an empty query with recent commands instead of the whole alphabetical list: people mostly repeat their last action.

  • command
  • palette
  • recent
  • history

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/command-003?lang=en

Недавние

  • Пересобрать реестр
  • Скопировать инструкцию для агента
  • Создать компонент
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 "command-003" (Recent Commands) 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/command-003.json

Registry item: https://vibeui.ru/r/command-003.json
Installs to: components/vibeui/command-003.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 palette that answers an empty query with recent commands instead of the whole alphabetical list: people mostly repeat their last action.

A palette with history: an empty field shows recent commands, typing switches to search, and running a command lifts it to the top of the history. Zero dependencies, one file.

## 3. How to use it
import { Command003 } from "@/components/vibeui/command-003"

<Command003 commands={["New component"]} recent={["Rebuild registry"]} />

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-command-003-* palette — do not swap it for your theme tokens
- recents instead of the full list on an empty query: an alphabetical dump helps nobody there
- the section heading changing with the mode — otherwise the shorter list looks broken
- the history cap: unbounded, it becomes a second full list
- the role=combobox plus aria-activedescendant pairing: focus stays in the field
- the different glyphs for history and search results: the mode shows per row, not only in the header

## 6. You may change
- the commands and recent arrays
- the field hint through the placeholder prop
- the history depth and the clear button wording
- the accent through the accent prop

## 7. Rules
- History lives in component state only: persisting it between sessions is added from outside.
- Enter runs the highlighted row and clears the query — wire run to your own command model.
- The clear button appears only in history mode: there is nothing to clear in search results.
- 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/command-003.json
https://vibeui.ru/r/command-003.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-command-003-*. Клиентский: "use client" ради useState на запросе и истории. Пустой запрос переключает список на историю, любой ввод — на фильтр по полному набору команд; заголовок над списком меняется вместе с режимом. Запуск команды поднимает её в начало истории и обрезает список до четырёх записей, поэтому история не растёт. Роли combobox, listbox и option проставлены явно, подсветка передаётся aria-activedescendant.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useId, useState } from "react"
import type {
  ComponentPropsWithoutRef,
  CSSProperties,
  KeyboardEvent,
} from "react"

export type Command003Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children"
> & {
  commands?: string[]
  recent?: string[]
  placeholder?: string
  accent?: string
}

// Идея компонента: палитра, которая при пустом запросе показывает не весь
// список, а недавние команды. Пустой ввод — это состояние «я ещё не знаю, что
// ищу», и полный алфавитный список в нём бесполезен: чаще всего повторяют
// последнее. Запуск команды поднимает её наверх недавних и обрезает историю,
// поэтому список не растёт. Заголовок раздела меняется вместе с режимом —
// иначе непонятно, почему строк стало меньше.
const STYLES = `
:where([data-vibeui-block="command-003"]){
--vibeui-command-003-bg:oklch(1 0 0);
--vibeui-command-003-fg:oklch(0.23 0.014 265);
--vibeui-command-003-muted:oklch(0.57 0.014 265);
--vibeui-command-003-border:oklch(0.9 0.006 265);
--vibeui-command-003-accent:oklch(0.58 0.16 200);
--vibeui-command-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="command-003"]{
display:block;box-sizing:border-box;width:100%;max-width:23rem;overflow:hidden;
background:var(--vibeui-command-003-bg);color:var(--vibeui-command-003-fg);
border:1px solid var(--vibeui-command-003-border);border-radius:0.875rem;
box-shadow:0 18px 40px -28px oklch(0.2 0.03 265 / 60%);
font-family:var(--vibeui-command-003-font);
}
[data-vibeui-block="command-003"] input{
box-sizing:border-box;width:100%;height:2.875rem;padding:0 0.875rem;
appearance:none;border:0;border-bottom:1px solid var(--vibeui-command-003-border);
background:none;color:inherit;font:inherit;font-size:0.9375rem;outline:none;
}
[data-vibeui-block="command-003"] input:focus{box-shadow:inset 0 -2px 0 0 var(--vibeui-command-003-accent)}
[data-vibeui-block="command-003"] [data-part="mode"]{
display:flex;align-items:center;gap:0.5rem;
padding:0.5rem 0.875rem 0.25rem;margin:0;
font-size:0.6875rem;font-weight:700;letter-spacing:0.05em;text-transform:uppercase;
color:var(--vibeui-command-003-muted);
}
[data-vibeui-block="command-003"] [data-part="clear"]{
margin-left:auto;appearance:none;border:0;background:none;cursor:pointer;
color:var(--vibeui-command-003-accent);font:inherit;font-size:0.6875rem;font-weight:700;
letter-spacing:0.05em;text-transform:uppercase;
}
[data-vibeui-block="command-003"] [data-part="clear"]:focus-visible{outline:2px solid var(--vibeui-command-003-accent);outline-offset:2px;border-radius:0.25rem}
[data-vibeui-block="command-003"] [data-part="list"]{
list-style:none;margin:0;padding:0.25rem 0.3125rem 0.4375rem;
max-height:14rem;overflow-y:auto;
}
[data-vibeui-block="command-003"] [data-part="row"]{
display:flex;align-items:center;gap:0.625rem;
padding:0.4375rem 0.5625rem;border-radius:0.5rem;cursor:pointer;font-size:0.875rem;
}
[data-vibeui-block="command-003"] [data-part="row"]:hover,
[data-vibeui-block="command-003"] [data-part="row"][aria-selected="true"]{
background:color-mix(in oklab,var(--vibeui-command-003-accent) 14%,transparent);
}
/* Значок часов у недавних: режим списка виден строкой, а не только шапкой. */
[data-vibeui-block="command-003"] [data-part="row"] [data-part="tick"]{
flex:none;width:1rem;text-align:center;color:var(--vibeui-command-003-muted);font-size:0.75rem;
}
[data-vibeui-block="command-003"] [data-part="empty"]{
margin:0;padding:1.125rem 0.875rem;font-size:0.875rem;color:var(--vibeui-command-003-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="command-003"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_COMMANDS = [
  "Создать компонент",
  "Пересобрать реестр",
  "Проверить metadata",
  "Открыть каталог",
  "Открыть настройки проекта",
  "Сменить тему оформления",
  "Скопировать инструкцию для агента",
]

const DEFAULT_RECENT = [
  "Пересобрать реестр",
  "Скопировать инструкцию для агента",
  "Создать компонент",
]

/**
 * Палитра с недавними командами: пустой запрос показывает историю, ввод
 * переключает на поиск. Один файл, ноль зависимостей.
 */
export function Command003({
  commands = DEFAULT_COMMANDS,
  recent = DEFAULT_RECENT,
  placeholder = "Что нужно сделать?",
  accent,
  className,
  style,
  ...props
}: Command003Props) {
  const [query, setQuery] = useState("")
  const [history, setHistory] = useState(recent)
  const [active, setActive] = useState(0)
  const listId = useId()
  const rowId = useId()

  const needle = query.trim().toLowerCase()
  const browsing = needle.length === 0
  const rows = browsing
    ? history
    : commands.filter((command) => command.toLowerCase().includes(needle))
  const current = rows[Math.min(active, rows.length - 1)]

  const run = (command: string) => {
    setHistory((list) =>
      [command, ...list.filter((entry) => entry !== command)].slice(0, 4),
    )
    setQuery("")
    setActive(0)
  }

  const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
    if (event.key === "ArrowDown" || event.key === "ArrowUp") {
      event.preventDefault()
      if (rows.length === 0) return
      const step = event.key === "ArrowDown" ? 1 : -1
      setActive((index) => (index + step + rows.length) % rows.length)
      return
    }

    if (event.key === "Enter" && current) {
      event.preventDefault()
      run(current)
      return
    }

    if (event.key === "Escape") {
      event.preventDefault()
      setQuery("")
      setActive(0)
    }
  }

  const paletteStyle = {
    ...(accent ? { "--vibeui-command-003-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-command-003" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="command-003"
        className={className}
        style={paletteStyle}
        role="dialog"
        aria-label="Командная палитра"
      >
        <input
          type="text"
          role="combobox"
          aria-expanded={rows.length > 0}
          aria-controls={listId}
          aria-autocomplete="list"
          aria-activedescendant={
            current ? `${rowId}-${rows.indexOf(current)}` : undefined
          }
          aria-label={placeholder}
          placeholder={placeholder}
          value={query}
          onChange={(event) => {
            setQuery(event.target.value)
            setActive(0)
          }}
          onKeyDown={onKeyDown}
        />
        <p data-part="mode">
          {browsing ? "Недавние" : `Найдено: ${rows.length}`}
          {browsing && history.length > 0 ? (
            <button
              type="button"
              data-part="clear"
              onClick={() => setHistory([])}
            >
              очистить
            </button>
          ) : null}
        </p>
        {rows.length === 0 ? (
          <p data-part="empty">
            {browsing
              ? "История пуста — начните вводить название команды."
              : "Совпадений нет. Попробуйте другое слово."}
          </p>
        ) : (
          <ul id={listId} data-part="list" role="listbox" aria-label="Команды">
            {rows.map((command, index) => (
              <li
                key={command}
                id={`${rowId}-${index}`}
                data-part="row"
                role="option"
                aria-selected={current === command}
                onClick={() => run(command)}
              >
                <span data-part="tick" aria-hidden="true">
                  {browsing ? "↺" : "›"}
                </span>
                {command}
              </li>
            ))}
          </ul>
        )}
      </div>
    </>
  )
}