diff --git a/src/navigation-bar.tsx b/src/navigation-bar.tsx index e8701f0db..269d07b33 100644 --- a/src/navigation-bar.tsx +++ b/src/navigation-bar.tsx @@ -291,6 +291,93 @@ const burgerMenuReducer = (state: MainNavigationBarMenuStatus, action: MainNavig return mainNavigationBurgerMenuTranstions[state][action] || state; }; +const MainNavigationBarBurgerSection = ({ + section, + closeSubMenu, + closeMenu, +}: { + section: MainNavigationBarSection; + closeSubMenu: () => void; + closeMenu: () => void; +}) => { + const {texts, t} = useTheme(); + + const {title, menu, ...interactiveProps} = section; + + const columns = menu?.columns || []; + const customContent = menu?.content; + const hasCustomInteraction = + interactiveProps.href !== undefined || + interactiveProps.onPress !== undefined || + interactiveProps.to !== undefined; + + return ( + + + + + + {texts.mainNavigationBarSectionSeeAll || + t(tokens.mainNavigationBarSectionSeeAll)} + + ) : undefined + } + > + {title} + + + + {customContent ? ( + + {typeof customContent === 'function' ? customContent({closeMenu}) : customContent} + + ) : ( + columns.map((column, columnIndex) => ( + + {column.title} + + + {column.items.map( + ({title: itemTitle, ...itemInteractiveProps}, itemIndex) => ( + + ) + )} + + + + )) + )} + + + ); +}; + const MainNavigationBarBurgerMenu = ({ sections, extra, @@ -308,16 +395,15 @@ const MainNavigationBarBurgerMenu = ({ disableFocusTrap: boolean; setDisableFocusTrap: (value: boolean) => void; }) => { - const {texts, t, isDarkMode} = useTheme(); + const {isDarkMode} = useTheme(); const [openedSection, setOpenedSection] = React.useState(-1); const [isSubMenuOpen, setIsSubMenuOpen] = React.useState(false); + const [subMenuStatus, dispatch] = React.useReducer(burgerMenuReducer, 'closed'); const menuRef = React.useRef(null); const shadowAlpha = isDarkMode ? 1 : 0.2; const menuAnimationDuration = isRunningAcceptanceTest() ? 0 : styles.BURGER_MENU_ANIMATION_DURATION_MS; - const [subMenuStatus, dispatch] = React.useReducer(burgerMenuReducer, 'closed'); - React.useEffect(() => { let id: NodeJS.Timeout; @@ -333,82 +419,6 @@ const MainNavigationBarBurgerMenu = ({ return () => clearTimeout(id); }, [isSubMenuOpen, menuAnimationDuration]); - const renderSection = (index: number) => { - const {title, menu, ...interactiveProps} = sections[index]; - const columns = menu?.columns || []; - const customContent = menu?.content; - const hasCustomInteraction = - interactiveProps.href !== undefined || - interactiveProps.onPress !== undefined || - interactiveProps.to !== undefined; - - return ( - - - - setIsSubMenuOpen(false)} - topFixed={false} - withBorder={false} - /> - - {texts.mainNavigationBarSectionSeeAll || - t(tokens.mainNavigationBarSectionSeeAll)} - - ) : undefined - } - > - {sections[index].title} - - - - {customContent ? ( - - {typeof customContent === 'function' ? customContent({closeMenu}) : customContent} - - ) : ( - columns.map((column, columnIndex) => ( - - {column.title} - - - {column.items.map( - ({title: itemTitle, ...itemInteractiveProps}, itemIndex) => ( - - ) - )} - - - - )) - )} - - - ); - }; - return ( @@ -474,9 +484,13 @@ const MainNavigationBarBurgerMenu = ({ transform: `translate(${isSubMenuOpen ? '0' : '100vw'})`, }} > - {subMenuStatus !== 'closed' && - openedSection !== -1 && - renderSection(openedSection)} + {subMenuStatus !== 'closed' && openedSection !== -1 && ( + setIsSubMenuOpen(false)} + /> + )}