Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Fix CSS footer spacing #268

Merged
merged 2 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions packages/grid/x-grid-modules/src/GridComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from './hooks/features';
import { DEFAULT_GRID_OPTIONS, ElementSize, RootContainerRef } from './models';
import { COMPONENT_ERROR, DATA_CONTAINER_CSS_CLASS } from './constants';
import { GridRoot } from './components/styled-wrappers/grid-root';
import { DataContainer } from './components/styled-wrappers/data-container';
import { ColumnsContainer } from './components/styled-wrappers/columns-container';
import { GridRoot } from './components/styled-wrappers/GridRoot';
import { GridDataContainer } from './components/styled-wrappers/GridDataContainer';
import { GridColumnsContainer } from './components/styled-wrappers/GridColumnsContainer';
import { useVirtualRows } from './hooks/virtualization';
import {
ApiContext,
Expand All @@ -25,7 +25,7 @@ import {
RenderContext,
Viewport,
Watermark,
Window,
GridWindow,
} from './components';
import { useApi, useColumns, useKeyboard, useRows } from './hooks/root';
import { useLogger, useLoggerFactory } from './hooks/utils';
Expand Down Expand Up @@ -190,19 +190,22 @@ export const GridComponent = React.forwardRef<HTMLDivElement, GridComponentProps
{customComponents.headerComponent}
<div className="MuiDataGrid-mainGridContainer">
<Watermark licenseStatus={props.licenseStatus} />
<ColumnsContainer ref={columnsContainerRef} height={internalOptions.headerHeight}>
<GridColumnsContainer
ref={columnsContainerRef}
height={internalOptions.headerHeight}
>
<ColumnsHeader
ref={columnsHeaderRef}
columns={internalColumns.visible || []}
hasScrollX={!!renderCtx?.hasScrollX}
onResizeColumn={onResizeColumn}
renderCtx={renderCtx}
/>
</ColumnsContainer>
</GridColumnsContainer>
{!props.loading && internalRows.length === 0 && customComponents.noRowsComponent}
{props.loading && customComponents.loadingComponent}
<Window ref={windowRef}>
<DataContainer
<GridWindow ref={windowRef}>
<GridDataContainer
ref={gridRef}
className={DATA_CONTAINER_CSS_CLASS}
style={{
Expand All @@ -220,8 +223,8 @@ export const GridComponent = React.forwardRef<HTMLDivElement, GridComponentProps
/>
</RenderContext.Provider>
)}
</DataContainer>
</Window>
</GridDataContainer>
</GridWindow>
</div>
{customComponents.footerComponent || (
<DefaultFooter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { GridOptions } from '../models';
import { Footer } from './styled-wrappers';
import { GridFooter } from './styled-wrappers/GridFooter';
import { RowCount } from './row-count';
import { SelectedRowCount } from './selected-row-count';
import { ApiContext } from './api-context';
Expand Down Expand Up @@ -29,13 +29,13 @@ export const DefaultFooter = React.forwardRef<HTMLDivElement, DefaultFooterProps
}

return (
<Footer ref={ref}>
<GridFooter ref={ref}>
{!options.hideFooterRowCount && <RowCount rowCount={rowCount} />}
{!options.hideFooterSelectedRowCount && (
<SelectedRowCount selectedRowCount={selectedRowCount} />
)}
{paginationComponent}
</Footer>
</GridFooter>
);
},
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { GridOverlay } from './styled-wrappers/window-overlay';
import { GridOverlay } from './styled-wrappers/GridOverlay';

export interface ErrorMessageProps {
message?: string;
Expand Down
9 changes: 4 additions & 5 deletions packages/grid/x-grid-modules/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
export * from './icons';
export * from './styled-wrappers';

export * from './api-context';
export * from './autosizer';
export * from './cell';
export * from './checkbox-renderer';
export * from './column-header-item';
export * from './column-header-separator';
export * from './column-header-sort-icon';
export * from './column-header-title';
export * from './column-header-separator';
export * from './column-headers';
export * from './default-footer';
export * from './icons';
export * from './loading-overlay';
export * from './no-row-message';
export * from './options-context';
export * from './pagination';
export * from './render-context';
export * from './rendering-zone';
export * from './row';
export * from './row-cells';
export * from './row-count';
export * from './row';
export * from './selected-row-count';
export * from './sticky-container';
export * from './styled-wrappers';
export * from './viewport';
export * from './watermark';
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import CircularProgress from '@material-ui/core/CircularProgress';
import { GridOverlay } from './styled-wrappers';
import { GridOverlay } from './styled-wrappers/GridOverlay';

export function LoadingOverlay() {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { GridOverlay } from './styled-wrappers/window-overlay';
import { GridOverlay } from './styled-wrappers/GridOverlay';

export function NoRowMessage() {
return <GridOverlay>No Rows</GridOverlay>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { DivProps } from './grid-root';
import { classnames } from '../../utils';

export const ColumnsContainer = React.forwardRef<HTMLDivElement, DivProps & { height: number }>(
(props, ref) => {
type GridColumnsContainerProps = React.HTMLAttributes<HTMLDivElement> & { height: number };

export const GridColumnsContainer = React.forwardRef<HTMLDivElement, GridColumnsContainerProps>(
function GridColumnsContainer(props, ref) {
const { className, height, style, ...other } = props;
return (
<div
Expand All @@ -15,4 +16,3 @@ export const ColumnsContainer = React.forwardRef<HTMLDivElement, DivProps & { he
);
},
);
ColumnsContainer.displayName = 'ColumnsContainer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import { classnames } from '../../utils';

type GridDataContainerProps = React.HTMLAttributes<HTMLDivElement>;

export const GridDataContainer = React.forwardRef<HTMLDivElement, GridDataContainerProps>(
function GridDataContainer(props, ref) {
const { className, ...other } = props;
return (
<div ref={ref} className={classnames('MuiDataGrid-dataContainer', className)} {...other} />
);
},
);
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import * as React from 'react';
import { DivProps } from './grid-root';
import { classnames } from '../../utils';

export const Footer = React.forwardRef<HTMLDivElement, DivProps>((props, ref) => {
type GridFooterProps = React.HTMLAttributes<HTMLDivElement>;

export const GridFooter = React.forwardRef<HTMLDivElement, GridFooterProps>(function GridFooter(
props,
ref,
) {
const { className, ...other } = props;
return <div ref={ref} className={classnames('MuiDataGrid-footer', className)} {...other} />;
});
Footer.displayName = 'Footer';
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { classnames } from '../../utils';
import { DivProps } from './grid-root';
import { OptionsContext } from '../options-context';

export function GridOverlay(props: DivProps) {
type GridOverlayProps = React.HTMLAttributes<HTMLDivElement>;

export function GridOverlay(props: GridOverlayProps) {
Copy link
Member Author

@oliviertassinari oliviertassinari Sep 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One this component, it seems that we can kill the <div className="MuiDataGrid-overlayContent" /> element. It will make customization easier. I will look closer at the issue later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, it's used in creating the no row message and error-message, and potentially more components.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm saying that because I didn't see something in the CSS that would prevent. We will see, I could be wrong. It needs to be done in an isolated pull request anyway.

const { className, children, ...other } = props;
const options = React.useContext(OptionsContext);
return (
Expand All @@ -16,4 +17,3 @@ export function GridOverlay(props: DivProps) {
</div>
);
}
GridOverlay.displayName = 'GridOverlay';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import * as React from 'react';
import { classnames } from '../../utils';
import { useStyles } from './GridRootStyles';

export type DivProps = React.HTMLAttributes<HTMLDivElement>;
type GridRootProps = React.HTMLAttributes<HTMLDivElement>;

export const GridRoot = React.forwardRef<HTMLDivElement, DivProps>(function GridRoot(props, ref) {
export const GridRoot = React.forwardRef<HTMLDivElement, GridRootProps>(function GridRoot(
props,
ref,
) {
const { className, ...other } = props;
const classes = useStyles();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const useStyles = makeStyles(
alignItems: 'center',
...theme.typography.body2,
display: 'none',
paddingLeft: theme.spacing(2),
margin: theme.spacing(0, 2),
Copy link
Member Author

@oliviertassinari oliviertassinari Sep 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix, the rest is refactorization.

[theme.breakpoints.up('md')]: {
minHeight: 52, // Match TablePagination min height
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import * as React from 'react';
import { DivProps } from './grid-root';
import { classnames } from '../../utils';
import { OptionsContext } from '../options-context';

export const Window = React.forwardRef<HTMLDivElement, DivProps>((props, ref) => {
const { headerHeight, autoHeight } = React.useContext(OptionsContext);
type GridWindowProps = React.HTMLAttributes<HTMLDivElement>;

export const GridWindow = React.forwardRef<HTMLDivElement, GridWindowProps>(function GridWindow(
props,
ref,
) {
const { className, ...other } = props;
const { headerHeight, autoHeight } = React.useContext(OptionsContext);
return (
<div
ref={ref}
Expand All @@ -15,4 +19,3 @@ export const Window = React.forwardRef<HTMLDivElement, DivProps>((props, ref) =>
/>
);
});
Window.displayName = 'Window';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './columns-container';
export * from './data-container';
export * from './footer';
export * from './grid-root';
export * from './window';
export * from './window-overlay';
export * from './GridColumnsContainer';
export * from './GridDataContainer';
export * from './GridFooter';
export * from './GridOverlay';
export * from './GridRoot';
export * from './GridWindow';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ColDef, XGrid, GridOverlay, Footer, useApiRef, ApiRef } from '@material-ui/x-grid';
import { ColDef, XGrid, GridOverlay, GridFooter, useApiRef, ApiRef } from '@material-ui/x-grid';
Copy link
Member Author

@oliviertassinari oliviertassinari Sep 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix public components with Grid, as we will re-export them from @material-ui/x later on, avoid conflicts.

import LinearProgress from '@material-ui/core/LinearProgress';
import CodeIcon from '@material-ui/icons/Code';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
Expand Down Expand Up @@ -139,7 +139,7 @@ export function CustomPagination() {
function FooterComponent(props) {
const { paginationProps } = props;
return (
<Footer className="my-custom-footer">
<GridFooter className="my-custom-footer">
<span style={{ display: 'flex', alignItems: 'center' }}>
This is my custom footer and pagination here!{' '}
</span>
Expand All @@ -149,7 +149,7 @@ function FooterComponent(props) {
count={paginationProps.pageCount}
onChange={(event, value) => paginationProps.setPage(value)}
/>
</Footer>
</GridFooter>
);
}

Expand Down