From 82835288bce93dc00f6ebb9f097f6675e4a74fe9 Mon Sep 17 00:00:00 2001 From: Andrei Grigore Date: Fri, 19 Nov 2021 12:51:30 +0200 Subject: [PATCH] NavigationLead variable items dep on width & fixed widths --- .../theme/Header/HeaderNavigation.jsx | 76 +++++-------------- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/src/components/theme/Header/HeaderNavigation.jsx b/src/components/theme/Header/HeaderNavigation.jsx index 756c5b6..7873125 100644 --- a/src/components/theme/Header/HeaderNavigation.jsx +++ b/src/components/theme/Header/HeaderNavigation.jsx @@ -11,25 +11,6 @@ import { connect } from 'react-redux'; import circleLeft from '@plone/volto/icons/circle-left.svg'; import circleRight from '@plone/volto/icons/circle-right.svg'; -const Card = ({ children, itemId }) => { - return ( -
- {children} -
- ); -}; - const MobileNav = ({ items, activeItem }) => { const [expanded, setExpanded] = React.useState(false); @@ -44,25 +25,23 @@ const MobileNav = ({ items, activeItem }) => { {items && items.length > 0 && items.map((item, i) => ( - - -

- {item.title} - {item.url === activeItem.url && ( - setExpanded(false)} - /> - )} -

- -
+ +

+ {item.title} + {item.url === activeItem.url && ( + setExpanded(false)} + /> + )} +

+ ))} ) : ( @@ -85,21 +64,6 @@ const MobileNav = ({ items, activeItem }) => { ); }; -function onWheel(apiObj, ev) { - const isThouchpad = Math.abs(ev.deltaX) !== 0 || Math.abs(ev.deltaY) < 15; - - if (isThouchpad) { - ev.stopPropagation(); - return; - } - - if (ev.deltaY < 0) { - apiObj.scrollNext(); - } else if (ev.deltaY > 0) { - apiObj.scrollPrev(); - } -} - const HeaderNavigation = ({ items, pageWidth }) => { const [activeItem, setActiveItem] = React.useState(''); const [isMobile, setIsMobile] = React.useState(false); @@ -120,9 +84,8 @@ const HeaderNavigation = ({ items, pageWidth }) => { const first = itemsIncrement * 3; const last = first + itemsPerPage; const itemsInit = items.slice(first, last); - setDisplayedItems(itemsInit); - }, [itemsIncrement]); + }, [itemsIncrement, itemsPerPage, items]); React.useEffect(() => { //init items @@ -144,6 +107,9 @@ const HeaderNavigation = ({ items, pageWidth }) => { if (pageWidth && pageWidth > 768) { setIsMobile(false); } + if (pageWidth && pageWidth > 1240) { + setItemsPerPage(7); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [items, pageWidth]);