Files
web/apps/scandic-web/components/Maps/InteractiveMap/PoiMapMarkers/index.tsx
Anton Gunnarsson a7ac79e429 Merged in chore/sw-3145-move-caption (pull request #2503)
chore(SW-3145): Move Caption to design-system

* Move Caption to design-system

* Mark Caption as deprecated


Approved-by: Linus Flood
Approved-by: Joakim Jäderberg
2025-07-03 07:48:24 +00:00

90 lines
2.6 KiB
TypeScript

import {
AdvancedMarker,
AdvancedMarkerAnchorPoint,
} from "@vis.gl/react-google-maps"
import { useIntl } from "react-intl"
import Caption from "@scandic-hotels/design-system/Caption"
import Body from "@/components/TempDesignSystem/Text/Body"
import HotelMarkerByType from "../../Markers"
import PoiMarker from "../../Markers/Poi"
import styles from "./poiMapMarkers.module.css"
import type { PointOfInterest } from "@scandic-hotels/trpc/types/hotel"
import type { MarkerInfo } from "@scandic-hotels/trpc/types/marker"
export type PoiMapMarkersProps = {
activePoi?: string | null
coordinates: { lat: number; lng: number }
onActivePoiChange?: (poiName: string | null) => void
pointsOfInterest: PointOfInterest[]
markerInfo: MarkerInfo
}
export default function PoiMapMarkers({
coordinates,
pointsOfInterest,
onActivePoiChange,
activePoi,
markerInfo,
}: PoiMapMarkersProps) {
const intl = useIntl()
function toggleActivePoi(poiName: string) {
onActivePoiChange?.(activePoi === poiName ? null : poiName)
}
return (
<>
<AdvancedMarker position={coordinates} zIndex={1}>
<HotelMarkerByType
hotelId={markerInfo.hotelId}
hotelType={markerInfo.hotelType}
/>
</AdvancedMarker>
{pointsOfInterest.map((poi) => (
<AdvancedMarker
key={poi.name}
className={styles.advancedMarker}
position={poi.coordinates}
anchorPoint={AdvancedMarkerAnchorPoint.CENTER}
zIndex={activePoi === poi.name ? 2 : 0}
onMouseEnter={() => onActivePoiChange?.(poi.name ?? null)}
onMouseLeave={() => onActivePoiChange?.(null)}
onClick={() => toggleActivePoi(poi.name ?? "")}
>
<span
className={`${styles.poi} ${activePoi === poi.name ? styles.active : ""}`}
>
<PoiMarker
group={poi.group}
categoryName={poi.categoryName}
size={activePoi === poi.name ? 20 : 16}
/>
<Body className={styles.poiLabel} asChild>
<span>
{poi.name}
<Caption asChild>
<span>
{intl.formatMessage(
{
defaultMessage: "{distanceInKm} km",
},
{
distanceInKm: poi.distance,
}
)}
</span>
</Caption>
</span>
</Body>
</span>
</AdvancedMarker>
))}
</>
)
}