为什么材质UI要有多个颜色声明?



调色板主题更新是否也会影响应用程序上的其他元素,如按钮?

如果我们这样写:

import blue from '@material-ui/core/colors/blue';
const theme = createTheme({
palette: {
primary: blue,
},
})

按钮组件将不会更改为创建的原色。此外,如果我创建一个框并提供以下内容:

<Box color='primary.main'>primary.main</Box>

它不会改变文本的颜色,除非我做以下操作

<Box color='palette.primary.main'>primary.main</Box>

背后有逻辑吗?我假设它与自动改变颜色有关,当进入不同的色调或深色时,但我不是100%确定。

您必须访问main属性来更改它:

import blue from '@material-ui/core/colors/blue';
const theme = createTheme({
palette: {
primary: {
main : blue,
}
},
})

最新更新