Skip to content

Commit

Permalink
[DataGrid] Fix background colors when CSSVarsProvider is used (#12901)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Sep 20, 2024
1 parent ae3659d commit 83e98fb
Showing 1 changed file with 10 additions and 9 deletions.
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 @@ -171,15 +171,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 @@ -780,3 +776,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%))`;
}

0 comments on commit 83e98fb

Please sign in to comment.