Skip to content

Commit

Permalink
TablePagination fixes & DS application (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmilan authored May 18, 2023
1 parent a3c2952 commit e1e8efd
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- TablePagination fixes & DS application [#673](https://github.com/CartoDB/carto-react/pull/673)
- Remove ReactDOMServer dependency and simplify avatar image fallback [#672](https://github.com/CartoDB/carto-react/pull/672)
- Remove @mui/styles after dumping makeStyles [#670](https://github.com/CartoDB/carto-react/pull/670)
- Add tooltip prop to ComparativeCategoryWidgetUI [#667](https://github.com/CartoDB/carto-react/pull/667)
Expand Down
97 changes: 65 additions & 32 deletions packages/react-ui/src/theme/sections/components/dataDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ICON_SIZE_MEDIUM, ICON_SIZE_LARGE, ICON_SIZE_SMALL } from '../../themeC
import { getSpacing } from '../../themeUtils';
import { commonPalette } from '../palette';
import { themeTypography } from '../typography';
import Typography from '../../../components/atoms/Typography';

const tooltipArrowSize = 1;
const tooltipSeparation = 0.5;
Expand Down Expand Up @@ -211,39 +212,65 @@ export const dataDisplayOverrides = {

// Table
MuiTablePagination: {
defaultProps: {
SelectProps: {
variant: 'outlined',
size: 'small'
},
labelDisplayedRows: ({ from, to, count }) => {
return (
<>
<Typography
component='span'
variant='inherit'
weight='strong'
color='textPrimary'
>
{`${from}-${to}`}
</Typography>
{` of ${count}`}
</>
);
}
},
styleOverrides: {
select: {
paddingRight: getSpacing(7.5),
paddingLeft: getSpacing(1.5)
root: {
borderBottom: 0
},
input: {
height: getSpacing(4),
width: 'auto',
border: `2px solid ${commonPalette.divider}`,
borderRadius: getSpacing(0.5),
fontWeight: themeTypography.fontWeightMedium,
paddingRight: getSpacing(3),
'& .MuiSelect-icon': {
top: '50%',
transform: 'translateY(-50%)',
width: getSpacing(2.25),
height: getSpacing(2.25),
right: getSpacing(0.75)
}
toolbar: {
minHeight: '0 !important',
padding: '0 !important',
height: getSpacing(6)
},
caption: {
selectLabel: {
margin: 0,
...themeTypography.caption,
'&:first-of-type': {
color: commonPalette.text.secondary
fontWeight: themeTypography.fontWeightMedium
},
selectIcon: {
'&.MuiSvgIcon-root': {
right: getSpacing(1)
}
},
toolbar: {
minHeight: 0,
marginTop: getSpacing(1)
input: {
marginRight: getSpacing(2),
marginLeft: getSpacing(1),
width: 'auto',
paddingRight: getSpacing(3)
},
displayedRows: {
color: commonPalette.text.secondary
},
actions: {
'& button:last-child': {
marginLeft: getSpacing(2)
marginLeft: getSpacing(1),

'.MuiIconButton-root': {
'&:not(.Mui-disabled)': {
color: commonPalette.text.secondary
},
'& + .MuiIconButton-root': {
marginLeft: getSpacing(0.5)
}
}
}
}
Expand All @@ -257,13 +284,8 @@ export const dataDisplayOverrides = {
styleOverrides: {
root: {
transition: 'background-color 0.25s ease',
'&:not(.MuiTableRow-head) th, td': {
borderColor: commonPalette.divider,
'&:not(.MuiTableCell-sizeSmall)': {
padding: getSpacing(1, 2),
height: getSpacing(6)
}
},
borderColor: commonPalette.divider,

'&.MuiTableRow-hover:hover': {
cursor: 'pointer'
}
Expand All @@ -272,6 +294,17 @@ export const dataDisplayOverrides = {
},
MuiTableCell: {
styleOverrides: {
root: {
padding: getSpacing(0.5, 2),
height: getSpacing(6),

'&.MuiTableCell-sizeSmall': {
height: getSpacing(4)
},
'&.MuiTableCell-footer': {
padding: 0
}
},
head: {
...themeTypography.caption,
fontWeight: themeTypography.fontWeightMedium,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useState } from 'react';
import {
Box,
TableRow,
TableCell,
TableHead,
TableContainer,
TableBody,
Table,
TablePagination,
TableFooter
} from '@mui/material';

function createData(name, calories, fat) {
return { name, calories, fat };
}
const rows = [
createData('Cupcake', 305, 3.7),
createData('Donut', 452, 25.0),
createData('Frozen yoghurt', 159, 6.0),
createData('Ice cream sandwich', 237, 9.0),
createData('KitKat', 518, 26.0)
];

const options = {
title: 'Molecules/TablePagination',
component: TablePagination,
argTypes: {},
parameters: {
design: {
type: 'figma',
url: 'https://www.figma.com/file/nmaoLeo69xBJCHm9nc6lEV/C4R-Components?node-id=1534-33541&t=EpJKKbIbCuhioYR9-0'
},
status: {
type: 'validated'
}
}
};

export default options;

const PlaygroundTemplate = (args) => {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(10);

const handleChangePage = (event, newPage) => {
setPage(newPage);
};

const handleChangeRowsPerPage = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};

return (
<TablePagination
count={100}
page={page}
onPageChange={handleChangePage}
rowsPerPage={rowsPerPage}
onRowsPerPageChange={handleChangeRowsPerPage}
/>
);
};

const TableExampleTemplate = (args) => {
return (
<Box>
<TableContainer>
<Table aria-label='simple table'>
<TableHead>
<TableRow>
<TableCell>#</TableCell>
<TableCell>Name</TableCell>
<TableCell>Calories</TableCell>
<TableCell>Fat</TableCell>
</TableRow>
</TableHead>
<TableBody>
{[...rows, ...rows].map((row, index) => (
<TableRow hover key={index}>
<TableCell component='th' scope='row'>
{index + 1}
</TableCell>
<TableCell>{row.name}</TableCell>
<TableCell>{row.calories}</TableCell>
<TableCell>{row.fat}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination count={20} page={0} rowsPerPage={10} />
</TableRow>
</TableFooter>
</Table>
</TableContainer>
</Box>
);
};

export const Playground = PlaygroundTemplate.bind({});

export const TableExample = TableExampleTemplate.bind({});

0 comments on commit e1e8efd

Please sign in to comment.