{
  "name": "command-panel",
  "type": "registry:block",
  "framework": "react",
  "title": "Command panel",
  "description": "A command browser with a selectable suggestion list and a detailed option card.",
  "registryDependencies": [
    "@newtui/slash-command-suggestions",
    "@newtui/bot-command-card"
  ],
  "files": [
    {
      "path": "blocks/command-panel/command-panel.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  BotCommandCard,\n  BotCommandCardDescription,\n  BotCommandCardHeader,\n  BotCommandCardName,\n  BotCommandCardOption,\n  BotCommandCardOptions,\n} from \"@/registry/bases/newt/ui/bot-command-card\"\nimport {\n  SlashCommandAppIcon,\n  SlashCommandSuggestion,\n  SlashCommandSuggestionGroup,\n  SlashCommandSuggestions,\n  SlashCommandSuggestionsHeader,\n  SlashCommandSuggestionsList,\n} from \"@/registry/bases/newt/ui/slash-command-suggestions\"\n\nexport interface CommandPanelOption {\n  name: string\n  type?: string\n  required?: boolean\n  description?: string\n}\n\nexport interface CommandPanelCommand {\n  id: string\n  name: string\n  description: string\n  appLabel?: string\n  options?: readonly CommandPanelOption[]\n}\n\nexport interface CommandPanelProps extends Omit<\n  React.ComponentProps<\"section\">,\n  \"children\"\n> {\n  commands: readonly CommandPanelCommand[]\n  selectedId?: string\n  defaultSelectedId?: string\n  onSelectedIdChange?: (id: string) => void\n  listLabel?: string\n  emptyLabel?: string\n}\n\nexport function CommandPanel({\n  commands,\n  selectedId: controlledSelectedId,\n  defaultSelectedId,\n  onSelectedIdChange,\n  listLabel = \"Available commands\",\n  emptyLabel = \"No commands available.\",\n  className,\n  ...props\n}: CommandPanelProps) {\n  const [uncontrolledSelectedId, setUncontrolledSelectedId] = React.useState(\n    defaultSelectedId ?? commands[0]?.id\n  )\n  const instanceId = React.useId().replaceAll(\":\", \"\")\n  const selectedId = controlledSelectedId ?? uncontrolledSelectedId\n  const selectedIndex = Math.max(\n    0,\n    commands.findIndex((command) => command.id === selectedId)\n  )\n  const selectedCommand = commands[selectedIndex]\n\n  function select(id: string) {\n    if (controlledSelectedId === undefined) setUncontrolledSelectedId(id)\n    onSelectedIdChange?.(id)\n  }\n\n  function moveSelection(key: \"first\" | \"last\" | \"next\" | \"previous\") {\n    if (commands.length === 0) return\n    const nextIndex =\n      key === \"first\"\n        ? 0\n        : key === \"last\"\n          ? commands.length - 1\n          : key === \"next\"\n            ? (selectedIndex + 1) % commands.length\n            : (selectedIndex - 1 + commands.length) % commands.length\n    const command = commands[nextIndex]\n    if (command) select(command.id)\n  }\n\n  return (\n    <section\n      className={cn(\n        \"grid w-full grid-cols-1 gap-4 md:grid-cols-[minmax(0,1fr)_minmax(18rem,24rem)]\",\n        className\n      )}\n      {...props}\n    >\n      <SlashCommandSuggestions className=\"max-w-none\">\n        <SlashCommandSuggestionsList\n          aria-label={listLabel}\n          aria-activedescendant={\n            selectedCommand\n              ? `${instanceId}-command-${selectedCommand.id}`\n              : undefined\n          }\n          tabIndex={0}\n          onKeyDown={(event) => {\n            if (event.key === \"ArrowDown\") {\n              event.preventDefault()\n              moveSelection(\"next\")\n            } else if (event.key === \"ArrowUp\") {\n              event.preventDefault()\n              moveSelection(\"previous\")\n            } else if (event.key === \"Home\") {\n              event.preventDefault()\n              moveSelection(\"first\")\n            } else if (event.key === \"End\") {\n              event.preventDefault()\n              moveSelection(\"last\")\n            }\n          }}\n        >\n          <SlashCommandSuggestionsHeader>\n            Commands\n          </SlashCommandSuggestionsHeader>\n          <SlashCommandSuggestionGroup aria-label={listLabel}>\n            {commands.map((command) => (\n              <SlashCommandSuggestion\n                key={command.id}\n                id={`${instanceId}-command-${command.id}`}\n                active={command.id === selectedCommand?.id}\n                name={command.name}\n                description={command.description}\n                appLabel={command.appLabel}\n                icon={\n                  <SlashCommandAppIcon>\n                    {command.name.slice(0, 1).toUpperCase()}\n                  </SlashCommandAppIcon>\n                }\n                onClick={() => select(command.id)}\n                onMouseEnter={() => select(command.id)}\n              />\n            ))}\n          </SlashCommandSuggestionGroup>\n          {commands.length === 0 ? (\n            <p className=\"px-2 py-4 text-sm text-newt-text-muted\">\n              {emptyLabel}\n            </p>\n          ) : null}\n        </SlashCommandSuggestionsList>\n      </SlashCommandSuggestions>\n\n      {selectedCommand ? (\n        <BotCommandCard className=\"max-w-none\" aria-live=\"polite\">\n          <BotCommandCardHeader>\n            <BotCommandCardName>{selectedCommand.name}</BotCommandCardName>\n            {selectedCommand.appLabel ? (\n              <span className=\"text-xs text-newt-text-muted\">\n                {selectedCommand.appLabel}\n              </span>\n            ) : null}\n          </BotCommandCardHeader>\n          <BotCommandCardDescription>\n            {selectedCommand.description}\n          </BotCommandCardDescription>\n          {selectedCommand.options?.length ? (\n            <BotCommandCardOptions>\n              {selectedCommand.options.map((option) => (\n                <BotCommandCardOption key={option.name} {...option} />\n              ))}\n            </BotCommandCardOptions>\n          ) : null}\n        </BotCommandCard>\n      ) : (\n        <div\n          className=\"rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-elevated p-4 text-sm text-newt-text-muted\"\n          aria-live=\"polite\"\n        >\n          {emptyLabel}\n        </div>\n      )}\n    </section>\n  )\n}\n",
      "type": "registry:block"
    }
  ]
}