Here you go. For anyone using react. If you make the Marker a separate component you can use this.
class MarkerWithInfoWindow extends React.Component {
constructor() {
super();
this.state = {
isOpen: false,
out: false,
in: false
}
}
componentDidMount() {
document.addEventListener('mousedown', this.handleClickOutside);
}
onToggleOpen = () => {
this.setState({
isOpen: !this.state.isOpen
});
}
setWrapperRef = (node) => {
this.wrapperRef = node;
}
handleClickOutside = (event) => {
if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
this.onToggleOpen();
}
}
render() {
return (<Marker
position={this.props.position}
onClick={this.onToggleOpen}>
{this.state.isOpen && <InfoWindow style={{ borderRadius: '25px'}} >
<div
ref={this.setWrapperRef}
style={{ borderRadius: '25px', backgroundColor: `white`, marginTop: 0, width: '250px', height: '350px' }}>
<Grid container >
<Grid item style={{height: '60%', }}>
<img src={GameImage} style={{ borderTopLeftRadius: '25px', borderTopRightRadius: '25px', position: 'absolute', top: 0, left:0, width: '100%'}}/>
</Grid>
</Grid>
<Grid container >
<Grid item xs={6} style={{position: 'absolute', top: '50%'}}>
<Typography variant="h6" gutterBottom>
Name of Game
</Typography>
</Grid>
</Grid>
</div>
</InfoWindow>}
</Marker>)
}
}`