Home

Awesome

Ink Quicksearch

QuickSearch Component for Ink

CircleCI

Install

$ npm install ink-quicksearch

Quickstart

npm install
npm start

Usage

const {h, render, Component} = require('ink');
const QuickSearch = require('ink-quicksearch');

class Demo extends Component {
    render() {
        const props = {
            items: [
                {value: 1, label: 'Animal'},
                {value: 3, label: 'Antilope'},
                {value: 2, label: 'Animation'},
                {value: 0, label: 'Animate'},
                {value: 4, label: 'Arizona'},
                {value: 5, label: 'Aria'},
                {value: 6, label: 'Arid'},
            ],
            onSelect: item => {
                // `item` = { label: 'First', value: 'first' }
            },
        };

        return <QuickSearch {...props} />
    }
}

render(<Demo/>);

Props

ParameterTypeDefaultDescription
itemsArray(object)[]Items to display in a list. <br> Each item must be an object and have at least a label prop.
onSelectfunctionFunction to call when user selects an item. <br> Item object is passed to that function as an argument.
focusbooleantrueListen to user's input. <br> Useful in case there are multiple input components at the same time and input must be "routed" to a specific component.
caseSensitivebooleanfalseWhether or not quicksearch matching will be case sensitive.
limitint0Limit the number of rows to display. 0 is unlimited <br> Use in conjunction with https://www.npmjs.com/package/term-size.
forceMatchingQueryboolfalseIf set to true, queries that return no results are not allowed. In particular, if previous query X returns at least one result and X + new_character would not, query will not update to X + new_character.
clearQueryCharsArray(char)['\u0015', '\u0017'] <br> (<kbd>Ctrl</kbd> + <kbd>u</kbd>, <kbd>Ctrl</kbd> + <kbd>w</kbd>)Key Combinations that will clear the query. <br> ch follows the keypress API process.stdin.on('keypress', (ch, key) => {}).
initialSelectionIndexint0Selection index when the component is initially rendered or when props.items changes. Can be set together with new props.items to automatically select an option.
indicatorComponentComponentCustom component to override the default indicator component (default - arrow).
itemComponentComponentCustom component to override the default item style (default - selection coloring).
highlightComponentComponentCustom component to override the default highlight style (default - background highlight).
statusComponentComponentCustom component to override the status component (default - current query).

Component Props

indicatorComponent

Type: Component<br> Props:

itemComponent

Type: Component<br> Props:

highlightComponent

Type: Component<br> Props:

statusComponent

Type: Component<br> Props:

Default Components

// For the following four, whitespace is important
const IndicatorComponent = ({isSelected}) => {
    return <Color hex="#00FF00">{isSelected ? '>' : ' '} </Color>;
};

const ItemComponent = ({isSelected, children}) => (
    <Color hex={isSelected ? '#00FF00' : ''}>{children}</Color>
);

const HighlightComponent = ({children}) => (
    <Color bgHex="#6C71C4">{children}</Color>
);

const StatusComponent = ({hasMatch, children}) => (
    <Color hex={hasMatch ? '#00FF00' : '#FF0000'}>{children}</Color>
);