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] Replace style-components with @material-ui/styles #168

Merged
merged 31 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d1ae9ff
remove style-components
dtassone Aug 13, 2020
41199da
fix rollup build
dtassone Aug 13, 2020
691ed84
fix import
dtassone Aug 13, 2020
b44a69e
convert styles to jss
dtassone Aug 14, 2020
81b3444
fix style
dtassone Aug 14, 2020
2b248d1
more cleanup
dtassone Aug 14, 2020
072a716
prettier
dtassone Aug 14, 2020
dacbaf0
lint
dtassone Aug 14, 2020
0dcf77d
Merge branch 'master' into cssModules
dtassone Sep 7, 2020
32511cd
fix font styles and fix hover header error
dtassone Sep 7, 2020
7e7a644
remove some specificity on css
dtassone Sep 7, 2020
54f30f9
fix prettier
dtassone Sep 7, 2020
16032d1
Update packages/grid/x-grid-modules/src/components/styled-wrappers/ge…
dtassone Sep 8, 2020
dc2e18b
cleanup styling
dtassone Sep 8, 2020
be51c9e
Merge branch 'cssModules' of github.com:dtassone/material-ui-x into c…
dtassone Sep 8, 2020
548ccae
fix dependency no cycle
dtassone Sep 8, 2020
3bfd638
prettier
dtassone Sep 8, 2020
a924dd7
small cleanup
dtassone Sep 8, 2020
b107942
prettier
dtassone Sep 9, 2020
b244586
refactor styles and selector
dtassone Sep 9, 2020
883c789
fix test
dtassone Sep 9, 2020
fac1d37
fix DataGrid resizing
oliviertassinari Sep 9, 2020
2cf4421
replace class name that doesn't exist
oliviertassinari Sep 9, 2020
eff34f2
remove all double spaces
oliviertassinari Sep 9, 2020
332a7d8
generate a global class names
oliviertassinari Sep 9, 2020
0c9e629
remove dead code
oliviertassinari Sep 9, 2020
b7abae5
all in with MuiDataGrid for the CSS
oliviertassinari Sep 9, 2020
2895038
polish CSS
oliviertassinari Sep 9, 2020
d0baee1
start to reproduce https://material-ui.com/components/tables/\#simple…
oliviertassinari Sep 9, 2020
d6730b4
Material Design spec
oliviertassinari Sep 10, 2020
8640691
improve footer display
oliviertassinari Sep 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/grid/data-grid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
},
"peerDependencies": {
"@material-ui/core": "^4.9.12",
"react": "^16.8.0",
"styled-components": "^5.1.0"
"react": "^16.8.0"
},
"setupFiles": [
"<rootDir>/src/setupTests.js"
Expand Down
3 changes: 1 addition & 2 deletions packages/grid/x-grid-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
},
"peerDependencies": {
"@material-ui/core": "^4.9.12",
"react": "^16.8.0",
"styled-components": "^5.1.0"
"react": "^16.8.0"
},
"scripts": {
"precommit": "npm run lint",
Expand Down
11 changes: 5 additions & 6 deletions packages/grid/x-grid-modules/src/GridComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
} from './hooks/features';
import { DEFAULT_GRID_OPTIONS, ElementSize, RootContainerRef } from './models';
import { COMPONENT_ERROR, DATA_CONTAINER_CSS_CLASS } from './constants';
import { ColumnsContainer, DataContainer, GridRoot } from './components/styled-wrappers';
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 { useVirtualRows } from './hooks/virtualization';
import {
ApiContext,
Expand Down Expand Up @@ -71,9 +73,7 @@ export const GridComponent = React.forwardRef<HTMLDivElement, GridComponentProps
// We are handling error here, to set up the handler as early as possible and be able to catch error thrown at init time.
setErrorState(args);
};
React.useEffect(() => {
return apiRef!.current.subscribeEvent(COMPONENT_ERROR, errorHandler);
}, [apiRef]);
React.useEffect(() => apiRef!.current.subscribeEvent(COMPONENT_ERROR, errorHandler), [apiRef]);

