Quicksearch Input Component for Ink 4
npm install @inkkit/ink-quicksearch-input> QuickSearch Component for Ink 4
Refactored version of John's ink-quicksearch-input
```
$ npm install @inkkit/ink-quicksearch-input
`jsx
import React, { useState } from 'react';
import { render, Text, Box } from 'ink';
import { QuickSearchInput } from '@inkkit/ink-quicksearch-input';
const Demo = (props) => {
const [result, setResult] = useState('');
return (
<>
{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) => setResult(item.label)} />
>
)
}
render(
`
| Parameter | Type | Default | Description
| --- | --- | --- | --- |
| items | Array(object) | [] | Items to display in a list. label
Each item must be an object and have at least a prop. function
| onSelect | | | Function to call when user selects an item. boolean
Item object is passed to that function as an argument.
| focus | | true | Listen to user's input. boolean
Useful in case there are multiple input components at the same time and input must be "routed" to a specific component.
| caseSensitive | | false | Whether or not quicksearch matching will be case sensitive.int
| limit | | 0 | Limit the number of rows to display. 0 is unlimited bool
Use in conjunction with https://www.npmjs.com/package/term-size.
| forceMatchingQuery | | false | If 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.Array(char)
| clearQueryChars | | ['\u0015', '\u0017'] ch
(Ctrl + u, Ctrl + w) | Key Combinations that will clear the query.
follows the keypress API process.stdin.on('keypress', (ch, key) => {}).int
| initialSelectionIndex | | 0 | Selection 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.string
| label | | | Optionally provide a label which will appear before the current query.
| indicatorComponent | Component | | Custom component to override the default indicator component (default - arrow).
| itemComponent | Component | | Custom component to override the default item style (default - selection coloring).
| highlightComponent | Component | | Custom component to override the default highlight style (default - background highlight).
| statusComponent | Component | | Custom component to override the status component (default - current query, optional value label).
Type: Component
Props:
- isSelected: booleanisHighlighted
- : booleanitem
- : Object - The corresponding object inside props.items
Type: Component
Props:
- isSelected: booleanisHighlighted
- : booleanitem
- : Object - The corresponding object inside props.itemschildren
- : any
Type: Component
Props:
- isSelected: booleanisHighlighted
- : booleanitem
- : Object - The corresponding object inside props.itemschildren
- : any
Type: Component
Props:
- hasMatch: booleanchildren
- : anylabel
- : Optional string
`jsx
// For the following four, whitespace is important
const IndicatorComponent = ({isSelected}) => {
return
};
const ItemComponent = ({isSelected, children}) => (
);
const HighlightComponent = ({children}) => (
);
const StatusComponent = ({hasMatch, children}) => (
);
``