Skip to content

Commit

Permalink
add possibillity to style component
Browse files Browse the repository at this point in the history
  • Loading branch information
mbagemihl committed Jun 1, 2022
1 parent a9e7b7b commit 25de9fb
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 331 deletions.
5 changes: 3 additions & 2 deletions src/GooglePlacesAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const GooglePlacesAutocomplete: React.ForwardRefRenderFunction<GooglePlacesAutoc
apiKey = '',
apiOptions = {},
autocompletionRequest = {},
debounce = 300,
debounce = 100,
minLengthAutocomplete = 0,
selectProps = {},
onLoadFailed = console.error,
withSessionToken = false,
styles = {},
} : GooglePlacesAutocompleteProps, ref) : React.ReactElement => {
const [placesService, setPlacesService] = useState<google.maps.places.AutocompleteService | undefined>(undefined);
const [sessionToken, setSessionToken] = useState<google.maps.places.AutocompleteSessionToken | undefined>(undefined);
Expand Down Expand Up @@ -73,7 +74,7 @@ const GooglePlacesAutocomplete: React.ForwardRefRenderFunction<GooglePlacesAutoc
}, []);

return (
<AsyncSelect
<AsyncSelect styles={styles}
{...selectProps}
loadOptions={fetchSuggestions}
getOptionValue={({ value }) => value.place_id}
Expand Down
10 changes: 7 additions & 3 deletions src/GooglePlacesAutocomplete.types.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoaderOptions } from '@googlemaps/js-api-loader';
import { Props, OptionTypeBase } from 'react-select';
import {LoaderOptions} from '@googlemaps/js-api-loader';
import {OptionTypeBase, Props} from 'react-select';
import {StylesConfig} from "react-select/src/styles";

export type GooglePlacesAutocompleteHandle = {
getSessionToken: () => google.maps.places.AutocompleteSessionToken | undefined;
Expand All @@ -20,7 +21,9 @@ export interface AutocompletionRequest {
types?: string[];
}

export default interface GooglePlacesAutocompleteProps {
export default interface GooglePlacesAutocompleteProps<
OptionType extends OptionTypeBase = { label: string; value: string },
IsMulti extends boolean = false> {
apiKey?: string;
apiOptions?: Partial<LoaderOptions>;
autocompletionRequest?: AutocompletionRequest;
Expand All @@ -29,4 +32,5 @@ export default interface GooglePlacesAutocompleteProps {
onLoadFailed?: (error: Error) => void;
selectProps?: Props<OptionTypeBase>;
withSessionToken?: boolean;
styles?: StylesConfig<OptionType, IsMulti>;
}
Loading

0 comments on commit 25de9fb

Please sign in to comment.