mirror of
https://github.com/jambonz/next-static-site.git
synced 2025-12-19 04:47:44 +00:00
* Adding latest news and banners * Adding first draft of cypress specs and github actions workflow * Adding sticky position for top banner * Tweak styles for new latest news section * Tweak styles for text__layout innerHTML * Fix Cypress homepage test spec * Fix mobile navi z-index with sticky top banner * Fix sticky banner z-index bug with mobile navi * Refactor markdown tools to support pages beyond developer docs * Adjust TADHACK text max-widths for small mobile * initial changes for open source copy * more copy * more copy * updated open source structure * minor * typo * more copy * Adjust styles for Open Source markdown small text * Update readme and remove floats from docs webhooks markdown * Add readme notes on Cypress and flesh out navi spec tests * Fix main navi highlight when on sub-sections of markdown pages Co-authored-by: Dave Horton <daveh@beachdognet.com>
114 lines
3.1 KiB
JavaScript
114 lines
3.1 KiB
JavaScript
import { useState } from 'react';
|
|
import { nanoid } from 'nanoid';
|
|
import classNames from 'classnames';
|
|
|
|
import Link from 'next/link';
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { Button, Icon, useMobileMedia } from './jambonz-ui';
|
|
|
|
function NaviItem({obj}) {
|
|
const router = useRouter();
|
|
const rSlash = /^\/|\/$/g;
|
|
const cleanLink = obj.link.replace(rSlash, '');
|
|
const cleanPath = router.asPath.replace(rSlash, '').split('/')[0];
|
|
const classes = {
|
|
navi__link: true,
|
|
active: cleanLink && cleanLink === cleanPath,
|
|
};
|
|
|
|
return (
|
|
<li>
|
|
<Link href={obj.link}>
|
|
<a target={obj.open ? '_blank' : null} className={classNames(classes)}>
|
|
{obj.label}
|
|
</a>
|
|
</Link>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
function NaviMobile({ active, handler, siteData }) {
|
|
const classes = {
|
|
'bg-jambonz': true,
|
|
'wrap': true,
|
|
'navi__mobile': true,
|
|
'active': active,
|
|
};
|
|
|
|
return (
|
|
<div className={classNames(classes)}>
|
|
<div className="navi__mobile__head">
|
|
<div className="navi__mobile__login">
|
|
<Button href={siteData.navi.login.link} target="_blank" mainStyle="login" subStyle="white">
|
|
{siteData.navi.login.label}
|
|
</Button>
|
|
</div>
|
|
<div className="navi__mobile__icon" onClick={handler}>
|
|
<Icon mainStyle="fill" subStyle="white" name="X" />
|
|
</div>
|
|
</div>
|
|
<ul className="navi__mobile__links">
|
|
<NaviItem key="home" obj={siteData.navi.home} />
|
|
{siteData.navi.links.map((obj) => {
|
|
return <NaviItem key={nanoid()} obj={obj} />;
|
|
})}
|
|
</ul>
|
|
<ul className="navi__mobile__footer">
|
|
{siteData.footer.links.map((obj) => {
|
|
return <NaviItem key={nanoid()} obj={obj} />;
|
|
})}
|
|
</ul>
|
|
<div className="navi__mobile__support">
|
|
<Button href={`mailto:${siteData.footer.email}`} target="_blank" subStyle="light">
|
|
{siteData.footer.email}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function Navi({ siteData }) {
|
|
const [active, setActive] = useState(false);
|
|
const mobile = useMobileMedia();
|
|
const classes = {
|
|
navi: true,
|
|
mobile,
|
|
active,
|
|
};
|
|
|
|
const handleNavi = () => {
|
|
setActive(!active);
|
|
};
|
|
|
|
// Make sure mobile navi is closed on resizes...
|
|
if (!mobile && active) {
|
|
setActive(false);
|
|
}
|
|
|
|
return (
|
|
<nav className={classNames(classes)}>
|
|
<div className="wrap navi__wrap">
|
|
<Link href="/">
|
|
<a className="navi__logo">
|
|
<img src="/svg/jambonz.svg" width="128" />
|
|
</a>
|
|
</Link>
|
|
<ul className="navi__links">
|
|
{siteData.navi.links.map((obj) => {
|
|
return <NaviItem key={nanoid()} obj={obj} />;
|
|
})}
|
|
</ul>
|
|
<div className="navi__icon" onClick={handleNavi}>
|
|
<Icon mainStyle="fill" name="Menu" />
|
|
</div>
|
|
<div className="navi__login">
|
|
<Button href={siteData.navi.login.link} target="_blank" mainStyle="login">
|
|
{siteData.navi.login.label}
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
{mobile && <NaviMobile active={active} handler={handleNavi} siteData={siteData} />}
|
|
</nav>
|
|
);
|
|
} |