Reactjs 材质ui自定义主题实现
接下来如何在材质ui中实现自定义主题?Reactjs 材质ui自定义主题实现,reactjs,material-ui,Reactjs,Material Ui,接下来如何在材质ui中实现自定义主题? 我读了文档,但我真的不理解它很简单,这里有一个例子 // First we need the theme provider and the theme creator import {createMuiTheme, MuiThemeProvider} from 'material-ui/styles'; // For this example I'll also be using the amber and blue color profiles imp
我读了文档,但我真的不理解它很简单,这里有一个例子
// First we need the theme provider and the theme creator
import {createMuiTheme, MuiThemeProvider} from 'material-ui/styles';
// For this example I'll also be using the amber and blue color profiles
import amber from 'material-ui/colors/amber';
import blue from 'material-ui/colors/blue';
// Now let us create our theme
const theme = createMuiTheme({
palette: {
type: 'dark',
primary: amber,
secondary: {
...blue // I'm using the spread operator because I want to overwrite some colors
A400: '#A7FFEB' // Overwrite the accent 400 color with custom
}
}
});
// Let my components know about the theme
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<App/>
</MuiThemeProvider>
)
因此,如果您想创建自己的,您可以非常轻松地创建一个遵循上述接口的对象。主题提供程序接受主调色板、次调色板和错误调色板。它根据您配置组件的方式在内部决定使用该调色板的颜色
您可以设置大量其他选项,完整的文档如下所示
这里是我开发的一个自定义脚本,如果有帮助的话,它可以帮助构建自定义主题
import tinycolor from 'tinycolor2'
function buildPaletteFrom(color, accent) {
accent = accent || color;
color = tinycolor(color).darken(25);
let i = 1;
let palette = {};
while (i < 10) {
color = color.lighten(5);
palette[(10 - i) * 100] = color.toHexString();
i++;
}
palette['50'] = tinycolor(palette['100']).lighten(5);
palette['contrastDefaultColor'] = tinycolor(palette['500']).isLight() ? dark : light;
palette['A100'] = tinycolor(accent).lighten(20).saturate().brighten().toHexString();
palette['A200'] = tinycolor(accent).lighten(15).saturate().brighten().toHexString();
palette['A400'] = tinycolor(accent).toHexString();
palette['A700'] = tinycolor(accent).darken(10).saturate().brighten().toHexString();
if (palette['A400'] === palette['500']) {
palette['A400'] = tinycolor(palette['500']).lighten(5).saturate().brighten().toHexString();
}
return palette
}
这很简单这里有个例子
// First we need the theme provider and the theme creator
import {createMuiTheme, MuiThemeProvider} from 'material-ui/styles';
// For this example I'll also be using the amber and blue color profiles
import amber from 'material-ui/colors/amber';
import blue from 'material-ui/colors/blue';
// Now let us create our theme
const theme = createMuiTheme({
palette: {
type: 'dark',
primary: amber,
secondary: {
...blue // I'm using the spread operator because I want to overwrite some colors
A400: '#A7FFEB' // Overwrite the accent 400 color with custom
}
}
});
// Let my components know about the theme
ReactDOM.render(
<MuiThemeProvider theme={theme}>
<App/>
</MuiThemeProvider>
)
因此,如果您想创建自己的,您可以非常轻松地创建一个遵循上述接口的对象。主题提供程序接受主调色板、次调色板和错误调色板。它根据您配置组件的方式在内部决定使用该调色板的颜色
您可以设置大量其他选项,完整的文档如下所示
这里是我开发的一个自定义脚本,如果有帮助的话,它可以帮助构建自定义主题
import tinycolor from 'tinycolor2'
function buildPaletteFrom(color, accent) {
accent = accent || color;
color = tinycolor(color).darken(25);
let i = 1;
let palette = {};
while (i < 10) {
color = color.lighten(5);
palette[(10 - i) * 100] = color.toHexString();
i++;
}
palette['50'] = tinycolor(palette['100']).lighten(5);
palette['contrastDefaultColor'] = tinycolor(palette['500']).isLight() ? dark : light;
palette['A100'] = tinycolor(accent).lighten(20).saturate().brighten().toHexString();
palette['A200'] = tinycolor(accent).lighten(15).saturate().brighten().toHexString();
palette['A400'] = tinycolor(accent).toHexString();
palette['A700'] = tinycolor(accent).darken(10).saturate().brighten().toHexString();
if (palette['A400'] === palette['500']) {
palette['A400'] = tinycolor(palette['500']).lighten(5).saturate().brighten().toHexString();
}
return palette
}
提到你提到的文档。提到你提到的文档。如果有帮助,我添加了一些代码来生成主题。如果有帮助,我添加了一些代码来生成主题