import { h, type FunctionComponent } from 'preact' import { useEffect, useReducer, useRef } from 'preact/hooks' import cn from 'classnames' import NavigationItem from './navigation_item.tsx' import s from './navigation.module.scss' import type { Route } from '../../../shared/types.ts' type NavigationGroupProps = { base: string currentPath: string path: string routes: Route[] title: string } const NavigationGroup: FunctionComponent = ({ base, currentPath, path, routes, title }) => { const itemsRef = useRef(null) const [visible, toggle] = useReducer((visible, force) => (typeof force === 'boolean' ? force : !visible), false) const current = currentPath === path || (path !== '/' && currentPath.startsWith(path)) useEffect(() => { itemsRef.current!.style.height = itemsRef.current!.scrollHeight + 'px' }, []) useEffect(() => { toggle(false) }, [currentPath]) return (
  • {title}
      {routes .filter(({ nav }) => nav !== false) .map(({ path, title, routes }) => routes ? ( ) : ( ), )}
  • ) } export default NavigationGroup