React.useEffect(() => {
apiRef!.current.showError(props.error);
Expand Down Expand Up @@ -190,12 +190,11 @@ export const GridComponent = React.forwardRef<HTMLDivElement, GridComponentProps
{customComponents.headerComponent}
<div className="main-grid-container">
<Watermark licenseStatus={props.licenseStatus} />
<ColumnsContainer ref={columnsContainerRef}>
<ColumnsContainer ref={columnsContainerRef} height={internalOptions.headerHeight}>
<ColumnsHeader
ref={columnsHeaderRef}
columns={internalColumns.visible || []}
hasScrollX={!!renderCtx?.hasScrollX}
headerHeight={internalOptions.headerHeight}
onResizeColumn={onResizeColumn}
renderCtx={renderCtx}
/>
Expand Down
10 changes: 9 additions & 1 deletion packages/grid/x-grid-modules/src/components/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { Alignement, CellValue } from '../models';
import { CELL_CSS_CLASS } from '../constants/cssClassesConstants';
import { classnames } from '../utils';
import { OptionsContext } from './options-context';

export interface GridCellProps {
field?: string;
Expand Down Expand Up @@ -37,6 +38,7 @@ export const Cell: React.FC<GridCellProps> = React.memo(
align !== 'left' ? align : '',
);
const valueToRender = formattedValue || value;
const { rowHeight } = React.useContext(OptionsContext);

return (
<div
Expand All @@ -47,7 +49,13 @@ export const Cell: React.FC<GridCellProps> = React.memo(
data-colindex={colIndex}
data-rowindex={rowIndex}
aria-colindex={colIndex}
style={{ minWidth: width, maxWidth: width }}
style={{
minWidth: width,
maxWidth: width,
lineHeight: `${rowHeight - 1}px`,
minHeight: rowHeight,
maxHeight: rowHeight,
}}
tabIndex={tabIndex}
>
{children || valueToRender?.toString()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react';
import Checkbox from '@material-ui/core/Checkbox';
import styled from 'styled-components';
import { SelectionChangeParams } from '../models/params/selectionChangeParams';
import { ColParams } from '../models/params/colParams';
import { CellParams } from '../models/params/cellParams';

const CheckboxInputContainer = styled.div`
display: block;
`;

export const HeaderCheckbox: React.FC<ColParams> = React.memo(({ api }) => {
const [isChecked, setChecked] = React.useState(false);
const [isIndeterminate, setIndeterminate] = React.useState(false);
Expand All @@ -32,15 +27,15 @@ export const HeaderCheckbox: React.FC<ColParams> = React.memo(({ api }) => {
return api.onSelectionChange(selectionChange);
}, [api, selectionChange]);
return (
<CheckboxInputContainer>
<div>
<Checkbox
indeterminate={isIndeterminate}
checked={isChecked}
onChange={handleChange}
className="checkbox-input"
inputProps={{ 'aria-label': 'Select All Rows checkbox' }}
/>
</CheckboxInputContainer>
</div>
);
});
HeaderCheckbox.displayName = 'HeaderCheckbox';
Expand All @@ -51,14 +46,14 @@ export const CellCheckboxRenderer: React.FC<CellParams> = React.memo(({ api, row
};

return (
<CheckboxInputContainer>
<div>
<Checkbox
checked={!!value}
onChange={handleChange}
className="checkbox-input"
inputProps={{ 'aria-label': 'Select Row checkbox' }}
/>
</CheckboxInputContainer>
</div>
);
});
CellCheckboxRenderer.displayName = 'CellCheckboxRenderer';
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import { classnames } from '../utils';
import { ColumnHeaderSortIcon } from './column-header-sort-icon';
import { ColumnHeaderTitle } from './column-header-title';
import { ColumnHeaderSeparator } from './column-header-separator';
import { OptionsContext } from './options-context';

interface ColumnHeaderItemProps {
column: ColDef;
headerHeight: number;
colIndex: number;
onResizeColumn?: (c: any) => void;
}

export const ColumnHeaderItem = React.memo(
({ column, colIndex, headerHeight, onResizeColumn }: ColumnHeaderItemProps) => {
({ column, colIndex, onResizeColumn }: ColumnHeaderItemProps) => {
const api = React.useContext(ApiContext);
const { headerHeight, showColumnRightBorder } = React.useContext(OptionsContext);

const cssClass = classnames(
HEADER_CELL_CSS_CLASS,
showColumnRightBorder ? 'with-border' : '',
column.headerClassName,
column.headerAlign !== 'left' ? column.headerAlign : '',
{ sortable: column.sortable },
Expand Down Expand Up @@ -66,6 +68,7 @@ export const ColumnHeaderItem = React.memo(
direction={column.sortDirection}
index={column.sortIndex}
hide={column.hideSortIcons}
height={headerHeight}
/>
)}
{headerComponent || (
Expand All @@ -80,6 +83,7 @@ export const ColumnHeaderItem = React.memo(
direction={column.sortDirection}
index={column.sortIndex}
hide={column.hideSortIcons}
height={headerHeight}
/>
)}
<ColumnHeaderSeparator resizable={column.resizable} onResize={onResize} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { useIcons } from '../hooks/utils/useIcons';
import { OptionsContext } from './options-context';

export interface ColumnHeaderSeparatorProps {
resizable: boolean | undefined;
Expand All @@ -9,6 +10,7 @@ export interface ColumnHeaderSeparatorProps {
export const ColumnHeaderSeparator: React.FC<ColumnHeaderSeparatorProps> = React.memo(
({ onResize, resizable }) => {
const icons = useIcons();
const { showColumnRightBorder, headerHeight } = React.useContext(OptionsContext);

const resizeIconProps = {
className: `icon separator ${resizable ? 'resizable' : ''}`,
Expand All @@ -17,7 +19,14 @@ export const ColumnHeaderSeparator: React.FC<ColumnHeaderSeparatorProps> = React

const icon = React.createElement(icons!.columnResize!, resizeIconProps);

return <div className="column-separator">{icon}</div>;
return (
<div
className="column-separator"
style={{ minHeight: headerHeight, opacity: showColumnRightBorder ? 0 : 1 }}
>
{icon}
</div>
);
},
);
ColumnHeaderSeparator.displayName = 'ColumnHeaderSeparator';
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ export interface ColumnHeaderSortIconProps {
direction: SortDirection;
index: number | undefined;
hide?: boolean;
height: number;
}

const getIcon = (icons: IconsOptions, direction: SortDirection): React.ReactNode =>
const getIcon = (icons: IconsOptions, direction: SortDirection, height: number): React.ReactNode =>
direction === 'asc'
? React.createElement(icons!.columnSortedAscending!)
: React.createElement(icons!.columnSortedDescending!);
? React.createElement(icons!.columnSortedAscending!, { styles: { minHeight: height } })
: React.createElement(icons!.columnSortedDescending!, { styles: { minHeight: height } });

export const ColumnHeaderSortIcon: React.FC<ColumnHeaderSortIconProps> = React.memo(
({ direction, index, hide }) => {
({ direction, index, hide, height }) => {
const icons = useIcons();

if (hide || direction == null) {
Expand All @@ -28,13 +29,13 @@ export const ColumnHeaderSortIcon: React.FC<ColumnHeaderSortIconProps> = React.m
{index != null && (
<Badge badgeContent={index} color="default">
<IconButton aria-label="Sort" size="small">
{getIcon(icons, direction)}
{getIcon(icons, direction, height)}
</IconButton>
</Badge>
)}
{index == null && (
<IconButton aria-label="Sort" size="small">
{getIcon(icons, direction)}
{getIcon(icons, direction, height)}
</IconButton>
)}
</span>
Expand Down
15 changes: 4 additions & 11 deletions packages/grid/x-grid-modules/src/components/column-headers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import { LeftEmptyCell, RightEmptyCell } from './cell';

export interface ColumnHeadersItemCollectionProps {
columns: Columns;
headerHeight: number;
onResizeColumn?: (col: ColDef) => void;
}
export const ColumnHeaderItemCollection: React.FC<ColumnHeadersItemCollectionProps> = React.memo(
({ headerHeight, onResizeColumn, columns }) => {
({ onResizeColumn, columns }) => {
const items = columns.map((col, idx) => (
<ColumnHeaderItem
key={col.field}
column={col}
colIndex={idx}
headerHeight={headerHeight}
onResizeColumn={onResizeColumn}
/>
));
Expand All @@ -29,15 +27,14 @@ ColumnHeaderItemCollection.displayName = 'ColumnHeaderItemCollection';
export interface ColumnsHeaderProps {
columns: Columns;
hasScrollX: boolean;
headerHeight: number;
onResizeColumn?: (col: ColDef) => void;
renderCtx: Partial<RenderContextProps> | null;
}

export const ColumnsHeader = React.memo(
React.forwardRef<HTMLDivElement, ColumnsHeaderProps>(
({ columns, hasScrollX, headerHeight, onResizeColumn, renderCtx }, columnsHeaderRef) => {
const wrapperCssClasses = `material-col-cell-wrapper ${hasScrollX ? 'scroll' : ''}`;
({ columns, hasScrollX, onResizeColumn, renderCtx }, columnsHeaderRef) => {
const wrapperCssClasses = `MuiDataGrid-col-cell-wrapper ${hasScrollX ? 'scroll' : ''}`;
const api = React.useContext(ApiContext);

if (!api) {
Expand Down Expand Up @@ -75,11 +72,7 @@ export const ColumnsHeader = React.memo(
style={{ minWidth: renderCtx?.totalSizes?.width }}
>
<LeftEmptyCell key="left-empty" width={renderCtx?.leftEmptyWidth} />
<ColumnHeaderItemCollection
columns={renderedCols}
onResizeColumn={onResizeColumn}
headerHeight={headerHeight}
/>
<ColumnHeaderItemCollection columns={renderedCols} onResizeColumn={onResizeColumn} />
<RightEmptyCell key="right-empty" width={renderCtx?.rightEmptyWidth} />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { GridOptions } from '../models';
import { DEFAULT_GRID_OPTIONS, GridOptions } from '../models';

export const OptionsContext = React.createContext<GridOptions | undefined>(undefined);
export const OptionsContext = React.createContext<GridOptions>(DEFAULT_GRID_OPTIONS);
11 changes: 9 additions & 2 deletions packages/grid/x-grid-modules/src/components/row.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { RowId } from '../models';
import { ROW_CSS_CLASS } from '../constants/cssClassesConstants';
import { OptionsContext } from './options-context';
import { classnames } from '../utils';

export interface RowProps {
id: RowId;
Expand All @@ -10,17 +12,22 @@ export interface RowProps {
}

export const Row: React.FC<RowProps> = ({ selected, id, className, rowIndex, children }) => {
const cssClasses = (selected ? 'selected ' : ' ') + (className || '');
const ariaRowIndex = rowIndex + 2; // 1 for the header row and 1 as it's 1 based
const { rowHeight } = React.useContext(OptionsContext);

return (
<div
key={id}
data-id={id}
data-rowindex={rowIndex}
role="row"
className={`${ROW_CSS_CLASS} ${cssClasses}`}
className={classnames(ROW_CSS_CLASS, className, { selected })}
aria-rowindex={ariaRowIndex}
aria-selected={selected}
style={{
maxHeight: rowHeight,
minHeight: rowHeight,
}}
>
{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import * as React from 'react';
import { DivProps } from './grid-root';
import { classnames } from '../../utils';

export const ColumnsContainer = React.forwardRef<HTMLDivElement, DivProps>((props, ref) => {
const { className, ...other } = props;
return <div ref={ref} className={classnames('columns-container', className)} {...other} />;
});
export const ColumnsContainer = React.forwardRef<HTMLDivElement, DivProps & { height: number }>(
(props, ref) => {
const { className, height, style, ...other } = props;
return (
<div
ref={ref}
className={classnames('columns-container', className)}
{...other}
style={{ minHeight: height, maxHeight: height, lineHeight: `${height}px`, ...style }}
/>
);
},
);
ColumnsContainer.displayName = 'ColumnsContainer';