|
1 | 1 | import React, { useRef, useEffect } from 'react';
|
2 |
| -import PropTypes from 'prop-types' |
| 2 | +import PropTypes from 'prop-types'; |
3 | 3 |
|
4 | 4 | function createPopupClass() {
|
5 | 5 | function Popup({ position, content, map }) {
|
@@ -40,35 +40,40 @@ function createPopupClass() {
|
40 | 40 | return Popup;
|
41 | 41 | }
|
42 | 42 |
|
43 |
| -const CustomPopup = ({ map, position, children, visible, google }) => { |
| 43 | +const CustomPopup = ({ map, position, children, visible, google, className }) => { |
44 | 44 | const containerEl = useRef(null);
|
45 | 45 | useEffect(() => {
|
46 | 46 | 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(); |
49 | 49 | new Popup({
|
50 |
| - position: pos, |
51 |
| - content: containerEl.current, |
52 |
| - map, |
53 |
| - }); |
| 50 | + position: pos, |
| 51 | + content: containerEl.current, |
| 52 | + map |
| 53 | + }); |
54 | 54 | }
|
55 | 55 | }, [map]);
|
56 | 56 | return (
|
57 |
| - <div style={{ position: 'absolute' }} ref={containerEl}> |
| 57 | + <div |
| 58 | + className={className} |
| 59 | + style={{ position: 'absolute' }} |
| 60 | + ref={containerEl} |
| 61 | + > |
58 | 62 | {visible && children}
|
59 | 63 | </div>
|
60 | 64 | );
|
61 | 65 | };
|
62 | 66 |
|
63 | 67 | CustomPopup.propTypes = {
|
| 68 | + google: PropTypes.object, |
| 69 | + className: PropTypes.string, |
64 | 70 | children: PropTypes.element.isRequired,
|
65 | 71 | map: PropTypes.object,
|
66 |
| - marker: PropTypes.object, |
67 | 72 | position: PropTypes.object,
|
68 |
| - visible: PropTypes.bool, |
69 |
| -} |
| 73 | + visible: PropTypes.bool |
| 74 | +}; |
70 | 75 |
|
71 | 76 | CustomPopup.defaultProps = {
|
72 | 77 | visible: true
|
73 |
| -} |
| 78 | +}; |
74 | 79 | export default CustomPopup;
|
0 commit comments