Skip to content

Commit

Permalink
[Chore]: Add onClickControlBtn prop to MapControlButton to pass addit…
Browse files Browse the repository at this point in the history
…ional callbacks (#2235)

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
igorDykhta and heshan0131 committed Jun 9, 2023
1 parent 9712615 commit ed5cb8a
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/components/src/map/map-legend-panel.tsx
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React, {ComponentType, useState} from 'react';
import React, {ComponentType, useCallback, useState} from 'react';
import styled from 'styled-components';

import {Legend} from '../common/icons';
Expand Down Expand Up @@ -77,6 +77,7 @@ export type MapLegendPanelProps = {
offsetRight?: number;
onToggleSplitMapViewport?: ActionHandler<typeof toggleSplitMapViewport>;
isViewportUnsyncAllowed?: boolean;
onClickControlBtn?: (e?: MouseEvent) => void;
};

function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
Expand All @@ -96,29 +97,37 @@ function MapLegendPanelFactory(MapControlTooltip, MapControlPanel, MapLegend) {
mapHeight,
offsetRight,
onToggleSplitMapViewport,
onClickControlBtn,
isViewportUnsyncAllowed = true
}) => {
const mapLegend = mapControls?.mapLegend || ({} as MapControlItem);
const {active: isPinned} = mapLegend || {};

const onClick = () => {
const onClick = useCallback(() => {
onClickControlBtn?.();
if (mapControls?.mapDraw?.active) {
onToggleMapControl('mapDraw');
}
};
}, [onClickControlBtn, onToggleMapControl, mapControls]);
const [tippyInstance, setTippyInstance] = useState(null);
const onCloseClick = e => {
e.preventDefault();
onToggleMapControl('mapLegend');
};
const onPinClick = e => {
e.preventDefault();
if (tippyInstance) {
// @ts-ignore
tippyInstance.hide();
}
onToggleMapControl('mapLegend');
};
const onCloseClick = useCallback(
e => {
e.preventDefault();
onToggleMapControl('mapLegend');
},
[onToggleMapControl]
);
const onPinClick = useCallback(
e => {
e.preventDefault();
if (tippyInstance) {
// @ts-ignore
tippyInstance.hide();
}
onToggleMapControl('mapLegend');
},
[tippyInstance, onToggleMapControl]
);

if (!mapLegend.show) {
return null;
Expand Down

0 comments on commit ed5cb8a

Please sign in to comment.