Skip to content

Commit

Permalink
Merge pull request #1805 from Artsdatabanken/feature/header
Browse files Browse the repository at this point in the history
Ny Artsdatabanken header
  • Loading branch information
helemork authored Dec 14, 2023
2 parents ec9c87a + 4da7fc0 commit d1776f8
Show file tree
Hide file tree
Showing 15 changed files with 2,569 additions and 2,230 deletions.
4,316 changes: 2,166 additions & 2,150 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { withRouter } from "./withRouter";
import backend from "./Funksjoner/backend";
import { SettingsContext } from "./SettingsContext";
import InformasjonsVisning from "./InformasjonsVisning/InformasjonsVisning";
import Header from "./TopBar/Header";
import Headers from "./TopBar/Headers";
import Kartlag from "./Kartlag/Kartlag";
import Kart from "./Kart/LeafletTangram/Leaflet";
import metaSjekk from "./AppSettings/AppFunksjoner/metaSjekk";
Expand All @@ -23,6 +23,7 @@ import "./style/Sidebar.scss";
import "./style/InformasjonsSider.scss";
import "./style/Kartlag.scss";
import "./style/FargeMenyer.scss";
import "./style/Header.scss";
import fixerUpHack from "./fixerUpHack";
import Punkt from "./InformasjonsVisning/Punkt";
import Hjelp from "./InformasjonsVisning/Hjelp/Hjelp";
Expand Down Expand Up @@ -78,7 +79,7 @@ class App extends React.Component {
const path = this.props.location.pathname;
return (
<>
<Header
<Headers
searchFor={this.state.searchFor}
onToggleHovedMeny={this.handleToggleHovedMeny}
onSelectResult={item => {
Expand Down
11 changes: 0 additions & 11 deletions src/Funksjoner/getExternal.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/Kartlag/Breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ const Breadcrumbs = ({ isstartpage, onNavigate, meta }) => {
onNavigate("/kart");
}}
>
<Home />
NiN-Kart
</button>
</li>
{breadcrumbs.length - 1 > 0 && !showCrumbs && (
<li>
<ChevronRight />
<button
className="breadcrumb"
onClick={() => {
setShowCrumbs(!showCrumbs);
}}
Expand Down
128 changes: 128 additions & 0 deletions src/TopBar/GlobalHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React, { useEffect, useState } from "react";

/*
getJsonData, getExtraInfo, getListItems, event listeners, and toggle functions are to replace the functionality
from this file "https://design.artsdatabanken.no/script/header.js".
It is needed to build the header menu components that is used in all of Artsdatabanken.
We needed to do it this way instead of importing the script because importing the
script in a normal way made jquery stop working for some reason. It probably has something to do with the way this project
is bundled together, and fixing this was at this time considered more expensive than just copying the content like this.
If things change in the original file we will need to manually update this code as well.
*/

const getJsonData = async (url) => {
const response = await fetch(url);
return response?.json();
}

const getTitle = (item) => {
return item.Heading || item.Title;
}

const getExtraInfo = (item) => {
return item.Records.find((el) => {
return el.Label === 'MenuInfoText';
})?.Values;
}

const getTargetUrl = (item, baseUrl) => {
const spesificUrl = item.Records.find((el) => {
return el.Values[0].includes('http') || el.Values[0].includes('.no');
})?.Values[0];
return spesificUrl || baseUrl + item.Url
}

const getListItems = (itemList, baseUrl) => {
return itemList.map((item) => {
return (
<li>
<a className="header-mega-link-element" href={getTargetUrl(item, baseUrl)} target={item.Title === baseUrl ? '_self' : '_new'}>
<div className="header-mega-link-text">
<b className="header-site-name">{ getTitle(item) }</b>
<p className="header-site-description">{getExtraInfo(item)}</p>
</div>
<div className="contain-the-icon">
<div className="material-icons">{item.Title === baseUrl ? 'chevron_right' : 'open_in_new' }</div>
</div>
</a>
</li>
)
})
}

const GlobalHeader = (props) => {
const menuId = 'dropdown-header-menu',
menuUpIcon = 'menu-up-icon',
menuDownIcon = 'menu-down-icon';

const [headerMenus, setHeaderMenus] = useState();

const isOpen = (id) => {
return document.getElementById(id)?.style.display === 'block';
}

const setOpen = (id, shouldOpen) => {
document.getElementById(id).style.display = shouldOpen ? 'block' : 'none';
document.getElementById(menuUpIcon).style.display = shouldOpen ? 'inline-block' : 'none';
document.getElementById(menuDownIcon).style.display = !shouldOpen ? 'inline-block' : 'none';
}


useEffect(() => {
const closeMenu = (event) => {
if (!document.getElementById('menu-button').contains(event.target)) {
setOpen(menuId, false);
}
}

getHeaderMenus();
window.addEventListener('click', closeMenu);
return () => {
window.removeEventListener('click', closeMenu);
}
}, []);

const toggleMenu = () => {
setOpen(menuId, !isOpen(menuId));
}

const getHeaderMenus = async () => {
const baseUrl = 'https://artsdatabanken.no';
const data = await getJsonData('https://www.artsdatabanken.no/api/Content/341039');

const menus = data?.Records?.map((el, index) => {
return (
<li id={ `dropdown-list-${index}` } className="dropdown-list">
<ul>
<span className="dropdown-list-title">{ el.Values }</span>
{getListItems(el.References, baseUrl)}
</ul>
</li>
)
});

setHeaderMenus(menus);
}

return (
<header id="global-header" className="header">
<a href="https://artsdatabanken.no" className="header-logo">
<img src="https://design.artsdatabanken.no/icons/adb-logo/[email protected]" alt="Artsdatabanken" className="normal" />
</a>
<nav id="headermenu">
<button type='button' id='menu-button' className='dropdown-toggle' onClick={toggleMenu}>
Meny
<span className='material-icons dropicon' id={menuUpIcon} style={{ display: 'none' }}>expand_less</span>
<span className='material-icons dropicon' id={menuDownIcon}>expand_more</span>
</button>
<div id={menuId} style={{ display: 'none' }} className="dropdown-menu-artskart header-mega-menu">
<ul className='dropdown-menu-artskart'>
{headerMenus}
</ul>
</div>
</nav>
</header>
)
}

export default GlobalHeader;
43 changes: 0 additions & 43 deletions src/TopBar/Header.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/TopBar/Headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import TopBar from "./TopBar";
import GlobalHeader from "./GlobalHeader";

const Headers = ({ searchFor, onToggleHovedMeny, onSelectResult, history }) => {
return (
<div className="adb-dropdown-wrap">
<GlobalHeader/>
<TopBar
searchFor={searchFor}
onToggleHovedMeny={onToggleHovedMeny}
onSelectResult={onSelectResult}
history={history}
/>
</div>
);
};

export default Headers;
10 changes: 5 additions & 5 deletions src/style/App.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "./GraphicProfile.scss";
@import url("https://fonts.googleapis.com/css?family=Roboto+Condensed");
@import url("https://fonts.googleapis.com/css?family=Roboto");
@import url("https://fonts.googleapis.com/css?family=Chivo");
@import url("https://fonts.googleapis.com/css?family=Space+Mono");

/* Allow click through of events
on overlying node we can't get rid of*/
Expand Down Expand Up @@ -71,7 +71,7 @@ button {
h1,
h2,
h3 {
font-family:$font-space;
font-family:$font-chivo;
}

strong,
Expand Down Expand Up @@ -109,7 +109,7 @@ button {
margin: $gap;
margin-left: 0;
display: flex;
align-items: center;
align-items: center;
border-color: transparent;
}

Expand Down Expand Up @@ -544,7 +544,7 @@ div {

.cookiewarning {
width: $map-width;
background: $transparent-bg;
background: $transparent-bg-bright;
position: absolute;
top: $topbar-height-nin;
z-index: -1;
Expand Down
12 changes: 6 additions & 6 deletions src/style/Forside.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
top: $topbar-height-nin;
text-align: center;
position: relative;
max-height: 100vh;
overflow-y: auto;
}

/* General Stuff */
Expand Down Expand Up @@ -65,7 +67,6 @@

.frontpage_feature_block {
background: $sand-50;
font-size: 16pt;
}

.frontpage_feature_container {
Expand Down Expand Up @@ -117,9 +118,10 @@
@media only screen and (max-width: 768px) {
.frontpage_link_items .menu_item {
width: 100%;
margin: 0px;
margin: 4px;
left: 0px;
}

}

.flexit{
Expand Down Expand Up @@ -206,10 +208,8 @@
display: inline-block;
padding: 0px;
margin: 0px;
top: 20px;
right: 20px;
top: 12px;
right: 12px;
position: absolute;
top: 20px;
right: calc(50% - 100px);
}
}
9 changes: 5 additions & 4 deletions src/style/GraphicProfile.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$fresh-water-blue: #005B72;
$fresh-water-blue: #005B72;
$fresh-water-blue-medium: #017590;
$fresh-water-blue-light: #0283a1; // Ferskvannblå
$fresh-water-blue-80: #337B8D;
Expand Down Expand Up @@ -28,7 +28,8 @@ $dark-nin: hsla(189, 12%, 18%, 1); //#4b909e;
$medium-nin: hsla(189, 12%, 24%, 1); // #81b2bb;
$bright-nin: hsla(189, 12%, 31%, 1); //#b7d3d8;
$brightest-nin:$sand-10; //hsla(189, 30, 95, 1); // #edf4f5;
$transparent-bg:#fff7eb9e;// #0222286e;
$transparent-bg:rgba(0,0,0,0.5);// #0222286e;
$transparent-bg-bright:#fff7eb8a;// ;
$focus-color: $fresh-water-blue-light;
/* FUN COLOURS */
$fun-bg-1: #bce0ce;
Expand Down Expand Up @@ -82,7 +83,7 @@ $active-border: 2px solid black !important;
$fontfamily: $font-chivo;

/* Relative heights of menu items */
$nin-header: 48px;
$nin-header: 44px;
$topbar-height-nin: 96px;
$mobile_slide_up_area: 60px; // closed version
$ux-page-area: $topbar-height-nin;
Expand All @@ -107,4 +108,4 @@ $top-pad: 5px;
$top-icon-height: 40px;

$base-size:8px;
$border-button-radius: 30px;;
$border-button-radius: 30px;;
Loading

0 comments on commit d1776f8

Please sign in to comment.