EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
CommandPalette·component·@astryxdesign/core

Command Palette Item

A selectable item. Accepts arbitrary children for full rendering control. Registers with context for keyboard navigation when inside CommandPalette.

Open in Playground @astryxdesign/core/CommandPalette

Showcases and examples

2 documented examples

Command Palette Item

Command palette items with custom content via renderItem and as composed CommandPaletteItem with icons, highlighted, selected, and disabled states.

Preview loads on approachPreview loads on approach
Exact source · command-palette-item-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useMemo, type CSSProperties} from 'react';
import {CommandPalette} from '@astryxdesign/core/CommandPalette';
import {Text} from '@astryxdesign/core/Text';
import {Kbd} from '@astryxdesign/core/Kbd';
import {createStaticSource} from '@astryxdesign/core/Typeahead';
import type {SearchableItem} from '@astryxdesign/core/Typeahead';

const itemLabel: CSSProperties = {
  flexGrow: 1,
};

type CommandItem = SearchableItem<{shortcut?: string}>;

const commands: CommandItem[] = [
  {id: 'save', label: 'Save File', auxiliaryData: {shortcut: 'mod+s'}},
  {
    id: 'find',
    label: 'Find in Files',
    auxiliaryData: {shortcut: 'mod+shift+f'},
  },
  {
    id: 'palette',
    label: 'Command Palette',
    auxiliaryData: {shortcut: 'mod+shift+p'},
  },
  {
    id: 'terminal',
    label: 'Toggle Terminal',
    auxiliaryData: {shortcut: 'ctrl+`'},
  },
  {id: 'sidebar', label: 'Toggle Sidebar', auxiliaryData: {shortcut: 'mod+b'}},
];

export default function CommandPaletteItemShowcase() {
  const source = useMemo(() => createStaticSource(commands), []);

  return (
    <CommandPalette
      isOpen
      isInline
      onOpenChange={() => {}}
      searchSource={source}
      renderItem={(item: CommandItem) => (
        <>
          <Text type="body" style={itemLabel}>
            {item.label}
          </Text>
          {item.auxiliaryData?.shortcut && (
            <Kbd keys={item.auxiliaryData.shortcut} />
          )}
        </>
      )}
    />
  );
}

Usage

A selectable item. Accepts arbitrary children for full rendering control. Registers with context for keyboard navigation when inside CommandPalette.

Typed props

PropType and behavior
valuestring · required
Unique value for identification and selection.
childrenReactNode · required
Item content: render icons, descriptions, keyboard shortcuts, etc.
onSelect(value: string) => void
Called when this item is selected via click or Enter.
isHighlightedboolean · default false
Whether this item has keyboard focus. Derived from context when inside CommandPalette.
isSelectedboolean · default false
Whether this item is selected in picker mode.
isDisabledboolean · default false
Whether the item is non-interactive.
xstyleStyleXStyles
StyleX styles for layout customization. Must be a stylex.create() value.