Files
next-static-site/components/markdown.js
T
Brandon Lee Kitajchuk db94b17829 Latest news + banner, cypress tests, open source copy, general style tweaks (#13)
* 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>
2021-07-22 12:34:01 -04:00

91 lines
2.7 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 { Icon, TextLayout } from './jambonz-ui';
function MarkdownSidebar({scope, data}) {
const router = useRouter();
const regex = new RegExp(`^/${scope}/|^/+|/+$`, 'g');
const parsedTab = router.asPath.replace(regex, '').split('/').shift();
const parsedPath = router.asPath.replace(/^\/+|\/+$/g, '').split('/').pop();
const [active, setActive] = useState({
[parsedTab]: true,
});
const handleToggle = (slug) => {
setActive((oldActive) => {
const newActive = {};
for (let i in oldActive) {
newActive[i] = oldActive[i];
}
newActive[slug] = newActive[slug] ? false : true;
return newActive;
});
};
return (
<nav className="markdown__navi">
<div className="markdown__link">
<Link href={data.root.link}>
<a className="m">
<strong>{data.root.label}</strong>
</a>
</Link>
</div>
<ul className="markdown__list">
{data.navi.map((item) => {
const isActiveToggle = (active[item.path] ? true : false);
const subClasses = {
'markdown__sublist': true,
'active': isActiveToggle,
};
return (
<li key={nanoid()} className="markdown__item">
<div className="m markdown__label" onClick={() => handleToggle(item.path)}>
{isActiveToggle ? <Icon name="ChevronDown" /> : <Icon name="ChevronRight" />}
<strong>{item.title}</strong>
</div>
<ul className={classNames(subClasses)}>
{item.pages.map((page) => {
const isActiveItem = (parsedPath === page.path && parsedTab === item.path) && isActiveToggle;
const itemClasses = {
'ms': true,
'active': isActiveItem,
};
return (
<li key={nanoid()} className="markdown__subitem">
<Link href={`/${scope}/${item.path}/${page.path}`}>
<a className={classNames(itemClasses)}>{page.title}</a>
</Link>
</li>
);
})}
</ul>
</li>
);
})}
</ul>
</nav>
);
}
export default function Markdown({scope, data, docs}) {
return (
<div className="markdown">
<div className="wrap markdown__wrap">
<MarkdownSidebar scope={scope} data={data} />
<TextLayout data={docs} />
</div>
</div>
);
}