[Paper] Support dark mode brightening based on elevation#25522
[Paper] Support dark mode brightening based on elevation#25522
Conversation
|
@material-ui/lab: parsed: +0.05% , gzip: +0.09% |
|
Josh is probably busy. @m4theushw Do you want move forward? :) |
| paper: grey[800], | ||
| default: '#303030', | ||
| paper: '#121212', | ||
| default: '#121212', |
There was a problem hiding this comment.
Sorry for the question but is it expected to have such a dark background color as the default on the default dark theme? It doesn't look right.
There was a problem hiding this comment.
Yes, this color comes from the Material Design specification: https://material.io/design/color/dark-theme.html#properties
There was a problem hiding this comment.
I do agree with this general comment, it does look a bit strange. I'm saving this feedback. We have a designer joining the team full-time in the new few weeks.
- Material Design:
#121212brightness 7% - YouTube Music:
#040404brightness 1% - YouTube:
#131313brightness 9% - Facebook:
#131314brightness 10% - Chakra:
#141821brightness 17% - HeadlessUI:
#0E131Dbrightness 15% - linear.app product:
#17181Bbrightness 14%, linear.app homepage#070707brightness 2% - Twitter:
#000000brightness 0%, Dimmed#11182016% - GitHub:
#0C0E12brightness 9%, Dimmed#1A1D2218% - StackOverflow
#222222brightness 18%
It also seems that the documentation should use the default values of the palette.
There was a problem hiding this comment.
I was also initially shocked at the difference, but I've actually come to quite like the new Material defaults. I assume it also makes extra sense for newer fancy screens which can optimize energy usage for dark pixels.
I imagine it would be useful though (if it doesn't already exist) to be able to specify a base brightness and have the rest of the elevation levels automatically scale, similar to how color palettes can automatically infer dark/light based on tonalOffset.
There was a problem hiding this comment.
I imagine it would be useful though (if it doesn't already exist) to be able to specify a base brightness and have the rest of the elevation levels automatically scale, similar to how color palettes can automatically infer dark/light based on tonalOffset.
Done in #25522
There was a problem hiding this comment.
Ahh I guess I should have looked at the actual code :P, I see the backgroundImage alphaOverlay now. Awesome stuff!
|
hello, this is a breaking change visually, it should be documented |
|
I found this new behavior does not look good in our product. Use the following code in the theme to disable it temporally. components: {
MuiPaper: {
styleOverrides: { root: { backgroundImage: 'unset' } },
},
}, |
|
@m4theushw Do you want to update the migration to the v4 docs page with the proposed workaround? I have updated the PR's description to make it easier for developers. |
|
I think my workaround is not the correct way to recommended to all developers, there should be a new prop to control this behavior so developers can set this prop default to false in the theme to get the old behavior. |
|
@Jack-Works This behavior is disabled when the variant is outlined or the elevation is zero. Is this enough? |
But what if I want elevation or variant? 🤔 |
|
@Jack-Works If you want a variant elevation with an elevation and not the background change in dark mode. Do you really want to use the concept of Paper from Material Design? You could do: <Box sx={{ boxShadow: 3, p: 2, borderRadius: 1 }}>Hello</Box>@m4theushw What do you think? |
|
I ended up getting dark mode looking as it did before just by changing the default palette base: import React, { useMemo } from 'react'
import { createMuiTheme, ThemeProvider } from '@material-ui/core'
import { deepPurple, pink, red } from '@material-ui/core/colors'
import useDarkMode from 'use-dark-mode'
import CssBaseline from '@material-ui/core/CssBaseline'
function Theme({ path, children }) {
const darkMode = useDarkMode()
const isDark = darkMode.value
const theme = React.useMemo(() => {
return createMuiTheme({
palette: {
mode: isDark ? 'dark' : 'light',
primary: PRIMARY,
secondary: SECONDARY,
error: red,
background: {
paper: isDark ? '#424242' : '#fff',
default: isDark ? '#303030' : '#fafafa',
},
},
})
}, [darkMode.value])
return (
<ThemeProvider theme={theme}>
<>
<CssBaseline />
{children}
</>
</ThemeProvider>
)
}
export default Theme; |

Breaking changes
[Paper] Change the background opacity based on the elevation in dark mode. This change was done to follow the Material Design guidelines. You can revert it in the theme:
Closes #18309
Based on #21748
Preview: https://deploy-preview-25522--material-ui.netlify.app/components/paper/
Reference: https://material.io/design/color/dark-theme.html#properties