move toggle handler to base component

This commit is contained in:
Paul Wackerow 2022-12-19 15:17:17 -08:00
parent ea069728b2
commit e335da5391
No known key found for this signature in database
GPG Key ID: BB63E296FE9CAB8D
1 changed files with 6 additions and 4 deletions

View File

@ -41,14 +41,16 @@ export const DocsLinks: FC<Props> = ({ navLinks, toggleMobileAccordion }) => {
) )
); );
}, [asPath, navLinks]); }, [asPath, navLinks]);
const handleSectionToggle = (id: string): void => {
setOpenSections(prev => ({ ...prev, [id]: !prev[id] }));
};
return ( return (
<Stack border='2px' borderColor='primary'> <Stack border='2px' borderColor='primary'>
{navLinks.map(({ id, to, items }, idx) => { {navLinks.map(({ id, to, items }, idx) => {
const split = to?.split('/'); const split = to?.split('/');
const isActive = slug && split && split[split.length - 1] === slug[slug.length - 1]; const isActive = slug && split && split[split.length - 1] === slug[slug.length - 1];
const handleToggle = () => {
setOpenSections(prev => ({ ...prev, [id]: !prev[id] }));
};
return ( return (
<Accordion key={id} index={openSections[id] ? 0 : -1} allowToggle mt='0 !important'> <Accordion key={id} index={openSections[id] ? 0 : -1} allowToggle mt='0 !important'>
<AccordionItem border='none'> <AccordionItem border='none'>
@ -62,7 +64,7 @@ export const DocsLinks: FC<Props> = ({ navLinks, toggleMobileAccordion }) => {
placeContent='flex-end' placeContent='flex-end'
bg='button-bg' bg='button-bg'
data-group data-group
onClick={handleToggle} onClick={() => handleSectionToggle(id)}
> >
<Stack <Stack
p={4} p={4}