homeflowjs 0.11.1 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import L from 'leaflet';
4
- import { MapContainer, TileLayer, Marker } from 'react-leaflet';
4
+ import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
5
5
 
6
- const BranchLeafletMap = ({ iconConfig }) => {
6
+ const BranchLeafletMap = ({ iconConfig, CustomPopup }) => {
7
7
  const branch = Homeflow.get('branch');
8
8
 
9
9
  const defaultIconConfig = {
@@ -25,17 +25,25 @@ const BranchLeafletMap = ({ iconConfig }) => {
25
25
  attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
26
26
  url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
27
27
  />
28
- <Marker position={[branch.lat, branch.lng]} icon={icon} />
28
+ <Marker position={[branch.lat, branch.lng]} icon={icon}>
29
+ {CustomPopup && (
30
+ <Popup>
31
+ <CustomPopup branch={branch} />
32
+ </Popup>
33
+ )}
34
+ </Marker>
29
35
  </MapContainer>
30
36
  );
31
37
  };
32
38
 
33
39
  BranchLeafletMap.propTypes = {
34
40
  iconConfig: PropTypes.object,
41
+ CustomPopup: PropTypes.elementType,
35
42
  };
36
43
 
37
44
  BranchLeafletMap.defaultProps = {
38
45
  iconConfig: null,
46
+ CustomPopup: null,
39
47
  };
40
48
 
41
49
  export default BranchLeafletMap;
@@ -39,8 +39,6 @@ class BranchMap extends React.Component {
39
39
  // Should this be added to Redux?
40
40
  const branch = Homeflow.get('branch');
41
41
 
42
- // debugger;
43
-
44
42
  const options = {
45
43
  center: new google.maps.LatLng(branch.lat, branch.lng),
46
44
  mapTypeControl,
@@ -57,18 +55,34 @@ class BranchMap extends React.Component {
57
55
 
58
56
  const map = new google.maps.Map(document.getElementById('hfjs-branch-map'), options);
59
57
 
60
- new google.maps.Marker({
58
+ const marker = new google.maps.Marker({
61
59
  position: { lat: branch.lat, lng: branch.lng },
62
60
  map,
63
61
  ...(iconConfig && { icon: iconConfig.iconUrl }),
64
62
  });
63
+
64
+ const branchPopupContent = document.getElementById('branch-map-popup-template')?.innerHTML;
65
+
66
+ if (branchPopupContent) {
67
+ const infoWindow = new google.maps.InfoWindow({
68
+ content: branchPopupContent,
69
+ ariaLabel: 'Custom Popup',
70
+ });
71
+
72
+ marker.addListener('click', () => {
73
+ infoWindow.open({
74
+ anchor: marker,
75
+ map,
76
+ });
77
+ });
78
+ }
65
79
  }
66
80
 
67
81
  render() {
68
- const { google, iconConfig } = this.props;
82
+ const { google, iconConfig, CustomPopup } = this.props;
69
83
 
70
84
  if (!google) {
71
- return <LazyLeafletMap iconConfig={iconConfig} />;
85
+ return <LazyLeafletMap iconConfig={iconConfig} CustomPopup={CustomPopup} />;
72
86
  }
73
87
 
74
88
  return (
@@ -86,6 +100,7 @@ BranchMap.propTypes = {
86
100
  initGoogleMaps: PropTypes.func.isRequired,
87
101
  google: PropTypes.bool,
88
102
  iconConfig: PropTypes.object,
103
+ CustomPopup: PropTypes.elementType,
89
104
  zoomControl: PropTypes.bool,
90
105
  };
91
106
 
@@ -97,6 +112,7 @@ BranchMap.defaultProps = {
97
112
  disableStreetview: false,
98
113
  google: false,
99
114
  iconConfig: null,
115
+ CustomPopup: null,
100
116
  zoomControl: false,
101
117
  };
102
118
 
@@ -107,4 +123,4 @@ const mapDispatchToProps = {
107
123
  export default connect(
108
124
  null,
109
125
  mapDispatchToProps,
110
- )(BranchMap);
126
+ )(BranchMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,6 +14,7 @@ const PropertiesDisplay = ({
14
14
  displayType,
15
15
  infiniteScroll,
16
16
  inserts,
17
+ noResultsMessage,
17
18
  ...other
18
19
  }) => {
19
20
  const onScroll = () => {
@@ -49,9 +50,7 @@ const PropertiesDisplay = ({
49
50
  }, [properties]);
50
51
 
51
52
  if (!properties.length) {
52
- return (
53
- <p>There were no properties matching your search.</p>
54
- );
53
+ return noResultsMessage;
55
54
  }
56
55
 
57
56
  const addWrapper = displayType === 'list';
@@ -107,10 +106,12 @@ PropertiesDisplay.propTypes = {
107
106
  displayType: PropTypes.string.isRequired,
108
107
  infiniteScroll: PropTypes.bool.isRequired,
109
108
  inserts: PropTypes.array,
109
+ noResultsMessage: PropTypes.node,
110
110
  };
111
111
 
112
112
  PropertiesDisplay.defaultProps = {
113
113
  inserts: null,
114
+ noResultsMessage: <p>There were no properties matching your search.</p>,
114
115
  };
115
116
 
116
117
  const mapStateToProps = (state) => ({
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
+ import PropTypes from 'prop-types';
2
3
  import L from 'leaflet';
3
- import { MapContainer, TileLayer, Marker } from 'react-leaflet';
4
+ import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
4
5
 
5
- const PropertyLeafletMap = () => {
6
+ const PropertyLeafletMap = ({ CustomPopup }) => {
6
7
  const property = Homeflow.get('property');
7
8
  const customIcon = Homeflow.get('custom_map_icon');
8
9
 
@@ -23,9 +24,23 @@ const PropertyLeafletMap = () => {
23
24
  attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
24
25
  url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
25
26
  />
26
- <Marker position={[property.lat, property.lng]} icon={defaultIcon} />
27
+ <Marker position={[property.lat, property.lng]} icon={defaultIcon}>
28
+ {CustomPopup && (
29
+ <Popup>
30
+ <CustomPopup property={property} />
31
+ </Popup>
32
+ )}
33
+ </Marker>
27
34
  </MapContainer>
28
35
  );
29
36
  };
30
37
 
38
+ PropertyLeafletMap.propTypes = {
39
+ CustomPopup: PropTypes.elementType,
40
+ };
41
+
42
+ PropertyLeafletMap.defaultProps = {
43
+ CustomPopup: null,
44
+ };
45
+
31
46
  export default PropertyLeafletMap;
@@ -55,13 +55,29 @@ class PropertyMap extends React.Component {
55
55
  map,
56
56
  ...(iconConfig && { icon: iconConfig.iconUrl }),
57
57
  });
58
+
59
+ const propertyPopupContent = document.getElementById('property-show-map-popup-template')?.innerHTML;
60
+
61
+ if (propertyPopupContent) {
62
+ const infoWindow = new google.maps.InfoWindow({
63
+ content: propertyPopupContent,
64
+ ariaLabel: 'Custom Popup',
65
+ });
66
+
67
+ marker.addListener('click', () => {
68
+ infoWindow.open({
69
+ anchor: marker,
70
+ map,
71
+ });
72
+ });
73
+ }
58
74
  }
59
75
 
60
76
  render() {
61
- const { google, iconConfig } = this.props;
77
+ const { google, iconConfig, CustomPopup } = this.props;
62
78
 
63
79
  if (!google) {
64
- return <LazyLeafletMap iconConfig={iconConfig} />;
80
+ return <LazyLeafletMap iconConfig={iconConfig} CustomPopup={CustomPopup} />;
65
81
  }
66
82
 
67
83
  return (
@@ -79,6 +95,7 @@ PropertyMap.propTypes = {
79
95
  initGoogleMaps: PropTypes.func.isRequired,
80
96
  google: PropTypes.bool,
81
97
  iconConfig: PropTypes.object,
98
+ CustomPopup: PropTypes.elementType,
82
99
  };
83
100
 
84
101
  PropertyMap.defaultProps = {
@@ -89,6 +106,7 @@ PropertyMap.defaultProps = {
89
106
  disableStreetview: false,
90
107
  google: false,
91
108
  iconConfig: null,
109
+ CustomPopup: null,
92
110
  };
93
111
 
94
112
  const mapDispatchToProps = {
@@ -98,4 +116,4 @@ const mapDispatchToProps = {
98
116
  export default connect(
99
117
  null,
100
118
  mapDispatchToProps,
101
- )(PropertyMap);
119
+ )(PropertyMap);
@@ -26,6 +26,7 @@ const PropertyResults = ({
26
26
  infiniteScroll,
27
27
  noMap,
28
28
  inserts,
29
+ noResultsMessage,
29
30
  ...other
30
31
  }) => (
31
32
  <Router>
@@ -36,6 +37,7 @@ const PropertyResults = ({
36
37
  displayType="list"
37
38
  infiniteScroll={infiniteScroll}
38
39
  inserts={inserts}
40
+ noResultsMessage={noResultsMessage}
39
41
  {...other}
40
42
  />
41
43
  </Route>
@@ -46,6 +48,7 @@ const PropertyResults = ({
46
48
  displayType="grid"
47
49
  infiniteScroll={infiniteScroll}
48
50
  inserts={inserts}
51
+ noResultsMessage={noResultsMessage}
49
52
  {...other}
50
53
  />
51
54
  </Route>
@@ -57,6 +60,7 @@ const PropertyResults = ({
57
60
  displayType="map"
58
61
  infiniteScroll={infiniteScroll}
59
62
  inserts={inserts}
63
+ noResultsMessage={noResultsMessage}
60
64
  {...other}
61
65
  />
62
66
  ) : (
@@ -71,6 +75,7 @@ const PropertyResults = ({
71
75
  displayType="grid"
72
76
  infiniteScroll={infiniteScroll}
73
77
  inserts={inserts}
78
+ noResultsMessage={noResultsMessage}
74
79
  {...other}
75
80
  />
76
81
  </Route>
@@ -81,6 +86,7 @@ const PropertyResults = ({
81
86
  displayType="list"
82
87
  infiniteScroll={infiniteScroll}
83
88
  inserts={inserts}
89
+ noResultsMessage={noResultsMessage}
84
90
  {...other}
85
91
  />
86
92
  </Route>