Caret-Tui

SearchModal

A command palette style search modal.

SearchModal renders a focused overlay with a text input designed for fuzzy searching through a list of items. It is highly inspired by traditional Command Palettes (Cmd+K menus) found in modern editors.

Usage

import { SearchModal, Box, Text } from 'caret-tui';
import { useState } from 'react';

const items = [
  { label: 'Create New File', value: 'create_file', category: 'File' },
  { label: 'Save All', value: 'save_all', category: 'File' },
  { label: 'Toggle Terminal', value: 'toggle_term', category: 'View' }
];

const App = () => {
  const [open, setOpen] = useState(true);

  return (
    <Box>
      <Text>Press Esc to close</Text>
      <SearchModal 
        isOpen={open} 
        onClose={() => setOpen(false)} 
        onSelect={(val) => console.log('Selected:', val)}
        items={items}
        placeholder="Search for an action..."
      />
    </Box>
  );
};

Props

PropTypeDefaultDescription
isOpenboolean-Controls the visibility of the modal.
onClose() => void-Callback fired when the user presses Esc.
onSelect(value: string) => void-Callback fired when an item is selected via Enter.
itemsSearchItem[]-The list of items to search through.
placeholderstring"Search commands..."Text to display when the input is empty.

SearchItem Definition

FieldTypeDescription
labelstringThe text displayed in the search list.
valuestringThe underlying value returned by onSelect.
categorystringOptional categorization tag displayed next to the label.

On this page