55 sharedMediaFrameRadius ,
66 sharedMediaFrameShapeStyles ,
77} from "@/styles/mediaFrame" ;
8- import { useMemo } from "react" ;
8+ import { forwardRef , useMemo } from "react" ;
99
10- import Map , { AttributionControl } from "react-map-gl/maplibre" ;
10+ import Map , { AttributionControl , type MapRef } from "react-map-gl/maplibre" ;
1111import "maplibre-gl/dist/maplibre-gl.css" ;
1212import { useLocale } from "next-intl" ;
1313
@@ -17,45 +17,48 @@ import { handleMapError } from "@/features/map/lib/mapErrors";
1717import { createProtomapsStyle } from "@/features/map/lib/protomapsStyle" ;
1818import { usePreferredMapFlavor } from "@/features/map/hooks/usePreferredMapFlavor" ;
1919
20+ type MapThumbnailProps = {
21+ height ?: number | string ;
22+ children ?: ReactNode ;
23+ } & Omit < ComponentProps < typeof Map > , "children" | "style" | "mapStyle" > ;
24+
2025const MapContainer = styled . div `
2126 ${ sharedMediaFrameShapeStyles }
2227 ${ sharedMediaFrameBorderStyles }
2328 background-color: ${ theme . colors . background . map } ;
2429 position: relative;
2530` ;
2631
27- export default function MapThumbnail ( {
28- height = "300" ,
29- children,
30- ...props
31- } : {
32- height ?: number | string ;
33- children ?: ReactNode ;
34- } & Omit < ComponentProps < typeof Map > , "children" | "style" | "mapStyle" > ) {
35- const locale = useLocale ( ) ;
36- const mapFlavor = usePreferredMapFlavor ( ) ;
37- const mapStyle = useMemo (
38- ( ) => createProtomapsStyle ( { flavorName : mapFlavor , locale } ) ,
39- [ locale , mapFlavor ]
40- ) ;
32+ const MapThumbnail = forwardRef < MapRef , MapThumbnailProps > (
33+ function MapThumbnail ( { height = "300" , children, ...props } , ref ) {
34+ const locale = useLocale ( ) ;
35+ const mapFlavor = usePreferredMapFlavor ( ) ;
36+ const mapStyle = useMemo (
37+ ( ) => createProtomapsStyle ( { flavorName : mapFlavor , locale } ) ,
38+ [ locale , mapFlavor ]
39+ ) ;
40+
41+ return (
42+ < MapContainer >
43+ < Map
44+ ref = { ref }
45+ attributionControl = { false } // Customised below
46+ mapStyle = { mapStyle }
47+ onError = { handleMapError }
48+ renderWorldCopies = { true }
49+ style = { {
50+ width : "100%" ,
51+ height : height ,
52+ borderRadius : sharedMediaFrameRadius ,
53+ } }
54+ { ...props }
55+ >
56+ < AttributionControl compact = { true } />
57+ { children }
58+ </ Map >
59+ </ MapContainer >
60+ ) ;
61+ }
62+ ) ;
4163
42- return (
43- < MapContainer >
44- < Map
45- attributionControl = { false } // Customised below
46- mapStyle = { mapStyle }
47- onError = { handleMapError }
48- renderWorldCopies = { true }
49- style = { {
50- width : "100%" ,
51- height : height ,
52- borderRadius : sharedMediaFrameRadius ,
53- } }
54- { ...props }
55- >
56- < AttributionControl compact = { true } />
57- { children }
58- </ Map >
59- </ MapContainer >
60- ) ;
61- }
64+ export default MapThumbnail ;
0 commit comments