diff --git a/src/App.css b/src/App.css index 1894d1d..52be712 100644 --- a/src/App.css +++ b/src/App.css @@ -12,17 +12,22 @@ body { } #country-info { - display: flex; - background-color: white; + width: 100%; + background-color: rgb(179, 179, 179); z-index: 10; + position: fixed; + bottom: 0px; + padding: 0.5rem; } .country-flag { - width: 8rem; + width: 3rem; } .map-container { - position: relative; + position: sticky; + top: 0; + background-color: white; } .tools { diff --git a/src/App.tsx b/src/App.tsx index ee5132d..23b9eb9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,21 +4,12 @@ import "./App.css"; import { BrowserRouter, Route, Link, Routes } from "react-router-dom"; import { PointCountryGame } from "./pages/PointCountryGame"; import { PointCountryInfo } from "./pages/PointCountryInfo"; +import { IntroPage } from "./pages/IntroPage"; function App() { return ( <> - - + } > - }> + }> diff --git a/src/assets/Map.tsx b/src/assets/Map.tsx index 4e59001..14e8625 100644 --- a/src/assets/Map.tsx +++ b/src/assets/Map.tsx @@ -5,19 +5,23 @@ import { TransformComponent, useControls, useTransformContext, + zoom, } from "react-zoom-pan-pinch"; import { MapControls } from "../components/MapControls"; export const Map = ({ onPathClick, + selectedCountry, }: { onPathClick: (e: MouseEvent) => void; + selectedCountry: string; }) => { const MAX_SCALE = 1000; const maxStroke = 0.35; const minStroke = 0.075; const [strokeWidth, setStrokeWidth] = useState(0.07); const ref = useRef(); + const mapRef = useRef(); const onZoom = (a, b) => { const newStrokeWidth = getStrokeWidth(a.state.scale); @@ -39,7 +43,7 @@ export const Map = ({ return (
- {({ zoomIn, zoomOut, resetTransform, ...rest }) => ( + {({ zoomIn, zoomOut, resetTransform, zoomToElement, ...rest }) => ( <> ; }; export const MapControls = ({ isMaxScale, isMinScale, onZoomWithButtons, + zoomToElement, + selectedCountry, + wrapperRef, }: MapControlsProps) => { const { zoomIn, zoomOut /* resetTransform */ } = useControls(); + useEffect(() => { + const countryPath = wrapperRef?.current?.querySelector( + `[title="${selectedCountry}"]` + ); + zoomToElement(countryPath); + //(node: HTMLElement | string, scale?: number, animationTime?: number, animationType?: keyof typeof animations) => void; + }, [selectedCountry]); return (