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] Support theme.vars #6784

Merged
merged 22 commits into from
Nov 24, 2022
Merged

Conversation

alexfauquette
Copy link
Member

Fix #6702

Similar to #6778 but more difficult, because we have some customization such as

const borderColor =
    theme.palette.mode === 'light'
      ? lighten(alpha(theme.palette.divider, 1), 0.88)
      : darken(alpha(theme.palette.divider, 1), 0.68);

I do not see how to manage it because lighten and darken are not CSS functions

@mui-bot
Copy link

mui-bot commented Nov 8, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-6784--material-ui-x.netlify.app/

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 640.7 1,219.3 656.5 843.44 211.011
Sort 100k rows ms 641.2 1,071.2 773.1 880.1 155.032
Select 100k rows ms 200.8 311.7 230.6 249.88 44.781
Deselect 100k rows ms 136.4 288.2 187.8 196.98 51.332

Generated by 🚫 dangerJS against b7c3643

@@ -35,7 +35,9 @@ const GridOverlayRoot = styled('div', {
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: alpha(theme.palette.background.default, theme.palette.action.disabledOpacity),
backgroundColor: theme.vars
? `rgba(${theme.vars.palette.common.backgroundChannel} / ${theme.vars.palette.action.disabledOpacity})`
Copy link
Member

Choose a reason for hiding this comment

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

This will yield a different result in dark mode. I think we can add another token for theme.vars.palette.background.defaultChannel in Material UI.

@siriwatknp
Copy link
Member

siriwatknp commented Nov 9, 2022

const borderColor =
    theme.palette.mode === 'light'
      ? lighten(alpha(theme.palette.divider, 1), 0.88)
      : darken(alpha(theme.palette.divider, 1), 0.68);

I do not see how to manage it because lighten and darken are not CSS functions

I think we can add extra tokens in Material UI for these cases. The downside is the bundle size of the generated HTML (with inline CSS). Ideally, the DataGrid and Pickers should use the existing tokens with the least JS color manipulation.

@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Nov 9, 2022
@alexfauquette
Copy link
Member Author

For the following part of the code, I realised it comes from the Table component, so I use theme.vars.palette.TableCell.border

const borderColor =
    theme.palette.mode === 'light'
      ? lighten(alpha(theme.palette.divider, 1), 0.88)
      : darken(alpha(theme.palette.divider, 1), 0.68);

I also did the following modification

-theme.vars.palette.common.backgroundChannel
+theme.vars.palette.background.defaultChannel

@siriwatknp do you take care of creating the background.defaultChannel in core?

Comment on lines +28 to +33
// eslint-disable-next-line no-nested-ternary
const borderColor = theme.vars
? theme.vars.palette.TableCell.border
: theme.palette.mode === 'light'
? lighten(alpha(theme.palette.divider, 1), 0.88)
: darken(alpha(theme.palette.divider, 1), 0.68);
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@siriwatknp
Copy link
Member

@siriwatknp do you take care of creating the background.defaultChannel in core?

Sure!

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 10, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

1 similar comment
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 16, 2022
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 17, 2022
package.json Outdated Show resolved Hide resolved
alexfauquette and others added 3 commits November 17, 2022 10:47
Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com>
Signed-off-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 22, 2022
@@ -81,7 +81,7 @@ const GridColumnHeadersPinnedColumnHeaders = styled('div', {
display: 'flex',
flexDirection: 'column',
boxShadow: theme.shadows[2],
backgroundColor: theme.palette.background.default,
backgroundColor: (theme.vars || theme).palette.background.default,
...(theme.palette.mode === 'dark' && {
Copy link
Member

Choose a reason for hiding this comment

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

Opps! this would not work.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it can help, getOverlayAlpha(elevation) is defined as a function, but used with only elevation=2

getOverlayAlpha(2) = 0.07

Copy link
Member

@siriwatknp siriwatknp Nov 24, 2022

Choose a reason for hiding this comment

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

Found the solution, it can be fixed this way:

There is a variable for the dark mode overlay theme.vars.overlays[2]. https://github.com/siriwatknp/material-ui/blob/system/use-css-theme-vars/packages/mui-material/src/styles/experimental_extendTheme.js#L75

You can use it like this:

...theme.vars ? {
  backgroundImage: theme.vars.overlays[2],
} : {
  ...theme.palette.mode === 'dark' && {
    backgroundImage: ...
  }
}

When CSS variables are detected, the styles will be:

  ...
  background-image: var(--mui-overlays-2);

This works fine on both light & dark modes.

@@ -128,7 +128,7 @@ const VirtualScrollerPinnedColumns = styled('div', {
position: 'sticky',
overflow: 'hidden',
zIndex: 1,
backgroundColor: theme.palette.background.default,
backgroundColor: (theme.vars || theme).palette.background.default,
...(theme.palette.mode === 'dark' && { backgroundImage: darkModeBackgroundImage }),
Copy link
Member

Choose a reason for hiding this comment

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

This too.

@@ -157,7 +157,7 @@ const VirtualScrollerPinnedRows = styled('div', {
position: 'sticky',
// should be above the detail panel
zIndex: 3,
backgroundColor: theme.palette.background.default,
backgroundColor: (theme.vars || theme).palette.background.default,
...(theme.palette.mode === 'dark' && { backgroundImage: darkModeBackgroundImage }),
Copy link
Member

Choose a reason for hiding this comment

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

This too.

@@ -81,7 +81,7 @@ const GridColumnHeadersPinnedColumnHeaders = styled('div', {
display: 'flex',
flexDirection: 'column',
boxShadow: theme.shadows[2],
backgroundColor: theme.palette.background.default,
backgroundColor: (theme.vars || theme).palette.background.default,
...(theme.palette.mode === 'dark' && {
backgroundImage: `linear-gradient(${alpha('#fff', getOverlayAlpha(2))}, ${alpha(
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

🤩 Awesomeee!

@alexfauquette
Copy link
Member Author

Thanks for all the feedbacks :)

@alexfauquette alexfauquette merged commit 043522f into mui:next Nov 24, 2022
@alexfauquette alexfauquette deleted the css-var-datagrid branch November 24, 2022 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support CSS theme variables in DataGrid and DatePickers
4 participants