Skip to content

Commit

Permalink
Merge branch 'develop' into feature/JNG-5993-card-representation
Browse files Browse the repository at this point in the history
  • Loading branch information
noherczeg authored Nov 11, 2024
2 parents 93489c5 + 7389c8b commit f6e5ed5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FC, ReactNode } from 'react';
import { useState, useRef, useEffect } from 'react';
import { useState, useRef, useEffect, useCallback } from 'react';
import IconButton from '@mui/material/IconButton';
import Box from '@mui/material/Box';
import { MdiIcon } from '~/components';
Expand All @@ -13,67 +13,57 @@ export const ScrollableMenu: FC<ScrollableMenuProps> = ({ children }) => {
const [showLeftButton, setShowLeftButton] = useState(false);
const [showRightButton, setShowRightButton] = useState(false);

useEffect(() => {
if (menuRef.current) {
const container = menuRef.current;
setShowLeftButton(container.scrollLeft > 0);
setShowRightButton(container.scrollWidth > container.clientWidth + container.scrollLeft);
}
}, [showLeftButton, showRightButton]);

const handleScroll = () => {
if (menuRef.current) {
const container = menuRef.current;
setShowLeftButton(container.scrollLeft > 0);
setShowRightButton(container.scrollWidth > container.clientWidth + container.scrollLeft);
}
};
const updateScrollButtons = useCallback(() => {
const content: any = menuRef.current;
setShowLeftButton(content.scrollLeft > 0);
setShowRightButton(content.scrollLeft < content.scrollWidth - content.clientWidth);
}, []);

const handleScrollLeft = () => {
if (menuRef.current) {
menuRef.current.scrollBy({
left: -200,
behavior: 'smooth',
});
}
};
const scrollContent = useCallback((direction: number) => {
const content: any = menuRef.current;
const scrollAmount = 300;
content.scrollLeft += direction * scrollAmount;
window.setTimeout(() => {
updateScrollButtons();
}, 300);
}, []);

const handleScrollRight = () => {
if (menuRef.current) {
menuRef.current.scrollBy({
left: 200,
behavior: 'smooth',
});
}
};
useEffect(() => {
updateScrollButtons();
}, []);

return (
<div
style={ {
position: 'relative',
overflowX: 'hidden',
display: 'flex',
alignItems: 'center',
width: '100%'
} }
>
<IconButton sx={ { visibility: !showLeftButton ? 'hidden' : 'visible' } } onClick={handleScrollLeft}>
<MdiIcon path="chevron-left" />
</IconButton>
<Box
sx={ {
<div style={ { flex: '0 0 auto', padding: '10px', marginRight: '5px' } }>
<IconButton sx={ {visibility: !showLeftButton ? 'hidden' : 'visible'} } onClick={() => scrollContent(-1)}>
<MdiIcon path="chevron-left" />
</IconButton>
</div>
<div
ref={menuRef}
style={ {
display: 'flex',
overflowX: 'hidden',
WebkitOverflowScrolling: 'touch',
overflow: 'hidden',
flex: '1 1 auto',
whiteSpace: 'nowrap',
scrollBehavior: 'smooth',
} }
ref={menuRef}
onScroll={handleScroll}
>
<Box sx={ { display: 'flex', flexDirection: 'row' } }>{children}</Box>
</Box>
<IconButton sx={ { visibility: !showRightButton ? 'hidden' : 'visible' } } onClick={handleScrollRight}>
<MdiIcon path="chevron-right" />
</IconButton>
<Box sx={ { display: 'flex', flexDirection: 'row', alignItems: 'center' } }>
{children}
</Box>
</div>
<div style={ { flex: '0 0 auto', padding: '10px', marginLeft: '5px' } }>
<IconButton sx={ { visibility: !showRightButton ? 'hidden' : 'visible' } } onClick={() => scrollContent(1)}>
<MdiIcon path="chevron-right" />
</IconButton>
</div>
</div>
);
};
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<node-version>22.11.0</node-version>
<pnpm-version>9.12.3</pnpm-version>

<judo-meta-ui-version>1.1.0.20241107_161838_edc54d33_feature_JNG_5993_card_representation</judo-meta-ui-version>
<judo-meta-ui-version>1.1.0.20241108_101226_9e56a9c2_develop</judo-meta-ui-version>
<judo-generator-commons-version>1.0.0.20240923_095240_119ac3cd_develop</judo-generator-commons-version>
<judo-ui-typescript-rest-version>1.0.0.20241018_172421_24e62e7f_bugfix_JNG_5962_aggregation_validation</judo-ui-typescript-rest-version>

Expand Down

0 comments on commit f6e5ed5

Please sign in to comment.