move toggle handler to base component
This commit is contained in:
parent
ea069728b2
commit
e335da5391
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue