mirror of
https://github.com/jambonz/next-static-site.git
synced 2025-12-19 04:47:44 +00:00
* Initial refactor of jambonz-ui package library * Delete public/fonts directory * Jambonz UI test-app and some refinements * next lint * working on jambonz ui docs * Update package.json * Update package.json * Update package.json * Create package.json * typescript * Update components.tsx * Update components.tsx * Update utils.ts * Update icons.ts * Update components.tsx * Update components.tsx * Update icons.ts * Update components.tsx * Update _icons.scss * Update components.tsx * Update components.tsx * fix some thangs and compile all * wrap up the docs * Update tsconfig.json * icons refactor * refine docs * update readmes * update readme * fix props interfaces and test in TS app * Update components.tsx * button up some things * change package name... * include readme in pkg dist * use published package
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
import Link from 'next/link';
|
|
import { useRouter } from 'next/router';
|
|
|
|
import { useState } from 'react';
|
|
import { nanoid } from 'nanoid';
|
|
import { classNames, Icon } from 'jambonz-ui';
|
|
|
|
import { Icons } from './icons';
|
|
import { TextLayout } from './layout';
|
|
|
|
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 ? <Icons.ChevronDown /> : <Icons.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} name={scope} />
|
|
</div>
|
|
</div>
|
|
);
|
|
} |