Skip to content

Commit d0f1fef

Browse files
committed
add burger menu animation
1 parent 8776802 commit d0f1fef

File tree

2 files changed

+73
-23
lines changed

2 files changed

+73
-23
lines changed

src/navigation-bar.css.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,23 @@ export const burgerMenu = style([
316316
}),
317317
{
318318
height: `calc(100vh - ${NAVBAR_HEIGHT_MOBILE}px)`,
319-
overflowY: 'auto',
320319
},
321320
]);
322321

322+
export const burgerMainMenuContainer = style({
323+
height: `calc(100vh - ${NAVBAR_HEIGHT_MOBILE}px)`,
324+
overflowY: 'auto',
325+
});
326+
327+
export const burgerSubMenuContainer = style({
328+
height: `calc(100vh - ${NAVBAR_HEIGHT_MOBILE}px)`,
329+
overflowY: 'auto',
330+
width: '100%',
331+
position: 'absolute',
332+
left: '100vw',
333+
top: 0,
334+
});
335+
323336
export const iconButtonVariants = styleVariants({
324337
default: [
325338
sprinkles({color: colorVars.colors.neutralHigh}),

src/navigation-bar.tsx

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ const MainNavigationBarBurgerMenu = ({
255255
const {isDarkMode} = useTheme();
256256
const [openedSection, setOpenedSection] = React.useState(-1);
257257
const menuRef = React.useRef<HTMLDivElement>(null);
258+
const menuContentRef = React.useRef<HTMLDivElement>(null);
258259

259260
const shadowAlpha = isDarkMode ? 1 : 0.2;
260261

@@ -269,6 +270,8 @@ const MainNavigationBarBurgerMenu = ({
269270
: {...interactiveProps, onNavigate: () => closeMenu()};
270271
};
271272

273+
const [isSubMenuOpen, setIsSubMenuOpen] = React.useState(false);
274+
272275
const renderSection = (index: number) => {
273276
const {title, menu, ...interactiveProps} = sections[index];
274277
const columns = menu?.columns || [];
@@ -279,7 +282,7 @@ const MainNavigationBarBurgerMenu = ({
279282
<Stack space={16}>
280283
<NavigationBar
281284
title={texts.backNavigationBar || t(tokens.backNavigationBar)}
282-
onBack={() => setOpenedSection(-1)}
285+
onBack={() => setIsSubMenuOpen(false)}
283286
topFixed={false}
284287
withBorder={false}
285288
/>
@@ -331,7 +334,10 @@ const MainNavigationBarBurgerMenu = ({
331334
<CSSTransition
332335
onEntered={() => setDisableFocusTrap(false)}
333336
onExiting={() => setDisableFocusTrap(true)}
334-
onExited={() => setOpenedSection(-1)}
337+
onExited={() => {
338+
setIsSubMenuOpen(false);
339+
setOpenedSection(-1);
340+
}}
335341
classNames={styles.burgerMenuTransition}
336342
in={open}
337343
nodeRef={menuRef}
@@ -346,26 +352,57 @@ const MainNavigationBarBurgerMenu = ({
346352
id={id}
347353
ref={menuRef}
348354
>
349-
{openedSection !== -1 ? (
350-
renderSection(openedSection)
351-
) : (
352-
<ResponsiveLayout>
353-
<ResetResponsiveLayout>
354-
<RowList>
355-
{sections.map(({title, menu, ...interactiveProps}, index) => (
356-
<Row
357-
key={index}
358-
title={title}
359-
{...(menu
360-
? {onPress: () => setOpenedSection(index)}
361-
: getInteractivePropsWithCloseMenu(interactiveProps))}
362-
/>
363-
))}
364-
</RowList>
365-
</ResetResponsiveLayout>
366-
{extra && <Box paddingY={16}>{extra}</Box>}
367-
</ResponsiveLayout>
368-
)}
355+
<CSSTransition
356+
timeout={isRunningAcceptanceTest() ? 0 : BURGER_MENU_ANIMATION_DURATION_MS}
357+
in={isSubMenuOpen}
358+
nodeRef={menuContentRef}
359+
>
360+
{(transitionStatus) => (
361+
<div
362+
ref={menuContentRef}
363+
style={{
364+
transition: `transform ${isRunningAcceptanceTest() ? 0 : BURGER_MENU_ANIMATION_DURATION_MS}ms ease-out`,
365+
transform: `translate(${isSubMenuOpen ? '-100vw' : '0vw'})`,
366+
}}
367+
>
368+
{transitionStatus !== 'entered' && (
369+
<div className={styles.burgerMainMenuContainer}>
370+
<ResponsiveLayout>
371+
<ResetResponsiveLayout>
372+
<RowList>
373+
{sections.map(
374+
({title, menu, ...interactiveProps}, index) => (
375+
<Row
376+
key={index}
377+
title={title}
378+
{...(menu
379+
? {
380+
onPress: () => {
381+
setIsSubMenuOpen(true);
382+
setOpenedSection(index);
383+
},
384+
}
385+
: getInteractivePropsWithCloseMenu(
386+
interactiveProps
387+
))}
388+
/>
389+
)
390+
)}
391+
</RowList>
392+
</ResetResponsiveLayout>
393+
{extra && <Box paddingY={16}>{extra}</Box>}
394+
</ResponsiveLayout>
395+
</div>
396+
)}
397+
398+
{transitionStatus !== 'exited' && openedSection !== -1 && (
399+
<div className={styles.burgerSubMenuContainer}>
400+
{renderSection(openedSection)}
401+
</div>
402+
)}
403+
</div>
404+
)}
405+
</CSSTransition>
369406
</nav>
370407
</FocusTrap>
371408
</CSSTransition>

0 commit comments

Comments
 (0)