-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Add default background color to grid #16066
base: master
Are you sure you want to change the base?
Conversation
const pinnedBackground = t.mixins.MuiDataGrid?.pinnedBackground ?? containerBackground; | ||
: (t.mixins.MuiDataGrid?.background ?? t.palette.background.default); | ||
const headerBackground = t.mixins.MuiDataGrid?.headerBackground ?? background; | ||
const pinnedBackground = t.mixins.MuiDataGrid?.pinnedBackground ?? background; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, containerBackground
is applied to column headers and pinned rows. IMO, it makes more sense to use the pinnedBackground
color for pinned rows. With this change, containerBackground
would only change the color of column headers, hence why I have renamed it to headerBackground
.
It would be a second breaking change in addition to adding a background color to the grid.
Any concerns with this change? @mui/xgrid
@@ -663,7 +664,7 @@ export const GridRootStyles = styled('div', { | |||
backgroundColor: pinnedSelectedBackgroundColor, | |||
}, | |||
}, | |||
[`& .${c.virtualScrollerContent} .${c.row}`]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/data/data-grid/style/style.md
Outdated
// Headers, and top & bottom fixed rows | ||
containerBackground: '#343434', | ||
// Container background | ||
background: '#fafaf9', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to handle dark mode here? It would be great to have this included in this demo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned here #16066 (comment) and updated the docs
const background = t.vars | ||
? t.vars.palette.background.default | ||
: (t.mixins.MuiDataGrid?.containerBackground ?? t.palette.background.default); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't t.mixins.MuiDataGrid?.containerBackground
be used if provided, regardless of t.vars
?
const background =
t.mixins.MuiDataGrid?.containerBackground ??
(t.vars ? t.vars.palette.background.default : t.palette.background.default);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the priority was wrong, good spot. Fixed e2e9b02
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
// Pinned rows and columns background | ||
pinnedBg: '#f1f5f9', | ||
// Column header background | ||
headerBg: '#eaeff5', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another breaking change to make Data Grid theming consistent with Material UI.
Instead of using the mixins
theme property, we add DataGrid
to the palette
—in addition to being consistent with other component color options, this gives us built-in support for light/dark mode theming with colorSchemes
(as shown in the snippet below this).
Material use bg
instead of background
, so also updated the property names for consistency.
### CSS classes and styling | ||
- `bg`: Sets the entire grid's background color (new property) | ||
- `headerBg`: Sets the header background color (previously named `containerBackground`) | ||
- `pinnedBg`: Sets pinned rows and columns background color (previously named `pinnedBackground`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `pinnedBg`: Sets pinned rows and columns background color (previously named `pinnedBackground`) | |
- `pinnedBg`: Sets the background color of pinned rows and columns (previously named `pinnedBackground`) |
@@ -116,26 +116,64 @@ The following demo illustrates how this can be achieved. | |||
|
|||
{{"demo": "StripedGrid.js", "bg": "inline"}} | |||
|
|||
## Theme header and pinned sections | |||
## Theme container, header and pinned sections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oxford comma. 😁 and is "Theme" necessary here? If not I think it's better without, for the sake of keeping the header as short as possible. I'm on the fence about whether or not to pluralize everything so I'll leave that to your judgement.
## Theme container, header and pinned sections | |
## Containers, headers, and pinned sections |
By default, the Data Grid uses the Material UI `theme.palette.background.default` color for the background of its header and pinned sections. These elements require a solid color to hide the scrollable content behind them. You can override that color with the following configuration: | ||
By default, the Data Grid uses the Material UI `theme.palette.background.default` color for the background color of the grid container, the column headers, and the pinned rows and columns. | ||
|
||
The various background colors can be overridden with the following configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
passive –> active voice
The various background colors can be overridden with the following configuration: | |
You can override these background colors with the following theme configuration: |
}, | ||
}, | ||
}); | ||
``` | ||
|
||
Material UI v6 users can use the `colorSchemes` property to specify different colors for light and dark mode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nice to add h3s for ### Material UI v6
and ### Material UI v5
so users can quickly differentiate between the two samples when skimming
Closes #15517
Changelog
Breaking changes
The Data Grid now has a default background color, and its customization has moved from
theme.mixins.MuiDataGrid
totheme.palette.DataGrid
with the following properties:bg
: Sets the entire grid's background color (new property)headerBg
: Sets the header background color (previously namedcontainerBackground
)pinnedBg
: Sets pinned rows and columns background color (previously namedpinnedBackground
)