/* eslint-disable react/jsx-props-no-spreading */ import { FocusTrapWrapper } from "@opentripplanner/building-blocks"; import React, { useState } from "react"; import { Marker, PopupOptions } from "react-map-gl/maplibre"; import { LeafletStyleMarker, Popup } from "./styled"; type Props = React.ComponentPropsWithoutRef & { autoOffset?: number; popupContents?: React.ReactNode; popupProps?: PopupOptions; position: [number, number]; tooltipContents?: React.ReactNode; }; /** * A MapLibre marker with a connected popup or tooltip */ const MarkerWithPopup = ({ autoOffset, children, popupContents, popupProps, position, tooltipContents }: Props): JSX.Element => { const [showPopup, setShowPopup] = useState(false); const [showTooltip, setShowTooltip] = useState(false); return ( // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore setShowPopup(true)} style={{ cursor: popupContents ? "pointer" : "inherit" }} > setShowTooltip(true)} onMouseLeave={() => setShowTooltip(false)} > {children || } {/** TODO: adjust tooltip styling? */} {showTooltip && tooltipContents && ( {tooltipContents} )} {showPopup && popupContents && ( setShowPopup(false)} > setShowPopup(false)} id="map-popup" > {popupContents} )} ); }; export default MarkerWithPopup;