-
-
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] Fix background colors when CSSVarsProvider
is used
#12901
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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%))`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KenanYusuf What do you think about this approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cherniavskii I left a comment here regarding I think it's a great alternative and does exactly what we need besides the couple of versions of Safari that do not support it. |
||
} |
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.
Wasn't sure if we could use
color-mix
. What are our supported browser versions?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.
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?
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.
No, this is the only thing that could work with CSS variables.