import { Box, chakra, Flex } from '@chakra-ui/react';
import { t } from '@/i18n';
import { isSectionCurrent } from '@/lib/navCurrent';
import type { NavMenuEvent } from '@/lib/navMenuState';
import type { NavItem } from '@/navigation';
import RouterLink from '../RouterLink';
import ChevronIcon from './ChevronIcon';
type MobileNavGroupProps = {
item: NavItem & { children: readonly NavItem[] };
// Id of the sub-list, for aria-controls
id: string;
open: boolean;
pathname: string;
dispatch: (event: NavMenuEvent) => void;
};
// Exact: only the page itself is current (BR-NAV-01), also with a query
const exactActive = { exact: true, includeSearch: false } as const;
const duration = '0.3s';
const easing = 'cubic-bezier(.22, .61, .36, 1)';
// The parent row of the mobile menu: the link to the overview, a chevron
// button and an expandable list of sub-pages (BR-NAV-30..36)
export default function MobileNavGroup({
item,
id,
open,
pathname,
dispatch,
}: MobileNavGroupProps) {
return (
<>
dispatch({ type: 'linkChosen' })}
display="block"
fontFamily="heading"
fontSizeAdjust="0.43"
fontSize="1.9rem"
color={isSectionCurrent(item, pathname) ? 'accent' : 'ink'}
_currentPage={{ color: 'accent' }}
>
{item.label}
dispatch({ type: 'toggleGroup' })}
>
{/* Grid rows 0fr to 1fr animate the height without measuring. On
close the visibility switches only after the collapse, so the
collapse is seen; collapsed links are neither focusable nor
read (BR-NAV-36). */}
{item.children.map((child) => (
dispatch({ type: 'linkChosen' })
}
display="flex"
alignItems="center"
minH="44px"
fontFamily="heading"
fontSizeAdjust="0.43"
fontSize="1.4rem"
color="ink"
// accent.deep: 1.4rem is not large text
_currentPage={{ color: 'accent.deep' }}
>
{child.label}
))}
>
);
}