AsterUIDocsv1.0.2

Docs / Component reference

CommandPalette & yield* pickCommand()

Let someone find an action by typing its name. A command can return a choice to the calling generator.

Command example

Install

sh
npx @fierst/ui@1.0.2 add command

Registry dependencies: theme, icon. Package dependencies: @lucide/icons.

Exports from ./ui/command: CommandItem, CommandPalette, pickCommand.

Download the registry source for command 1.0.2.

API contracts

ts
export interface CommandItem {
  id: string;
  label: string;
  hint?: string;
  group?: string;
  keywords?: readonly string[];
  shortcut?: string;
  onSelect?: () => void;
}

export function* CommandPalette(
  props: {
    items: readonly CommandItem[];
    open?: boolean;
    onOpenChange?: (open: boolean) => void;
    onSelect?: (item: CommandItem) => void;
    placeholder?: string;
    shortcut?: boolean;
    class?: string;
  },
  ctx: Ctx,
)

export function* pickCommand(
  items: readonly CommandItem[],
  opts: { placeholder?: string } = {},
): Generator<View, CommandItem | null, any>