Skip to content

Commit

Permalink
Refactor MapControls position
Browse files Browse the repository at this point in the history
Lets use true/false props here for position which makes the code a lot easier.

Also fixes the visibility of the button on desktop.
  • Loading branch information
tordans committed Mar 17, 2022
1 parent b1e7354 commit 5dc47a0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/apps/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const MapView = ({
calculatePopupPosition={calculatePopupPosition}
>
{!isEmbedMode && (
<MapControl position="top-right">
<MapControl top right>
<StyledFMBLogo width={67} />
</MapControl>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components2/Article/FullscreenMap/FullscreenMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const FullscreenMap: React.FC<FullscreenMapProps> = ({
if (isFullscreen) {
return (
<FullscreenWrapper id="FullscreenMap">
<MapControl position="top-right" visible={!showLegend}>
<MapControl top right visible={isDesktopView || !showLegend}>
<ClosePanelButton
onClick={() => setFullscreen(false)}
controlsId="FullscreenMap"
Expand All @@ -90,7 +90,7 @@ export const FullscreenMap: React.FC<FullscreenMapProps> = ({
<MapWrapper>
<BaseMap {...mapProps} onInit={setMap} />
</MapWrapper>
<MapControl position="top-left">
<MapControl top left>
<FloatingLegendIcon
showLegend={showLegend}
setShowLegend={setShowLegend}
Expand Down
11 changes: 3 additions & 8 deletions src/components2/MapsControls/LocatorMapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import React from 'react';
import { LocatorButton, LocatorButtonProps } from './LocatorButton';
import { MapcControlProps, MapControl } from './MapControl';

type Props = MapcControlProps & LocatorButtonProps;
type Props = Pick<MapcControlProps, 'className' | 'style'> & LocatorButtonProps;

export const LocatorMapControl: React.VFC<Props> = ({
position = 'top-left',
customPosition,
className,
style,
onChange,
}) => {
return (
<MapControl
position={position}
customPosition={customPosition}
className={className}
>
<MapControl style={style} className={className}>
<LocatorButton onChange={onChange} />
</MapControl>
);
Expand Down
42 changes: 14 additions & 28 deletions src/components2/MapsControls/MapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,30 @@ const StyledMapControl = styled.div`
`;

export type MapcControlProps = {
position?: 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left';
top?: boolean;
right?: boolean;
bottom?: boolean;
left?: boolean;
className?: string;
style?: React.CSSProperties;
visible?: boolean;
};

export const MapControl: React.FC<MapcControlProps> = ({
position = 'top-left',
top = false,
right = false,
bottom = false,
left = false,
className,
style,
visible = true,
children,
}) => {
const positionCss = (pos) => {
switch (pos) {
case 'top-left':
return {
top: '16px',
left: '16px',
};
case 'top-right':
return {
top: '16px',
right: '16px',
};
case 'bottom-right':
return {
right: '16px',
bottom: '16px',
};
case 'bottom-left':
return {
bottom: '16px',
left: '16px',
};
default:
return {};
}
const position: React.CSSProperties = {
top: top && '16px',
right: right && '16px',
bottom: bottom && '16px',
left: left && '16px',
};

if (!visible) return null;
Expand All @@ -53,7 +39,7 @@ export const MapControl: React.FC<MapcControlProps> = ({
<StyledMapControl
data-cy="map-map-control"
className={className}
style={style || positionCss(position)}
style={style || position}
>
{children}
</StyledMapControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class LocateMeMap extends Component {
<LocatorMapControl
key="ReportsLocateMap__LocatorControl"
onChange={this.onDevicePosition}
customPosition={locatorControlPosition}
style={locatorControlPosition}
/>
)}

Expand Down

0 comments on commit 5dc47a0

Please sign in to comment.