@navinc/base-react-components
Version:
Nav's Pattern Library
24 lines (23 loc) • 963 B
TypeScript
import { ChangeEventHandler, ReactElement, Ref, ReactNode } from 'react';
import { BaseStringInputProps } from '../base-string-input/base-string-input.js';
import { TargetValue } from '../shared.js';
export type BaseSearchInputChildrenProps<T> = {
shouldShowResults: boolean;
shouldShowNoResults: boolean;
query: string;
results: T[];
focusedResultIndex: number;
handleResultSelect: (result: T) => void;
};
export type BaseSearchInputProps<T> = Omit<BaseStringInputProps, 'value' | 'results' | 'children' | 'onChange'> & {
value?: T;
results: T[];
resultToQuery: (result: T) => string;
search: (query: string) => void;
isLoading?: boolean;
children: (props: BaseSearchInputChildrenProps<T>) => ReactNode;
onChange?: ChangeEventHandler<TargetValue<HTMLInputElement, T | undefined>>;
};
export declare const BaseSearchInput: <T>(p: BaseSearchInputProps<T> & {
ref?: Ref<HTMLInputElement>;
}) => ReactElement;