Merge pull request #72 from twentyhq/cbo-horizontal-scroll

Add horizontal scroll on tables
This commit is contained in:
Charles Bochet
2023-04-25 12:16:12 +02:00
committed by GitHub
3 changed files with 60 additions and 43 deletions

View File

@ -21,7 +21,8 @@ type OwnProps<TData> = {
}; };
const StyledTable = styled.table` const StyledTable = styled.table`
min-width: calc(100% - ${(props) => props.theme.spacing(4)}); min-width: 1000px;
width: calc(100% - ${(props) => props.theme.spacing(4)});
border-radius: 4px; border-radius: 4px;
border-spacing: 0; border-spacing: 0;
border-collapse: collapse; border-collapse: collapse;
@ -61,6 +62,13 @@ const StyledTableWithHeader = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
flex: 1; flex: 1;
width: 100%;
`;
const StyledTableScrollableContainer = styled.div`
overflow: auto;
height: 100%;
flex: 1;
`; `;
function Table<TData>({ function Table<TData>({
@ -85,6 +93,7 @@ function Table<TData>({
onSortsUpdate={onSortsUpdate} onSortsUpdate={onSortsUpdate}
sortsAvailable={sortsAvailable || []} sortsAvailable={sortsAvailable || []}
/> />
<StyledTableScrollableContainer>
<StyledTable> <StyledTable>
<thead> <thead>
{table.getHeaderGroups().map((headerGroup) => ( {table.getHeaderGroups().map((headerGroup) => (
@ -108,7 +117,10 @@ function Table<TData>({
{row.getVisibleCells().map((cell) => { {row.getVisibleCells().map((cell) => {
return ( return (
<td key={cell.id}> <td key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())} {flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</td> </td>
); );
})} })}
@ -118,7 +130,8 @@ function Table<TData>({
{table {table
.getFooterGroups() .getFooterGroups()
.flatMap((group) => group.headers) .flatMap((group) => group.headers)
.filter((header) => !!header.column.columnDef.footer).length > 0 && ( .filter((header) => !!header.column.columnDef.footer).length >
0 && (
<tfoot> <tfoot>
{table.getFooterGroups().map((footerGroup) => ( {table.getFooterGroups().map((footerGroup) => (
<tr key={footerGroup.id}> <tr key={footerGroup.id}>
@ -137,6 +150,7 @@ function Table<TData>({
</tfoot> </tfoot>
)} )}
</StyledTable> </StyledTable>
</StyledTableScrollableContainer>
</StyledTableWithHeader> </StyledTableWithHeader>
); );
} }

View File

@ -16,6 +16,7 @@ const StyledRightContainer = styled.div`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex: 1; flex: 1;
overflow: hidden;
`; `;
type OwnProps = { type OwnProps = {

View File

@ -12,6 +12,7 @@ const StyledContainer = styled.div`
display: flex; display: flex;
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
overflow: hidden;
`; `;
const ContentContainer = styled.div` const ContentContainer = styled.div`
@ -21,6 +22,7 @@ const ContentContainer = styled.div`
flex: 1; flex: 1;
padding-right: ${(props) => props.theme.spacing(3)}; padding-right: ${(props) => props.theme.spacing(3)};
padding-bottom: ${(props) => props.theme.spacing(3)}; padding-bottom: ${(props) => props.theme.spacing(3)};
width: calc(100% - ${(props) => props.theme.spacing(3)});
`; `;
const ContentSubContainer = styled.div` const ContentSubContainer = styled.div`