Skip to content

Commit

Permalink
fix: the visible height of the table container
Browse files Browse the repository at this point in the history
  • Loading branch information
devgustavosantos committed Jul 20, 2024
1 parent 3d0661b commit 0d48466
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
26 changes: 26 additions & 0 deletions src/components/CustomSimpleBar/hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect, useRef, useState } from 'react';

function useCustomSimpleBar() {
const [scrollBarMaxHeight, setScrollBarMaxHeight] = useState(0);
const scrollBarContainer = useRef<HTMLDivElement | null>(null);

useEffect(() => {
function handleResize() {
if (!scrollBarContainer?.current) return;

setScrollBarMaxHeight(scrollBarContainer.current.offsetHeight);
}

handleResize();

window.addEventListener('resize', handleResize);

return () => {
window.removeEventListener('resize', handleResize);
};
}, []);

return { scrollBarMaxHeight, scrollBarContainer };
}

export { useCustomSimpleBar };
9 changes: 7 additions & 2 deletions src/components/CustomSimpleBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import 'simplebar-react/dist/simplebar.min.css';
import { useCustomSimpleBar } from './hook';
import * as S from './styles';
import { CustomSimpleBarProps } from './types';

export function CustomSimpleBar({ children }: CustomSimpleBarProps) {
const { scrollBarContainer, scrollBarMaxHeight } = useCustomSimpleBar();

return (
<S.Container>
<S.Wrapper>{children}</S.Wrapper>
<S.Container ref={scrollBarContainer}>
<S.Wrapper style={{ maxHeight: scrollBarMaxHeight }}>
{children}
</S.Wrapper>
</S.Container>
);
}
11 changes: 1 addition & 10 deletions src/components/CustomSimpleBar/styles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import SimpleBar from 'simplebar-react';
import { styled } from 'styled-components';

import { BREAKPOINTS } from '../../styles/breakpoints';

const Container = styled.div`
position: relative;
width: 100%;
height: 100%;
flex-grow: 1;
overflow: hidden;
`;
Expand All @@ -15,7 +15,6 @@ const Wrapper = styled(SimpleBar)`
top: 0;
left: 0;
width: 100%;
height: 100%;
.simplebar-scrollbar::before {
background-color: ${({ theme }) => theme.GRAY_800};
Expand All @@ -37,14 +36,6 @@ const Wrapper = styled(SimpleBar)`
height: 6rem;
}
}
@media only screen and (max-width: ${BREAKPOINTS.SMALL}) {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
`;

export { Container, Wrapper };
7 changes: 6 additions & 1 deletion src/pages/History/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled, { css } from 'styled-components';

import { Wrapper as SimpleBar } from '../../components/CustomSimpleBar/styles';
import { TaskStatusProps } from './types';
import { statusColors } from './utils';

Expand All @@ -23,6 +24,10 @@ const Container = styled.div`
max-width: 932rem;
&:has(${TBody}:empty) {
${SimpleBar} {
height: 100%;
}
.simplebar-content-wrapper {
overflow: hidden;
background-color: ${({ theme }) => theme.BLACK_700};
Expand Down Expand Up @@ -116,7 +121,7 @@ const TaskStatus = styled.td<TaskStatusProps>`
display: block;
border-radius: 50%;
background-color: ${({ theme, situation }) =>
theme[statusColors[situation]]};
theme[statusColors[situation]]};
}
`;

Expand Down

0 comments on commit 0d48466

Please sign in to comment.