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 background colors when CSSVarsProvider is used #12901

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all 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: 10 additions & 9 deletions packages/x-data-grid/src/components/containers/GridRootStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,11 @@ export const GridRootStyles = styled('div', {
t.palette.action.selectedOpacity + t.palette.action.hoverOpacity,
);

const pinnedHoverBackground = t.vars
? hoverColor
: blend(pinnedBackground, hoverColor, hoverOpacity);
const pinnedSelectedBackground = t.vars
? selectedBackground
: blend(pinnedBackground, selectedBackground, selectedOpacity);
const pinnedSelectedHoverBackground = t.vars
? hoverColor
: blend(pinnedSelectedBackground, hoverColor, hoverOpacity);
const blendFn = t.vars ? blendCssVars : blend;

const pinnedHoverBackground = blendFn(pinnedBackground, hoverColor, hoverOpacity);
const pinnedSelectedBackground = blendFn(pinnedBackground, selectedBackground, selectedOpacity);
const pinnedSelectedHoverBackground = blendFn(pinnedSelectedBackground, hoverColor, hoverOpacity);

const selectedStyles = {
backgroundColor: selectedBackground,
Expand Down Expand Up @@ -678,3 +674,8 @@ function blend(background: string, overlay: string, opacity: number, gamma: numb
values: rgb as any,
});
}

const removeOpacity = (color: string) => `rgb(from ${color} r g b / 1)`;
function blendCssVars(background: string, overlay: string, opacity: number) {
return `color-mix(in srgb,${background}, ${removeOpacity(overlay)} calc(${opacity} * 100%))`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't sure if we could use color-mix. What are our supported browser versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to validate this approach.
color-mix requires iOS >= 16.2, while we currently support >= 15.4. Same for Safari on MacOS. Other browsers seem to match what we have in our browserslist.

Do you have other ideas for solving this issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this is the only thing that could work with CSS variables.

}