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 support for @material-ui/core@4.12 #2108

Merged
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
8 changes: 5 additions & 3 deletions packages/grid/_modules_/grid/components/GridPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useGridSelector } from '../hooks/features/core/useGridSelector';
import { gridPaginationSelector } from '../hooks/features/pagination/gridPaginationSelector';
import { optionsSelector } from '../hooks/utils/optionsSelector';
import { useGridApiContext } from '../hooks/root/useGridApiContext';
import { isMuiV5, createTheme } from '../utils';
import { getMuiVersion, createTheme } from '../utils';

const defaultTheme = createTheme();
// Used to hide the Rows per page selector on small devices
Expand Down Expand Up @@ -66,7 +66,7 @@ export const GridPagination = React.forwardRef<
);

const getPaginationChangeHandlers = () => {
if (isMuiV5()) {
if (getMuiVersion() !== 'v4') {
return {
onPageChange: handlePageChange,
onRowsPerPageChange: handlePageSizeChange,
Expand All @@ -84,7 +84,9 @@ export const GridPagination = React.forwardRef<
<TablePagination
ref={ref}
classes={{
...(isMuiV5() ? { selectLabel: classes.selectLabel } : { caption: classes.caption }),
...(getMuiVersion() === 'v5'
? { selectLabel: classes.selectLabel }
: { caption: classes.caption }),
input: classes.input,
}}
component="div"
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/_modules_/grid/components/panel/GridPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import Paper from '@material-ui/core/Paper';
import Popper, { PopperProps } from '@material-ui/core/Popper';
import { useGridApiContext } from '../../hooks/root/useGridApiContext';
import { isEscapeKey, isMuiV5, createTheme } from '../../utils';
import { isEscapeKey, getMuiVersion, createTheme } from '../../utils';
import {
InternalStandardProps as StandardProps,
generateUtilityClasses,
Expand Down Expand Up @@ -55,7 +55,7 @@ export const GridPanel = React.forwardRef<HTMLDivElement, GridPanelProps>(functi
const apiRef = useGridApiContext();

const getPopperModifiers = (): any => {
if (isMuiV5()) {
if (getMuiVersion() === 'v5') {
return [
{
name: 'flip',
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/_modules_/grid/utils/getGridLocalization.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GridLocaleText } from '../models/api/gridLocaleTextApi';
import { GridOptions } from '../models/gridOptions';
import { isMuiV5 } from './utils';
import { getMuiVersion } from './utils';

export interface LocalizationV4 {
props: {
Expand All @@ -22,7 +22,7 @@ export const getGridLocalization = (
gridTranslations: Partial<GridLocaleText>,
coreTranslations?,
): Localization => {
if (isMuiV5()) {
if (getMuiVersion() === 'v5') {
return {
components: {
MuiDataGrid: {
Expand Down
18 changes: 14 additions & 4 deletions packages/grid/_modules_/grid/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@ export function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

export function isMuiV5(): boolean {
return 'alpha' in styles;
export function getMuiVersion(): string {
if (!('fade' in styles)) {
return 'v5';
}

if ('fade' in styles && 'alpha' in styles) {
return 'v4.12';
}

return 'v4';
}

export function muiStyleAlpha(color: string, value: number): string {
if (isMuiV5()) {
if ((styles as any)?.alpha) {
Copy link
Member

@oliviertassinari oliviertassinari Jul 10, 2021

Choose a reason for hiding this comment

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

A good take away for us: feature detection >> version matching.

return (styles as any)?.alpha(color, value);
}
// deprecated name in v4.12 and v5
return (styles as any)?.fade(color, value);
}

export function createTheme(): styles.Theme {
if (isMuiV5()) {
if ((styles as any)?.createTheme) {
return (styles as any)?.createTheme();
}
// deprecated name in v4.12 and v5
return (styles as any)?.createMuiTheme();
}

Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3234,13 +3234,13 @@
write-file-atomic "^3.0.3"

"@material-ui/core@^4.9.12":
version "4.11.4"
resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-4.11.4.tgz#4fb9fe5dec5dcf780b687e3a40cff78b2b9640a4"
integrity sha512-oqb+lJ2Dl9HXI9orc6/aN8ZIAMkeThufA5iZELf2LQeBn2NtjVilF5D2w7e9RpntAzDb4jK5DsVhkfOvFY/8fg==
version "4.12.1"
resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-4.12.1.tgz#ac8f081498047aa02bb6ee70b77c5dad6a2a6e73"
integrity sha512-C6hYsjkWCTfBx9FaqxhCZCITBagh7fyCKFtHyvO3tTOcBw6NJaktdhNZ2n82jQdQdgfFvg6OOxi7OOzsAdAcBQ==
dependencies:
"@babel/runtime" "^7.4.4"
"@material-ui/styles" "^4.11.4"
"@material-ui/system" "^4.11.3"
"@material-ui/system" "^4.12.1"
"@material-ui/types" "5.1.0"
"@material-ui/utils" "^4.11.2"
"@types/react-transition-group" "^4.2.0"
Expand Down Expand Up @@ -3268,9 +3268,9 @@
"@babel/runtime" "^7.4.4"

"@material-ui/lab@^4.0.0-alpha.54", "@material-ui/lab@^4.0.0-alpha.56":
version "4.0.0-alpha.58"
resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.58.tgz#c7ebb66f49863c5acbb20817163737caa299fafc"
integrity sha512-GKHlJqLxUeHH3L3dGQ48ZavYrqGOTXkFkiEiuYMAnAvXAZP4rhMIqeHOPXSUQan4Bd8QnafDcpovOSLnadDmKw==
version "4.0.0-alpha.60"
resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-4.0.0-alpha.60.tgz#5ad203aed5a8569b0f1753945a21a05efa2234d2"
integrity sha512-fadlYsPJF+0fx2lRuyqAuJj7hAS1tLDdIEEdov5jlrpb5pp4b+mRDUqQTUxi4inRZHS1bEXpU8QWUhO6xX88aA==
dependencies:
"@babel/runtime" "^7.4.4"
"@material-ui/utils" "^4.11.2"
Expand All @@ -3279,8 +3279,8 @@
react-is "^16.8.0 || ^17.0.0"

"@material-ui/monorepo@https://github.com/mui-org/material-ui.git#master":
version "4.11.1"
resolved "https://github.com/mui-org/material-ui.git#c8b7ad499c6573c63ccb7e1fb21eb2124c6e77c8"
version "4.12.1"
resolved "https://github.com/mui-org/material-ui.git#1c5beec4be20eae30e75c69ab513bbfec3e9baaf"

"@material-ui/monorepo@https://github.com/mui-org/material-ui.git#next":
version "5.0.0-beta.0"
Expand Down Expand Up @@ -3308,10 +3308,10 @@
jss-plugin-vendor-prefixer "^10.5.1"
prop-types "^15.7.2"

"@material-ui/system@^4.11.3":
version "4.11.3"
resolved "https://registry.yarnpkg.com/@material-ui/system/-/system-4.11.3.tgz#466bc14c9986798fd325665927c963eb47cc4143"
integrity sha512-SY7otguNGol41Mu2Sg6KbBP1ZRFIbFLHGK81y4KYbsV2yIcaEPOmsCK6zwWlp+2yTV3J/VwT6oSBARtGIVdXPw==
"@material-ui/system@^4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@material-ui/system/-/system-4.12.1.tgz#2dd96c243f8c0a331b2bb6d46efd7771a399707c"
integrity sha512-lUdzs4q9kEXZGhbN7BptyiS1rLNHe6kG9o8Y307HCvF4sQxbCgpL2qi+gUk+yI8a2DNk48gISEQxoxpgph0xIw==
dependencies:
"@babel/runtime" "^7.4.4"
"@material-ui/utils" "^4.11.2"
Expand Down