Skip to content

Commit e7acc9f

Browse files
committed
improve styles of custom overlay
1 parent cb25dcd commit e7acc9f

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

examples/components/withCustomOverlay.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ const WithCustomOverlay = (props) => {
1919
<CustomOverlay
2020
position={{ lat: 37.782551, lng: -122.425368 }}
2121
visible={showOverlay}
22+
className={styles.overlayContainer}
2223
>
23-
<div className={styles.overlayContainer}>
24-
Hi there. I'm a custom overlay.
25-
</div>
24+
<div>Hi there. I'm a custom overlay.</div>
2625
</CustomOverlay>
2726
</Map>
2827
</Fragment>

examples/components/withCustomOverlay.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
background-color: white;
33
padding: 20px;
44
border-radius: 10px;
5+
transform: translate(-50%, -100%);
56
}
67

78
.button {

src/components/CustomOverlay.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useRef, useEffect } from 'react';
2-
import PropTypes from 'prop-types'
2+
import PropTypes from 'prop-types';
33

44
function createPopupClass() {
55
function Popup({ position, content, map }) {
@@ -40,35 +40,40 @@ function createPopupClass() {
4040
return Popup;
4141
}
4242

43-
const CustomPopup = ({ map, position, children, visible, google }) => {
43+
const CustomPopup = ({ map, position, children, visible, google, className }) => {
4444
const containerEl = useRef(null);
4545
useEffect(() => {
4646
if (map) {
47-
const pos = new google.maps.LatLng(position.lat, position.lng);
48-
const Popup = createPopupClass();
47+
const pos = new google.maps.LatLng(position.lat, position.lng);
48+
const Popup = createPopupClass();
4949
new Popup({
50-
position: pos,
51-
content: containerEl.current,
52-
map,
53-
});
50+
position: pos,
51+
content: containerEl.current,
52+
map
53+
});
5454
}
5555
}, [map]);
5656
return (
57-
<div style={{ position: 'absolute' }} ref={containerEl}>
57+
<div
58+
className={className}
59+
style={{ position: 'absolute' }}
60+
ref={containerEl}
61+
>
5862
{visible && children}
5963
</div>
6064
);
6165
};
6266

6367
CustomPopup.propTypes = {
68+
google: PropTypes.object,
69+
className: PropTypes.string,
6470
children: PropTypes.element.isRequired,
6571
map: PropTypes.object,
66-
marker: PropTypes.object,
6772
position: PropTypes.object,
68-
visible: PropTypes.bool,
69-
}
73+
visible: PropTypes.bool
74+
};
7075

7176
CustomPopup.defaultProps = {
7277
visible: true
73-
}
78+
};
7479
export default CustomPopup;

0 commit comments

Comments
 (0)