diff --git a/storefront/components/Layout/Header/MobileMenu/MobileMenu.tsx b/storefront/components/Layout/Header/MobileMenu/MobileMenu.tsx index a7216ea0ce..c453549e3d 100644 --- a/storefront/components/Layout/Header/MobileMenu/MobileMenu.tsx +++ b/storefront/components/Layout/Header/MobileMenu/MobileMenu.tsx @@ -42,7 +42,7 @@ export const MobileMenu: FC = () => { initial={{ translateX: '100%' }} transition={{ duration: 0.2, type: 'tween' }} className={twJoin( - 'fixed inset-0 z-maximum flex max-h-screen flex-col gap-5 overflow-y-auto bg-background p-8 shadow-md', + 'fixed inset-0 z-maximum max-h-screen w-full overflow-y-auto overflow-x-hidden bg-background p-8 shadow-md', )} > = ({ navigationItems, const { t } = useTranslation(); const [historyMenuGroups, setHistoryMenuGroups] = useState(); const [currentMenuItems, setCurrentMenuItems] = useState(mapNavigationMenuItems(navigationItems)); + const [scope, animate] = useAnimate(); const currentGroupTitle = currentMenuItems[0].parentItem; + const handleExpandClick = (navigationItem: MenuItem) => { + const slideAwayThenTeleportIntoViewSequence: AnimationSequence = [ + ['#animation-visible-element', { transform: 'translateX(-120%)' }, { duration: 0.2, type: 'tween' }], + ['#animation-visible-element', { transform: 'translateX(0)' }, { duration: 0 }], + ]; + + const slideIntoViewThenTeleportAwaySequence: AnimationSequence = [ + ['#animation-hidden-element', { transform: 'translateX(0)' }, { duration: 0.2, type: 'tween' }], + ['#animation-hidden-element', { transform: 'translateX(120%)' }, { duration: 0 }], + ]; + + animate(slideAwayThenTeleportIntoViewSequence); + animate(slideIntoViewThenTeleportAwaySequence); + + setHistoryMenuGroups([...(historyMenuGroups || []), currentMenuItems]); + setCurrentMenuItems(navigationItem.children!); + }; + const handleBackClick = (historyMenuGroups: MenuItem[][]) => { - const previousHistoryMenuGroups = [...historyMenuGroups].pop()!; + const teleportAwayThenSlideIntoViewSequence: AnimationSequence = [ + ['#animation-visible-element', { transform: 'translateX(-120%)' }, { duration: 0 }], + ['#animation-visible-element', { transform: 'translateX(0)' }, { duration: 0.2, type: 'tween' }], + ]; + const teleportIntoViewThenSlideAwaySequence: AnimationSequence = [ + ['#animation-hidden-element', { transform: 'translateX(0)' }, { duration: 0 }], + ['#animation-hidden-element', { transform: 'translateX(120%)' }, { duration: 0.2, type: 'tween' }], + ]; + + animate(teleportAwayThenSlideIntoViewSequence); + animate(teleportIntoViewThenSlideAwaySequence); + const previousHistoryMenuGroups = [...historyMenuGroups].pop()!; setCurrentMenuItems(previousHistoryMenuGroups); setHistoryMenuGroups(historyMenuGroups.slice(0, -1)); }; return ( - <> -
+
+
{!!historyMenuGroups?.length && (
-
- {currentMenuItems.map((navigationItem) => ( - { - setHistoryMenuGroups([...(historyMenuGroups || []), currentMenuItems]); - setCurrentMenuItems(navigationItem.children!); - }} - /> - ))} -
+ + + - +
+ ); +}; + +const MenuItems: FC<{ + id: string; + menuItems: MenuItem[]; + onExpand: (item: MenuItem) => void; + onNavigate: () => void; +}> = ({ className, id, menuItems, onExpand, onNavigate }) => { + return ( +
+ {menuItems.map((navigationItem) => ( + onExpand(navigationItem)} + onNavigate={onNavigate} + /> + ))} +
); }; diff --git a/storefront/components/Layout/Header/MobileMenu/MobileMenuListItem.tsx b/storefront/components/Layout/Header/MobileMenu/MobileMenuListItem.tsx index b080701fa2..fc4c601b10 100644 --- a/storefront/components/Layout/Header/MobileMenu/MobileMenuListItem.tsx +++ b/storefront/components/Layout/Header/MobileMenu/MobileMenuListItem.tsx @@ -13,7 +13,7 @@ export const DropdownMenuListItem: FC = ({ navigationItem const isWithChildren = !!navigationItem.children?.length; return ( -
+
= ({ onNavigate }) => { const { wishlist } = useWishlist(); return ( -
+
{t('Stores')}