From 10711585ccd8e95ab7ce6a084d2d4355a60baf15 Mon Sep 17 00:00:00 2001 From: Danail Hadjiatanasov Date: Wed, 4 Nov 2020 13:47:23 +0100 Subject: [PATCH] [DataGrid] Fix display of row count and selected rows on mobile (#508) * Enable Row Count and Selected Rows on mobile * Hide RowCount and SelectedRowCount if paginationComponent is provided * Hide Row count and Selected rows on mobile if Pagination is available * Hide Total rows when there is pagination, remove select and label from TablePagination * Update packages/grid/_modules_/grid/components/pagination.tsx Co-authored-by: Olivier Tassinari * Adjust class names * Swap Total Row and rows selected places * Update footer breakpoint to "sm" * Fix formatting * Fix responsive styles Co-authored-by: Olivier Tassinari --- .../grid/components/default-footer.tsx | 24 +++++++++++++++---- .../_modules_/grid/components/pagination.tsx | 22 +++++++++++++++++ .../styled-wrappers/GridRootStyles.ts | 22 +++++++++++------ 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/packages/grid/_modules_/grid/components/default-footer.tsx b/packages/grid/_modules_/grid/components/default-footer.tsx index 9c3011b30590..a2ec297a48eb 100644 --- a/packages/grid/_modules_/grid/components/default-footer.tsx +++ b/packages/grid/_modules_/grid/components/default-footer.tsx @@ -7,6 +7,7 @@ import { ApiContext } from './api-context'; import { RowCount } from './row-count'; import { SelectedRowCount } from './selected-row-count'; import { GridFooter } from './styled-wrappers/GridFooter'; +import { classnames } from '../utils'; export interface DefaultFooterProps { paginationComponent: React.ReactNode; @@ -24,12 +25,25 @@ export const DefaultFooter = React.forwardRef + ); + const showSelectedRowCount = !options.hideFooterSelectedRowCount && ( + + ); + const justifyItemsEnd = !selectedRowCount && !options.hideFooterSelectedRowCount; + return ( - - {!options.hideFooterRowCount && } - {!options.hideFooterSelectedRowCount && ( - - )} + + {showSelectedRowCount} + {showRowCount} {paginationComponent} ); diff --git a/packages/grid/_modules_/grid/components/pagination.tsx b/packages/grid/_modules_/grid/components/pagination.tsx index e9463bdbfe7b..0c45d7eb1004 100644 --- a/packages/grid/_modules_/grid/components/pagination.tsx +++ b/packages/grid/_modules_/grid/components/pagination.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import TablePagination from '@material-ui/core/TablePagination'; +import { makeStyles, Theme } from '@material-ui/core/styles'; export interface PaginationComponentProps { pageCount: number; @@ -11,6 +12,25 @@ export interface PaginationComponentProps { rowsPerPageOptions?: number[]; } +// Used to hide the drop down select from the TablePaginagion +const useStyles = makeStyles((theme: Theme) => ({ + caption: { + display: 'none', + [theme.breakpoints.up('md')]: { + display: 'block', + }, + '& ~ &': { + display: 'block', + }, + }, + input: { + display: 'none', + [theme.breakpoints.up('md')]: { + display: 'block', + }, + }, +})); + export const Pagination: React.FC = ({ setPage, setPageSize, @@ -19,6 +39,7 @@ export const Pagination: React.FC = ({ currentPage, rowsPerPageOptions, }) => { + const classes = useStyles(); const onPageSizeChange = React.useCallback( (event: React.ChangeEvent) => { const newPageSize = Number(event.target.value); @@ -36,6 +57,7 @@ export const Pagination: React.FC = ({ return (