@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
100 lines • 4.22 kB
TypeScript
/** @packageDocumentation
* @module AutoSuggest
*/
import "./AutoSuggest.scss";
import * as React from "react";
import ReactAutosuggest from "react-autosuggest";
import type { CommonProps } from "../utils/Props.js";
/** Data for the [[AutoSuggest]] options
* @public
* @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.
*/
export interface AutoSuggestData {
/** Value of [[AutoSuggest]] option. */
value: string;
/** Label of [[AutoSuggest]] option. This is shown in the dropdown. */
label: string;
}
/** Prototype for function returning AutoSuggestData
* @public
* @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.
*/
export type GetAutoSuggestDataFunc = (value: string) => AutoSuggestData[];
/** Prototype for async function returning AutoSuggestData
* @public
* @deprecated in 4.16.0. Used in a deprecated interface {@link AutoSuggestProps}.
*/
export type AsyncGetAutoSuggestDataFunc = (value: string) => Promise<AutoSuggestData[]>;
/** Properties for the [[AutoSuggest]] component.
* @public
* @deprecated in 4.16.0. Props of deprecated {@link AutoSuggest} component.
*/
export interface AutoSuggestProps extends React.InputHTMLAttributes<HTMLInputElement>, CommonProps {
/** Optional input value override. */
value?: string;
/** Options for dropdown. */
options?: AutoSuggestData[] | GetAutoSuggestDataFunc;
/** Asynchronously calculate suggestions for any given input value. */
getSuggestions?: AsyncGetAutoSuggestDataFunc;
/** Gets a label associated with a given value */
getLabel?: (value: string | undefined) => string;
/** Handler for when suggested selected. */
onSuggestionSelected: (selected: AutoSuggestData) => void;
/** Handler for Enter key. */
onPressEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
/** Handler for Escape key. */
onPressEscape?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
/** Handler for Tab key. */
onPressTab?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
/** Handler for input receiving focus. */
onInputFocus?: (e: React.FocusEvent<HTMLInputElement>) => void;
/** Called every time you need to clear suggestions. */
onSuggestionsClearRequested?: () => void;
/** Indicates whether to set focus to the input element */
setFocus?: boolean;
/** Use it only if you need to customize the rendering of the input.
* @internal
*/
renderInputComponent?: any;
/** Use it if you want to customize things inside the suggestions container beyond rendering the suggestions themselves.
* @internal
*/
renderSuggestionsContainer?: ReactAutosuggest.RenderSuggestionsContainer;
/** @internal */
alwaysRenderSuggestions?: boolean;
}
interface AutoSuggestState {
inputValue: string;
suggestions: AutoSuggestData[];
}
/** Auto Suggest React component. Uses the react-autosuggest component internally.
* @public
* @deprecated in 4.16.0. Use {@link https://itwinui.bentley.com/ iTwinUI components} instead.
*/
export declare class AutoSuggest extends React.PureComponent<AutoSuggestProps, AutoSuggestState> {
private _isMounted;
constructor(props: AutoSuggestProps);
componentDidMount(): void;
componentWillUnmount(): void;
/** @internal */
componentDidUpdate(prevProps: AutoSuggestProps): void;
private _onChange;
private _onFocus;
/** Autosuggest will call this function every time you need to update suggestions. */
private _onSuggestionsFetchRequested;
/** Autosuggest will call this function every time you need to clear suggestions. */
private _onSuggestionsClearRequested;
private _onSuggestionSelected;
/** Teach Autosuggest how to calculate suggestions for any given input value. */
private _getSuggestions;
/** When suggestion is clicked, Autosuggest needs to populate the input based on the clicked suggestion. */
private _getSuggestionValue;
/** Render each suggestion. */
private _renderSuggestion;
private getLabel;
private _handleKeyDown;
private _theme;
render(): React.ReactElement;
}
export {};
//# sourceMappingURL=AutoSuggest.d.ts.map