Inventory of how to customize the global theme in v5 #32150
Labels
discussion
docs
Improvements or additions to the documentation
package: system
Specific to @mui/system
Duplicates
Latest version
Current docs
The docs for v5 are really good. In the theme customization section I was taking inventory of how to customize the theme used throughout the app. While doing so, I was not able to fully understand the capability in one or two spots. If it's not just my missing something, I thought it might be worthwhile to clarify in the docs accordingly.
Scope of how to create a theme that is inherently responsive
Here is the summary of how the "theme" as "function that generates a theme", we have the following options enabled by the
mui
createTheme
engineering:createTheme
takes the following value that has "built-in" capacity to respond:The above accomplishes:
"dynamic" comes from changing `className`
The styles are applied when the application of the css selector expression returns the component/node being rendered. The dynamics comes from the ability to change the
className
values ("for free" when the browser dynamically switchespseudo-element
s).Efficiently specify different versions of related components by way of code reuse that that comes with using a function and parameter combination.
The open questions
As I ask the question, I suspect the answer is obvious, but I wanted to clarify. Access the
theme
value:createTheme
encountersstyleOverrides: String
does it create a closure with access to thetheme
value? So, can we set the value ofmui-slot
:color: ${theme.palette.primary.main}
?createTheme
encountersvariants
, does it interpret thestyle
value in a closure with access to thetheme
value?Given that the place to call
createTheme
is at the root of the app by way ofin the event I am using
CssBaseline
, what is the advantage of creatingmyInherentlyDynamicTheme
using theCssBaseline
overrides I saw documented?App
:theme
value using theuseTheme()
hook from'@mui/material/styles'
, butApp
globally; in other words, the question is what prevents'@mui/material/styles'
from providing access to asetTheme
function?<ThemeProvider />
in a context with a theme that depends on the extra context to create another layer of responsiveness. Yes?Is there no way to change
ThemeProvider
's internal ref to theme?If not, this inability to call a
setTheme
directly onThemeProvider
limits the scope of the dynamics of the theme. This limit is the reason for documented approach where we roll-our-ownContext
that hosts[mode, setMode]
? (a context that is a parent toThemeProvider
). Is this right?Thank you in advance to confirming/clarifying.
The text was updated successfully, but these errors were encountered: