Commit c0bf7546 authored by jim's avatar jim Committed by 陈帅

add theme change

parent 6816dd86
......@@ -30,15 +30,12 @@ const ThemeColor = ({ colors, value, onChange }) => {
'#EB2F96',
];
}
return (
<div className={styles.themeColor}>
<h3 className={styles.title}>主题颜色</h3>
{colorList.map((color) => {
{colorList.map(color => {
const classname =
value === color
? `${styles.colorBlock} ${styles.active}`
: styles.colorBlock;
value === color ? `${styles.colorBlock} ${styles.active}` : styles.colorBlock;
return (
<Tag
className={classname}
......
import React, { PureComponent, Fragment } from 'react';
import { Select, List, Switch, Divider, Radio } from 'antd';
import { Select, message, List, Switch, Divider, Radio } from 'antd';
import DrawerMenu from 'rc-drawer-menu';
import styles from './index.less';
import ThemeColor from './ThemeColor';
......@@ -133,6 +133,17 @@ class Sidebar extends PureComponent {
togglerContent = () => {
this.changeSetting('collapse', !this.state.collapse);
};
colorChange = color => {
window.less
.modifyVars({
'@primary-color': color,
})
.then(() => {})
.catch(() => {
message.error(`Failed to update theme`);
});
this.changeSetting('themeColor', color);
};
render() {
const radioStyle = {
display: 'block',
......@@ -174,10 +185,7 @@ class Sidebar extends PureComponent {
<ColorBlock color="#E9E9E9" title="浅色导航" />
</Radio>
</RadioGroup>
<ThemeColor
value={this.state.themeColor}
onChange={color => this.changeSetting('themeColor', color)}
/>
<ThemeColor value={this.state.themeColor} onChange={this.colorChange} />
</Body>
<Divider style={{ margin: 0 }} />
<Body title="导航设置 ">
......
import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
const path = require('path');
export default webpackConfig => {
const options = {
antDir: path.join(__dirname, './node_modules/antd'),
stylesDir: path.join(__dirname, './src'),
varFile: path.join(__dirname, './node_modules/antd/lib/style/themes/default.less'),
mainLessFile: path.join(__dirname, './src/index.less'),
themeVariables: ['@primary-color'],
indexFileName: 'index.html',
};
const themePlugin = new AntDesignThemePlugin(options);
// in config object
webpackConfig.plugins.push(themePlugin);
return webpackConfig;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment