Skip to content

Commit

Permalink
refactor: simplify sticky
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Oct 23, 2023
1 parent bed0d1a commit 78ed334
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions frontend/src/component/common/Sticky/Sticky.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { StickyContext } from './StickyContext';
import { styled } from '@mui/material';

const StyledSticky = styled('div', {
shouldForwardProp: (prop) => prop !== 'top' && prop !== 'zIndex',
})<{ top?: number; zIndex?: number }>(({ theme, top, zIndex }) => ({
shouldForwardProp: (prop) => prop !== 'top',
})<{ top?: number }>(({ theme, top }) => ({
position: 'sticky',
zIndex: zIndex ?? theme.zIndex.sticky - 100,
zIndex: theme.zIndex.sticky - 100,
...(top !== undefined
? {
'&': {
Expand All @@ -34,7 +34,6 @@ export const Sticky = ({ children, ...props }: IStickyProps) => {
null,
);
const [top, setTop] = useState<number>();
const [zIndex, setZIndex] = useState<number>();

if (!context) {
throw new Error(
Expand All @@ -52,11 +51,6 @@ export const Sticky = ({ children, ...props }: IStickyProps) => {
setInitialTopOffset(
parseInt(getComputedStyle(ref.current).getPropertyValue('top')),
);
setZIndex(
parseInt(
getComputedStyle(ref.current).getPropertyValue('z-index'),
),
);
}
}, []);

Expand All @@ -79,7 +73,7 @@ export const Sticky = ({ children, ...props }: IStickyProps) => {
}, [ref, registerStickyItem, unregisterStickyItem]);

return (
<StyledSticky ref={ref} top={top} zIndex={zIndex} {...props}>
<StyledSticky ref={ref} top={top} {...props}>
{children}
</StyledSticky>
);
Expand Down

0 comments on commit 78ed334

Please sign in to comment.