@ubilabs/react-geosuggest
Version:
A React autosuggest for the Google Maps Places API.
305 lines (297 loc) • 8.13 kB
TypeScript
/// <reference types="googlemaps" />
/// <reference types="react" />
import * as React$1 from 'react';
/**
* The suggest interface
*/
interface Suggest {
readonly description?: string;
readonly label: string;
readonly placeId: string;
readonly isFixture: boolean;
readonly location?: {
lat: number;
lng: number;
};
readonly matchedSubstrings?: {
offset: number;
length: number;
}[];
readonly className?: string;
}
interface Props$1 {
readonly value: string;
readonly className?: string;
readonly id?: string;
readonly doNotSubmitOnEnter?: boolean;
readonly ignoreEnter?: boolean;
readonly ignoreTab?: boolean;
readonly style?: any;
readonly autoComplete?: string;
readonly isSuggestsHidden: boolean;
readonly activeSuggest: Suggest | null;
readonly listId: string;
readonly label?: string;
readonly inputType: string;
readonly onChange: (value: string) => void;
readonly onSelect: () => void;
readonly onKeyDown?: (event: React$1.KeyboardEvent) => void;
readonly onKeyPress?: (event: React$1.KeyboardEvent) => void;
readonly onNext: () => void;
readonly onPrev: () => void;
readonly onEscape: () => void;
readonly onFocus: () => void;
readonly onBlur: () => void;
}
/**
* The input field
*/
declare class Input extends React$1.PureComponent<Props$1, unknown> {
/**
* Default values for the properties
*/
static defaultProps: Props$1;
/**
* The reference to the input element
*/
input: HTMLInputElement | null;
/**
* The constructor.
*/
constructor(props: Props$1);
/**
* When the input got changed
*/
onChange(): void;
/**
* When a key gets pressed in the input
*/
onInputKeyDown(event: React$1.KeyboardEvent): void;
/**
* Focus the input
*/
focus(): void;
/**
* Blur the input
*/
blur(): void;
/**
* Render the view
*/
render(): React$1.JSX.Element;
}
/**
* The fixture interface
*/
interface Fixture {
readonly label: string;
readonly placeId?: string;
readonly location?: {
lat: number;
lng: number;
};
readonly className?: string;
}
/**
* The suggest interface
*/
interface Location extends Suggest {
readonly location: {
lat: number;
lng: number;
};
readonly gmaps?: google.maps.GeocoderResult | google.maps.places.PlaceResult;
}
/**
* Prop Types
*/
interface Props {
readonly fixtures?: Fixture[];
readonly maxFixtures?: number;
readonly initialValue?: string;
readonly placeholder?: string;
readonly disabled?: boolean;
readonly id?: string;
readonly className?: string;
readonly inputClassName?: string;
readonly suggestsClassName?: string;
readonly suggestsHiddenClassName?: string;
readonly suggestItemClassName?: string;
readonly suggestItemActiveClassName?: string;
readonly location?: google.maps.LatLng;
readonly radius?: string | number;
readonly bounds?: google.maps.LatLngBounds | google.maps.LatLngBoundsLiteral;
readonly country?: string | string[];
readonly types?: string[] | null;
readonly queryDelay?: number;
readonly googleMaps?: any;
readonly highlightMatch?: boolean;
readonly onSuggestSelect?: (suggest?: Location) => void;
readonly onFocus?: () => void;
readonly onBlur?: (userInput?: string) => void;
readonly onChange?: (value: string) => void;
readonly onKeyDown?: (event: React.KeyboardEvent) => void;
readonly onKeyPress?: (event: React.KeyboardEvent) => void;
readonly onUpdateSuggests?: (suggests: Suggest[], activeSuggest: Suggest | null) => void;
readonly onActivateSuggest?: (suggest: Suggest | null) => void;
readonly onSuggestNoResults?: (userInput: string) => void;
readonly skipSuggest?: (suggest: Fixture | google.maps.places.AutocompletePrediction) => boolean;
readonly getSuggestLabel?: (suggest: google.maps.places.AutocompletePrediction) => string;
readonly renderSuggestItem?: (suggest: Suggest) => string | React.JSX.Element;
readonly autoActivateFirstSuggest?: boolean;
readonly style?: {
input?: any;
suggests?: any;
suggestItem?: any;
};
readonly ignoreTab?: boolean;
readonly ignoreEnter?: boolean;
readonly label?: string;
readonly autoComplete?: string;
readonly minLength?: number;
readonly placeDetailFields?: string[] | null;
readonly inputType?: string;
}
interface State {
readonly isSuggestsHidden: boolean;
readonly isLoading: boolean;
readonly ignoreBlur: boolean;
readonly userInput: string;
readonly activeSuggest: null | Suggest;
readonly suggests: Suggest[];
}
/**
* Entry point for the Geosuggest component
*/
declare class GeoSuggest extends React$1.Component<Props, State> {
/**
* Default values for the properties
*/
static defaultProps: Props;
/**
* The Google Map instance
*/
googleMaps: any | null;
/**
* The autocomple service to get suggests
*/
autocompleteService: google.maps.places.AutocompleteService | null;
/**
* The places service to get place details
*/
placesService: google.maps.places.PlacesService | null;
/**
* The sessionToken service to use session based monetization
*/
sessionToken: google.maps.places.AutocompleteSessionToken | undefined;
/**
* The geocoder to get geocoded results
*/
geocoder: google.maps.Geocoder | null;
/**
* A timer
*/
timer?: number;
/**
* The input component
*/
input: Input | null;
/**
* Id for the suggestions list
*/
listId: string;
/**
* Label for the suggestions list
*/
listLabel: string;
/**
* The constructor. Sets the initial state.
*/
constructor(props: Props);
/**
* Change inputValue if prop changes
*/
componentDidUpdate(prevProps: Props): void;
/**
* Called on the client side after component is mounted.
* Google api sdk object will be obtained and cached as a instance property.
* Necessary objects of google api will also be determined and saved.
*/
componentDidMount(): void;
/**
* When the component will unmount
*/
componentWillUnmount(): void;
/**
* When the input changed
*/
onInputChange(userInput: string): void;
/**
* On After the input got changed
*/
onAfterInputChange(): void;
/**
* When the input gets focused
*/
onInputFocus(): void;
/**
* When the input gets blurred
*/
onInputBlur(): void;
onNext(): void;
onPrev(): void;
onSelect(): void;
onSuggestMouseDown(): void;
onSuggestMouseOut(): void;
onSuggestNoResults(): void;
/**
* Focus the input
*/
focus(): void;
/**
* Blur the input
*/
blur(): void;
/**
* Update the value of the user input
*/
update(userInput: string): void;
clear(): void;
/**
* Search for new suggests
*/
searchSuggests(): void;
/**
* Update the suggests
*/
updateSuggests(suggestsGoogle?: google.maps.places.AutocompletePrediction[], callback?: () => void): void;
/**
* Return the new activeSuggest object after suggests have been updated
*/
updateActiveSuggest(suggests?: Suggest[]): Suggest | null;
/**
* Show the suggestions
*/
showSuggests(): void;
/**
* Hide the suggestions
*/
hideSuggests(): void;
/**
* Activate a new suggest
*/
activateSuggest(direction: 'next' | 'prev'): void;
/**
* When an item got selected
*/
selectSuggest(suggestToSelect: Suggest | null): void;
/**
* Geocode a suggest
*/
geocodeSuggest(suggestToGeocode: Suggest): void;
/**
* Render the view
*/
render(): React$1.JSX.Element;
}
export { Fixture, Location, Props, Suggest, GeoSuggest as default };