r3bl-ts-utils
Version:
The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu
58 lines (57 loc) • 2.46 kB
TypeScript
import * as React from "react";
import { Data } from "../../lang-utils/data-class";
import { NodeKeypressTesting } from "../../tui-node-keyboard";
/** Props for custom indicator component. */
export declare type IndicatorProps = {
isHighlighted: boolean;
};
/** Props for custom check box component. */
export declare type CheckBoxProps = {
isSelected: boolean;
singleSelectionMode: boolean;
};
/** Props for custom item component. */
export declare type ItemProps = {
label: string;
isHighlighted: boolean;
};
export declare class ListItem extends Data {
readonly label: string;
readonly value?: any;
readonly key: string;
private constructor();
static createImmutable(label: string, value?: any): Readonly<ListItem>;
static createFromArray(array: string[]): Readonly<ListItem>[];
}
export declare type OperateOnOneItemFn = (item: ListItem) => void;
export declare type OperateOnManyItemsFn = (items: ListItem[]) => void;
export declare type MultiSelectInputProps = {
/** Items to display in a list. Each item must be an object and have `label`. */
items: ListItem[];
/** Enable or disable whether this component can accept user input via keyboard. */
hasFocus?: boolean;
/** Enable single selection mode (default is multi selection mode). */
singleSelectionMode?: boolean;
/** Limit the max number of items to display. */
maxRows?: number;
/** Items set as selected by default. */
initialSelected?: ListItem[];
/** Index of initially highlighted item in `items` array. */
initialHighlightedIndex?: number;
/** Function to call when user selects an item. */
onSelect?: OperateOnOneItemFn;
/** Function to call when user's cursor is over an item. */
onHighlight?: OperateOnOneItemFn;
/** Function to call when user unselects an item. */
onUnselect?: OperateOnOneItemFn;
/** Function to call when user submits selected items. */
onSubmit?: OperateOnManyItemsFn;
/** Custom component to override the default indicator component. */
indicatorComponent?: React.ComponentType<IndicatorProps>;
/** Custom component to override the default check box component. */
checkboxComponent?: React.ComponentType<CheckBoxProps>;
/** Custom component to override the default item component. */
itemComponent?: React.ComponentType<ItemProps>;
/** Optional argument that enables test mode. */
testing?: NodeKeypressTesting;
};