2. Sidebar & TopToolbar
Add Sidebar-Component
-
Import Sidebar-Component:
import {Sidebar} from "@mapcomponents/react-maplibre"insrc/App.tsx. -
Add Sidebar to the JSX: The Sidebar is assigned a
nameattribute with the valueSidebar(string) and anopenattribute set to true (boolean). In later stages, it will be shown how the sidebar can easily be toggled on and off with a button.<Sidebar open={true} name={"Sidebar"}></Sidebar>
Add TopToolbar-Component
-
Import TopToolbar-Component:
import {TopToolbar} from "@mapcomponents/react-maplibre"insrc/App.tsx. -
Add TopToolbar to the JSX: We use Material UI https://mui.com/material-ui/getting-started/ - a popular React UI framework - in our project.
<TopToolbar
unmovableButtons={
<>
<Button
id="basic-button"
variant="contained"
onClick={setShowSidebar(!showSidebar)}
>
Button
</Button>
</>
}
/> -
Define a State Variable: Initiate a
state variablenamedshowSidebaras follows:import { useState } from "react";const [showSidebar, setShowSidebar] = useState(true);