nav auto open

This commit is contained in:
sup39 2022-11-06 16:59:26 +09:00
parent ae827f515d
commit add93b2e3e

View file

@ -13,9 +13,11 @@ export type NavEntryInfo = {
export function NavEntry<Body, >({ export function NavEntry<Body, >({
entry: {name, link, children}, dir, here, children: childrenJSX, entry: {name, link, children}, dir, here, children: childrenJSX,
}: {entry: NavEntryInfo, dir: string, here: string, children?: Body}) { }: {entry: NavEntryInfo, dir: string, here: string, children?: Body}) {
const [toggle, setToggle] = useState(false);
const href = dir+link; const href = dir+link;
const isHere = href.replace(/\/$/, '')===here; // remove trailing slash const isHere = href.replace(/\/$/, '')===here; // remove trailing slash
const isRHere = isHere || here.startsWith(href); // here or is children
const [toggle, setToggle] = useState(isRHere);
const entryCls = 'nav-entry'+(isHere ? ' nav-here' : ''); const entryCls = 'nav-entry'+(isHere ? ' nav-here' : '');
return children?.length ? <div className={'nav-dir'+(toggle ? ' nav-fold-open' : '')}><> return children?.length ? <div className={'nav-dir'+(toggle ? ' nav-fold-open' : '')}><>
<div className={entryCls}> <div className={entryCls}>