Skip to content

Commit

Permalink
feat(places/StandaloneSearchBox): add component
Browse files Browse the repository at this point in the history
* Closes #618
* Closes #601
* Closes #593
  • Loading branch information
tomchentw committed Sep 16, 2017
1 parent 12a104b commit 51a1da5
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/macros/places/StandaloneSearchBox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* global google */
import React from "react"
import ReactDOM from "react-dom"
import PropTypes from "prop-types"

import {
construct,
componentDidMount,
componentDidUpdate,
componentWillUnmount,
} from "../../utils/MapChildHelper"

import { SEARCH_BOX } from "../../constants"

export const __jscodeshiftPlaceholder__ = `{
"eventMapOverrides": {
},
"getInstanceFromComponent": "this.state[SEARCH_BOX]"
}`

/**
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox
*/
class SearchBox extends React.PureComponent {
static displayName = "StandaloneSearchBox"

static propTypes = {
__jscodeshiftPlaceholder__: null,
}

state = {
[SEARCH_BOX]: null,
}

componentDidMount() {
const element = ReactDOM.findDOMNode(this)
/*
* @url https://developers.google.com/maps/documentation/javascript/3.exp/reference#SearchBox
*/
const searchBox = new google.maps.places.SearchBox(element)
construct(SearchBox.propTypes, updaterMap, this.props, searchBox)

componentDidMount(this, searchBox, eventMap)
this.setState({
[SEARCH_BOX]: searchBox,
})
}

componentDidUpdate(prevProps) {
componentDidUpdate(
this,
this.state[SEARCH_BOX],
eventMap,
updaterMap,
prevProps
)
}

componentWillUnmount() {
componentWillUnmount(this)
}

render() {
return React.Children.only(this.props.children)
}
}

export const StandaloneSearchBox = SearchBox

export default StandaloneSearchBox

const eventMap = {}

const updaterMap = {}

0 comments on commit 51a1da5

Please sign in to comment.