Skip to content

Commit 1a73a83

Browse files
committed
bump 1.3.0 add typescript annotations
1 parent df719bb commit 1a73a83

File tree

3 files changed

+56
-13
lines changed

3 files changed

+56
-13
lines changed

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## React google autocomplete
22

3-
This is a simple react component for working with google [autocomplete](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete)
3+
This is a simple react component for working with google [autocomplete](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete)
44

55
## Install
66

@@ -13,37 +13,54 @@ As of version 1.2.4, you can now pass an `apiKey` prop to automatically load the
1313
```js
1414
<AutoComplete
1515
apiKey={YOUR_GOOGLE_MAPS_API_KEY}
16-
onPlaceSelected={() => 'do something on select'}
16+
onPlaceSelected={() => "do something on select"}
1717
/>
1818
```
1919

2020
Alternatively if not passing the `apiKey` prop, you can include google autocomplete link api in your app. Somewhere in index.html or somewhere else.
2121

2222
```html
23-
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[YOUR_API_KEY]&libraries=places"></script>
23+
<script
24+
type="text/javascript"
25+
src="https://maps.googleapis.com/maps/api/js?key=[YOUR_API_KEY]&libraries=places"
26+
></script>
2427
```
2528

2629
## Example
2730

2831
```js
29-
import Autocomplete from 'react-google-autocomplete';
32+
import Autocomplete from "react-google-autocomplete";
3033

3134
<Autocomplete
32-
style={{width: '90%'}}
33-
onPlaceSelected={(place) => {
34-
console.log(place);
35-
}}
36-
types={['(regions)']}
37-
componentRestrictions={{country: "ru"}}
38-
/>
35+
style={{ width: "90%" }}
36+
onPlaceSelected={(place) => {
37+
console.log(place);
38+
}}
39+
types={["(regions)"]}
40+
componentRestrictions={{ country: "ru" }}
41+
/>;
42+
```
43+
44+
## Typescript
45+
46+
We are planning on adding a full support for TS and Flow in the later releases.
47+
48+
```js
49+
import Autocomplete, {
50+
ReactGoogleAutocomplete,
51+
} from "react-google-autocomplete";
52+
53+
const AutocompleteTS: FC<ReactGoogleAutocomplete> = Autocomplete as FC<ReactGoogleAutocomplete>;
54+
55+
<AutocompleteTS key="123" />
3956
```
4057

4158
The component has one function called `onPlaceSelected`. The function gets invoked every time a user chooses location.
4259
A `types` props means type of places in [google place API](https://developers.google.com/places/web-service/autocomplete#place_types). By default it uses (cities).
4360
A [componentRestrictions](https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions) prop by default is empty.
4461
A [bounds](https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions) prop by default is empty.
4562
You also can pass any props you want to the final input. You can also set [fields](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceResult) prop if you need extra information, now it defaults to basic data in order to control expenses.
46-
The `options`(optional) prop is the optional configuration to your Autocomplete instance. You can see full options [here](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete)
63+
The `options`(optional) prop is the optional configuration to your Autocomplete instance. You can see full options [here](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete)
4764

4865
## Contribution
4966

index.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type OptionType = {
2+
componentRestrictions?: {};
3+
bounds?: {};
4+
location?: {};
5+
offset?: number;
6+
origin?: {};
7+
radius?: number;
8+
sessionToken?: {};
9+
types?: string[];
10+
};
11+
12+
export interface ReactGoogleAutocomplete {
13+
onPlaceSelected?: (
14+
places: Record<string, unknown>,
15+
ref: HTMLInputElement
16+
) => void;
17+
types?: string[];
18+
componentRestrictions?: {};
19+
bounds?: {};
20+
fields?: string[];
21+
inputAutocompleteValue?: string;
22+
options?: OptionType;
23+
apiKey?: string;
24+
style?: CSSStyleDeclaration;
25+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "react-google-autocomplete",
3-
"version": "1.2.6",
3+
"version": "1.3.0",
44
"description": "React component for google autocomplete.",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"build": "babel src/ --out-dir lib"

0 commit comments

Comments
 (0)