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

[core] Remove theme.palette.type check #2679

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import { makeStyles } from '@mui/styles';
import { DataGrid } from '@mui/x-data-grid';
import { randomPrice } from '@mui/x-data-grid-generator';

function getThemePaletteMode(palette) {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();

const useStyles = makeStyles(
(theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import {
} from '@mui/x-data-grid';
import { randomPrice } from '@mui/x-data-grid-generator';

function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();

const useStyles = makeStyles(
(theme: Theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ import {
randomUpdatedDate,
} from '@mui/x-data-grid-generator';

// TODO v5: remove
function getThemePaletteMode(palette) {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme) => {
const backgroundColor =
getThemePaletteMode(theme.palette) === 'dark' ? '#376331' : 'rgb(217 243 190)';
theme.palette.mode === 'dark' ? '#376331' : 'rgb(217 243 190)';
return {
root: {
'& .MuiDataGrid-cell--editable': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ import {
randomUpdatedDate,
} from '@mui/x-data-grid-generator';

// TODO v5: remove
function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme: Theme) => {
const backgroundColor =
getThemePaletteMode(theme.palette) === 'dark' ? '#376331' : 'rgb(217 243 190)';
theme.palette.mode === 'dark' ? '#376331' : 'rgb(217 243 190)';
return {
root: {
'& .MuiDataGrid-cell--editable': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import {
randomUpdatedDate,
} from '@mui/x-data-grid-generator';

// TODO v5: remove
function getThemePaletteMode(palette) {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ import {
randomUpdatedDate,
} from '@mui/x-data-grid-generator';

// TODO v5: remove
function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme: Theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import { createTheme } from '@mui/material/styles';
import { makeStyles } from '@mui/styles';
import { useGridApiRef, DataGridPro } from '@mui/x-data-grid-pro';

// TODO v5: remove
function getThemePaletteMode(palette) {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import {
DataGridPro,
} from '@mui/x-data-grid-pro';

// TODO v5: remove
function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme: Theme) => {
const isDark = getThemePaletteMode(theme.palette) === 'dark';
const isDark = theme.palette.mode === 'dark';

return {
root: {
Expand Down
15 changes: 4 additions & 11 deletions docs/src/pages/components/data-grid/style/StylingRowsGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { useDemoData } from '@mui/x-data-grid-generator';
import { createTheme, darken, lighten } from '@mui/material/styles';
import { makeStyles } from '@mui/styles';

// TODO v5: remove
function getThemePaletteMode(palette) {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme) => {
const isDark = theme.palette.mode === 'dark';

const getBackgroundColor = (color) =>
getThemePaletteMode(theme.palette) === 'dark'
? darken(color, 0.6)
: lighten(color, 0.6);
isDark ? darken(color, 0.6) : lighten(color, 0.6);

const getHoverBackgroundColor = (color) =>
getThemePaletteMode(theme.palette) === 'dark'
? darken(color, 0.5)
: lighten(color, 0.5);
isDark ? darken(color, 0.5) : lighten(color, 0.5);

return {
root: {
Expand Down
15 changes: 4 additions & 11 deletions docs/src/pages/components/data-grid/style/StylingRowsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { useDemoData } from '@mui/x-data-grid-generator';
import { createTheme, darken, lighten, Theme } from '@mui/material/styles';
import { makeStyles } from '@mui/styles';

// TODO v5: remove
function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme: Theme) => {
const isDark = theme.palette.mode === 'dark';

const getBackgroundColor = (color) =>
getThemePaletteMode(theme.palette) === 'dark'
? darken(color, 0.6)
: lighten(color, 0.6);
isDark ? darken(color, 0.6) : lighten(color, 0.6);

const getHoverBackgroundColor = (color) =>
getThemePaletteMode(theme.palette) === 'dark'
? darken(color, 0.5)
: lighten(color, 0.5);
isDark ? darken(color, 0.5) : lighten(color, 0.5);

return {
root: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { darken, lighten, Theme } from '@mui/material/styles';
import { makeStyles } from '@mui/styles';
import { getThemePaletteMode, muiStyleAlpha, createTheme } from '../../utils/utils';
import { muiStyleAlpha, createTheme } from '../../utils/utils';
import { gridClasses } from '../../gridClasses';

const defaultTheme = createTheme();
export const useStyles = makeStyles(
(theme: Theme) => {
const borderColor =
getThemePaletteMode(theme.palette) === 'light'
theme.palette.mode === 'light'
? lighten(muiStyleAlpha(theme.palette.divider, 1), 0.88)
: darken(muiStyleAlpha(theme.palette.divider, 1), 0.68);

Expand Down Expand Up @@ -378,7 +378,7 @@ export const useStyles = makeStyles(
},
};

if (getThemePaletteMode(theme.palette) === 'dark') {
if (theme.palette.mode === 'dark') {
// Values coming from mac OS.
const track = '#202022';
const thumb = '#585859';
Expand Down
5 changes: 0 additions & 5 deletions packages/grid/_modules_/grid/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export function isObject(value: any): value is Record<string, any> {
return typeof value === 'object';
}

// TODO v5: remove
export function getThemePaletteMode(palette: any): string {
return palette.type || palette.mode;
}

export function getMuiVersion(): string {
if (!('fade' in styles)) {
return 'v5';
Expand Down
10 changes: 3 additions & 7 deletions packages/grid/x-grid-data-generator/src/renderer/renderPnl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clsx from 'clsx';
import { Theme } from '@mui/material/styles';
import { createStyles, makeStyles } from '@mui/styles';
import { GridCellParams } from '../../../_modules_/grid';
import { createTheme, getThemePaletteMode } from '../../../_modules_/grid/utils/utils';
import { createTheme } from '../../../_modules_/grid/utils/utils';

const defaultTheme = createTheme();
const useStyles = makeStyles(
Expand All @@ -15,15 +15,11 @@ const useStyles = makeStyles(
},
positive: {
color:
getThemePaletteMode(theme.palette) === 'light'
? theme.palette.success.dark
: theme.palette.success.light,
theme.palette.mode === 'light' ? theme.palette.success.dark : theme.palette.success.light,
},
negative: {
color:
getThemePaletteMode(theme.palette) === 'light'
? theme.palette.error.dark
: theme.palette.error.light,
theme.palette.mode === 'light' ? theme.palette.error.dark : theme.palette.error.light,
},
}),
{ defaultTheme },
Expand Down