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] Make colors customizable #12614

Merged
merged 10 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
19 changes: 19 additions & 0 deletions docs/data/data-grid/style/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ The following demo illustrates how this can be achieved.

{{"demo": "StripedGrid.js", "bg": "inline"}}

## Theme header & pinned sections
romgrk marked this conversation as resolved.
Show resolved Hide resolved

The Data Grid will use by default the MUI `theme.palette.background.default` color for the background of its header and pinned sections, which require a solid color to hide the scrollable content behind them. You can override that color with the following configuration:
romgrk marked this conversation as resolved.
Show resolved Hide resolved

```tsx
import { createTheme } from '@mui/material/styles';

const theme = createTheme({
mixins: {
DataGrid: {
// Pinned columns sections
pinnedBackground: '#340606',
// Headers, and top & bottom fixed rows
containerBackground: '#343434',
},
},
});
```

## Custom theme

The following demo leverages the CSS customization API to match the Ant Design specification.
Expand Down
13 changes: 11 additions & 2 deletions packages/x-data-grid/src/components/containers/GridRootStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const columnHeaderStyles = {
},
};

declare module '@mui/material' {
interface Mixins {
MBilalShafi marked this conversation as resolved.
Show resolved Hide resolved
DataGrid: {
romgrk marked this conversation as resolved.
Show resolved Hide resolved
containerBackground?: string;
pinnedBackground?: string;
MBilalShafi marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
romgrk marked this conversation as resolved.
Show resolved Hide resolved

export const GridRootStyles = styled('div', {
name: 'MuiDataGrid',
slot: 'Root',
Expand Down Expand Up @@ -126,9 +135,9 @@ export const GridRootStyles = styled('div', {

const containerBackground = t.vars
? t.vars.palette.background.default
: t.palette.background.default;
: t.mixins.DataGrid?.containerBackground ?? t.palette.background.default;

const pinnedBackground = containerBackground;
const pinnedBackground = t.mixins.DataGrid?.pinnedBackground ?? containerBackground;

const overlayBackground = t.vars
? `rgba(${t.vars.palette.background.defaultChannel} / ${t.vars.palette.action.disabledOpacity})`
Expand Down