Skip to content

Commit

Permalink
feat: fix Control component
Browse files Browse the repository at this point in the history
  • Loading branch information
ob6160 committed Jan 11, 2022
1 parent 0160bc6 commit dd64b72
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/components/Control/Control.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import L from 'leaflet';
import React from 'react';
import ReactDOM from 'react-dom';

const POSITION_CLASSES = {
bottomleft: 'leaflet-bottom leaflet-left',
bottomright: 'leaflet-bottom leaflet-right',
topleft: 'leaflet-top leaflet-left',
topright: 'leaflet-top leaflet-right',
};

const Control = (props): JSX.Element => {
const [container, setContainer] = React.useState<any>(
document.createElement('div')
);
const positionClass =
(props.position && POSITION_CLASSES[props.position]) ||
POSITION_CLASSES.topright;

React.useEffect(() => {
const targetDiv = document.getElementsByClassName(positionClass);
setContainer(targetDiv[0]);
}, [positionClass]);

const controlContainer = (
<div className="leaflet-control leaflet-bar">{props.children}</div>
);

L.DomEvent.disableClickPropagation(container);

return ReactDOM.createPortal(controlContainer, container);
};

export default Control;
4 changes: 3 additions & 1 deletion src/components/LooMap/LooMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ const LooMap: React.FC<LooMapProps> = ({
{mapState.focus && <CurrentLooMarker loo={mapState.focus} />}
<Markers />

<LocateMapControl position="bottomright" />

<Media greaterThan="md">
<ZoomControl position="bottomright" />
</Media>
<LocateMapControl position="bottomright" />

<MapTracker />
</MapContainer>
</Box>
Expand Down
2 changes: 0 additions & 2 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState, useRef } from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import isPropValid from '@emotion/is-prop-valid';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand Down Expand Up @@ -53,7 +52,6 @@ const Sidebar = () => {
const [isFiltersExpanded, setIsFiltersExpanded] = useState(false);
const filterToggleRef = useRef(null);
const [mapState, setMapState] = useMapState();
const { filters } = mapState;

return (
<section aria-labelledby="heading-search">
Expand Down

0 comments on commit dd64b72

Please sign in to comment.