|
| 1 | +/* global google */ |
| 2 | +import React from "react" |
| 3 | +import ReactDOM from "react-dom" |
| 4 | +import PropTypes from "prop-types" |
| 5 | + |
| 6 | +import { |
| 7 | + construct, |
| 8 | + componentDidMount, |
| 9 | + componentDidUpdate, |
| 10 | + componentWillUnmount, |
| 11 | +} from "../../utils/MapChildHelper" |
| 12 | + |
| 13 | +import { SEARCH_BOX } from "../../constants" |
| 14 | + |
| 15 | +export const __jscodeshiftPlaceholder__ = `{ |
| 16 | + "eventMapOverrides": { |
| 17 | + }, |
| 18 | + "getInstanceFromComponent": "this.state[SEARCH_BOX]" |
| 19 | +}` |
| 20 | + |
| 21 | +/** |
| 22 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox |
| 23 | + */ |
| 24 | +class SearchBox extends React.PureComponent { |
| 25 | + static displayName = "StandaloneSearchBox" |
| 26 | + |
| 27 | + static propTypes = { |
| 28 | + __jscodeshiftPlaceholder__: null, |
| 29 | + } |
| 30 | + |
| 31 | + state = { |
| 32 | + [SEARCH_BOX]: null, |
| 33 | + } |
| 34 | + |
| 35 | + componentDidMount() { |
| 36 | + const element = ReactDOM.findDOMNode(this) |
| 37 | + /* |
| 38 | + * @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox |
| 39 | + */ |
| 40 | + const searchBox = new google.maps.places.SearchBox(element) |
| 41 | + construct(SearchBox.propTypes, updaterMap, this.props, searchBox) |
| 42 | + |
| 43 | + componentDidMount(this, searchBox, eventMap) |
| 44 | + this.setState({ |
| 45 | + [SEARCH_BOX]: searchBox, |
| 46 | + }) |
| 47 | + } |
| 48 | + |
| 49 | + componentDidUpdate(prevProps) { |
| 50 | + componentDidUpdate( |
| 51 | + this, |
| 52 | + this.state[SEARCH_BOX], |
| 53 | + eventMap, |
| 54 | + updaterMap, |
| 55 | + prevProps |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + componentWillUnmount() { |
| 60 | + componentWillUnmount(this) |
| 61 | + } |
| 62 | + |
| 63 | + render() { |
| 64 | + return React.Children.only(this.props.children) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export const StandaloneSearchBox = SearchBox |
| 69 | + |
| 70 | +export default StandaloneSearchBox |
| 71 | + |
| 72 | +const eventMap = {} |
| 73 | + |
| 74 | +const updaterMap = {} |
0 commit comments