-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fc5fa3
commit 44abf61
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState, useEffect, useRef } from "@wordpress/element"; | ||
import { __ } from "@wordpress/i18n"; | ||
import { TextControl } from "@wordpress/components"; | ||
|
||
export default ({ onPlaceSelected, value }) => { | ||
const inputRef = useRef(null); | ||
|
||
const [location, setLocation] = useState(value); | ||
|
||
|
||
console.log( location ); | ||
useEffect(() => { | ||
if (inputRef.current && window.google) { | ||
const autocomplete = new window.google.maps.places.Autocomplete( | ||
inputRef.current, | ||
{ | ||
types: ["geocode"], // You can restrict the types of predictions | ||
}, | ||
); | ||
|
||
autocomplete.addListener("place_changed", () => { | ||
const place = autocomplete.getPlace(); | ||
setLocation(place.formatted_address); | ||
onPlaceSelected(place); | ||
}); | ||
} | ||
}, []); | ||
Check failure on line 27 in assets/js/geo-location/panel/AutoCompleteField.js GitHub Actions / ES Lint
|
||
|
||
return ( | ||
<> | ||
<TextControl | ||
ref={inputRef} | ||
type="text" | ||
label={__("Address", "elasticpress-labs")} | ||
placeholder={__("Enter an address", "elasticpress-labs")} | ||
value={location} | ||
onChange={(value) => setLocation(value)} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters