-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
203 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useCallback, useContext } from "react"; | ||
import { MapContext } from "../contexts"; | ||
import useClientHeight from "../useClientHeight"; | ||
import Metadata from "./Metadata"; | ||
import TabNav from "./TabNav"; | ||
import MediaQuery from "react-responsive"; | ||
import { HD_SIZE } from "../../../constants"; | ||
import { createPortal } from "react-dom"; | ||
import { Button, Icon } from "react-bulma-components"; | ||
|
||
export function DesktopSidebar({ data }) { | ||
const { height, ref } = useClientHeight(); | ||
const { sidebar } = useContext(MapContext); | ||
return ( | ||
<div id="sidebar" className={!sidebar ? "" : ""}> | ||
<Metadata {...data.data} metadataRef={ref} /> | ||
<TabNav map={data} top={height} /> | ||
</div> | ||
); | ||
} | ||
|
||
export function MobileSidebar({ data }) { | ||
const { height, ref } = useClientHeight(); | ||
const { sidebar, setSidebar } = useContext(MapContext); | ||
|
||
const onClose = useCallback(() => setSidebar(false), [setSidebar]); | ||
|
||
if (!sidebar) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div id="sidebar-mobile"> | ||
<div id="sidebar-close"> | ||
<Button onClick={onClose}> | ||
<Icon> | ||
<i className="fas fa-times"></i> | ||
</Icon> | ||
</Button> | ||
</div> | ||
<Metadata {...data.data} metadataRef={ref} /> | ||
<TabNav map={data} top={height} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default function Sidebar({ data }) { | ||
return ( | ||
<> | ||
<MediaQuery maxWidth={HD_SIZE}> | ||
{createPortal( | ||
<MobileSidebar data={data} />, | ||
document.getElementById("sidebar-portal"), | ||
)} | ||
</MediaQuery> | ||
<MediaQuery minWidth={HD_SIZE}> | ||
<DesktopSidebar data={data} /> | ||
</MediaQuery> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useCallback, useContext } from "react"; | ||
import { Button, Icon } from "react-bulma-components"; | ||
import MediaQuery from "react-responsive"; | ||
import { HD_SIZE } from "../../../constants"; | ||
import { MapContext } from "../contexts"; | ||
|
||
export default function SidebarWidget() { | ||
const { setSidebar } = useContext(MapContext); | ||
|
||
const open = useCallback(() => setSidebar(true), [setSidebar]); | ||
|
||
return ( | ||
<MediaQuery maxWidth={HD_SIZE}> | ||
<div id="sidebar-open"> | ||
<Button onClick={open}> | ||
<Icon> | ||
<i className="fas fa-bars"></i> | ||
</Icon> | ||
</Button> | ||
</div> | ||
</MediaQuery> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useMemo, useState } from "react"; | ||
import useClientHeight from "../useClientHeight"; | ||
import { Content, Tabs } from "react-bulma-components"; | ||
import Layers from "./LayersVTree"; | ||
import parse from "html-react-parser"; | ||
|
||
const TABS = { | ||
kartlag: { | ||
label: "Kartlag", | ||
render: (map) => <Layers layers={map.data.layers} />, | ||
}, | ||
beskrivelse: { | ||
label: "Beskrivelse", | ||
render: (map) => <Content px={2}>{parse(map.data.description)}</Content>, | ||
}, | ||
}; | ||
|
||
export default function TabNav({ map, top = 0 }) { | ||
const [active, setActive] = useState("kartlag"); | ||
|
||
const { height, ref } = useClientHeight(); | ||
|
||
const render = useMemo(() => TABS[active].render(map), [active, map]); | ||
|
||
return ( | ||
<> | ||
<Tabs fullwidth mt={3} domRef={ref}> | ||
{Object.keys(TABS).map((k) => ( | ||
<Tabs.Tab active={k === active} key={k} onClick={() => setActive(k)}> | ||
{TABS[k].label} | ||
</Tabs.Tab> | ||
))} | ||
</Tabs> | ||
<div style={{ height: `calc(100vh - ${height + top}px)` }}>{render}</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.