UNPKG

4.46 kBTypeScriptView Raw
1import PropTypes from 'prop-types';
2import React, { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent, SyntheticEvent } from 'react';
3import { noop } from '../utils';
4import type { Option, SelectEvent, TypeaheadProps, TypeaheadState } from '../types';
5type Props = TypeaheadProps;
6declare class Typeahead extends React.Component<Props, TypeaheadState> {
7 static propTypes: {
8 allowNew: PropTypes.Requireable<NonNullable<boolean | ((...args: any[]) => any) | null | undefined>>;
9 autoFocus: PropTypes.Requireable<boolean>;
10 caseSensitive: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
11 defaultInputValue: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
12 defaultOpen: PropTypes.Requireable<boolean>;
13 defaultSelected: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
14 filterBy: PropTypes.Requireable<NonNullable<string[] | ((...args: any[]) => any) | null | undefined>>;
15 highlightOnlyResult: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
16 id: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
17 ignoreDiacritics: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
18 labelKey: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
19 maxResults: PropTypes.Requireable<number>;
20 minLength: PropTypes.Requireable<number>;
21 multiple: PropTypes.Requireable<boolean>;
22 onBlur: PropTypes.Requireable<(...args: any[]) => any>;
23 onChange: PropTypes.Requireable<(...args: any[]) => any>;
24 onFocus: PropTypes.Requireable<(...args: any[]) => any>;
25 onInputChange: PropTypes.Requireable<(...args: any[]) => any>;
26 onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
27 onMenuToggle: PropTypes.Requireable<(...args: any[]) => any>;
28 onPaginate: PropTypes.Requireable<(...args: any[]) => any>;
29 open: PropTypes.Requireable<boolean>;
30 options: PropTypes.Validator<(NonNullable<string | object | null | undefined> | null | undefined)[]>;
31 paginate: PropTypes.Requireable<boolean>;
32 selected: (props: TypeaheadProps, propName: keyof TypeaheadProps, componentName: string) => void;
33 };
34 static defaultProps: {
35 allowNew: boolean;
36 autoFocus: boolean;
37 caseSensitive: boolean;
38 defaultInputValue: string;
39 defaultOpen: boolean;
40 defaultSelected: never[];
41 filterBy: never[];
42 highlightOnlyResult: boolean;
43 ignoreDiacritics: boolean;
44 labelKey: string;
45 maxResults: number;
46 minLength: number;
47 multiple: boolean;
48 onBlur: typeof noop;
49 onFocus: typeof noop;
50 onInputChange: typeof noop;
51 onKeyDown: typeof noop;
52 onMenuToggle: typeof noop;
53 onPaginate: typeof noop;
54 paginate: boolean;
55 };
56 state: TypeaheadState;
57 inputNode: HTMLInputElement | null;
58 isMenuShown: boolean;
59 items: Option[];
60 componentDidMount(): void;
61 componentDidUpdate(prevProps: Props, prevState: TypeaheadState): void;
62 render(): React.JSX.Element;
63 blur: () => void;
64 clear: () => void;
65 focus: () => void;
66 getInput: () => HTMLInputElement | null;
67 inputRef: (inputNode: HTMLInputElement | null) => void;
68 setItem: (item: Option, position: number) => void;
69 hideMenu: () => void;
70 toggleMenu: () => void;
71 _handleActiveIndexChange: (activeIndex: number) => void;
72 _handleActiveItemChange: (activeItem: Option) => void;
73 _handleBlur: (e: FocusEvent<HTMLInputElement>) => void;
74 _handleChange: (selected: Option[]) => void;
75 _handleClear: () => void;
76 _handleClick: (e: MouseEvent<HTMLInputElement>) => void;
77 _handleFocus: (e: SyntheticEvent<HTMLInputElement>) => void;
78 _handleInitialItemChange: (initialItem?: Option) => void;
79 _handleInputChange: (e: ChangeEvent<HTMLInputElement>) => void;
80 _handleKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;
81 _handleMenuItemSelect: (option: Option, e: SelectEvent<HTMLElement>) => void;
82 _handlePaginate: (e: SelectEvent<HTMLElement>) => void;
83 _handleSelectionAdd: (option: Option) => void;
84 _handleSelectionRemove: (selection: Option) => void;
85}
86export default Typeahead;