1.1.0 • Published 5 years ago

ink-search-select v1.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

ink-search-select

mpm node

incremental search and select component for ink

DEMO

Usage

import SearchSelect from "ink-search-select";
import React from 'react';
import { render } from 'ink';

let app;
const languages = [
    "JavaScript", "Java", "Python", "Ruby",
    "TypeScript", "ECMAScript", "AppleScript",
    "Swift", "Perl", "Lua", "Clojure", "C++", "C",
    "Go", "Haskell", "Scala", "Scheme", "BrainFu*k"
];
const items = languages.map(lang => {
    return { label: lang.toLowerCase(), value: lang };
});
const onSelect = (item) => {
    console.log(`You selected: '${item.value}'`);
    app.unmount();
};

app = render(
    <SearchSelect
        items={items}
        label="Query: "
        desc="Search any languages"
        onSelect={onSelect}
    />
);

Dependencies

Installation

npm install ink-search-select

or

yarn add ink-search-select

Props

label

TypeDefault
string"Search query: "

A label string in front of text input.

desc

TypeDefault
string"Search anything"

A description string of search. It displays between until text inputted after rendered.

placeholder

TypeDefault
string"..."

A placeholder string of text input.

items (from ink-select-input)

TypeDefault
array[]

An items array to display in a list. Each item must be an object and have label and value props, it may also optionally have a key prop. If no key prop is provided, the value will be used as the item key.

itemComponent (from ink-select-input)

TypeDefault
ComponentItem

A custom ink component to override the default item component.

onSelect (from ink-select-input)

TypeDefault
func() => {}

A function to call when user selects an item. Item object is passed to that function as an argument.