Commit 25c42c38 authored by hz's avatar hz

使用@ant-design/colors生成主题色系;兼容IE

parent 5e99cb1f
......@@ -2,8 +2,9 @@
import MergeLessPlugin from 'antd-pro-merge-less';
// import AntDesignThemePlugin from 'antd-theme-webpack-plugin';
const ThemeColorReplacer = require('webpack-theme-color-replacer');
import ThemeColorReplacer from 'webpack-theme-color-replacer';
import path from 'path';
import generate from '@ant-design/colors/lib/generate';
function getModulePackageName(module) {
if (!module.context) return null;
......@@ -42,7 +43,7 @@ export default config => {
]);
config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [{
fileName: 'css/theme-colors.css',
matchColors: getAntdSerials('#1890ff'), // 主色系列
matchColors: generate('#1890ff'), // 主色系列
}]);
// config.plugin('ant-design-theme').use(AntDesignThemePlugin, [
// {
......@@ -85,14 +86,3 @@ export default config => {
},
});
};
function getAntdSerials(color) {
const lightens = new Array(9).fill().map((t, i) => {
return ThemeColorReplacer.varyColor.lighten(color, i / 10);
});
// 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值
const darkens = new Array(6).fill().map((t, i) => {
return ThemeColorReplacer.varyColor.darken(color, i / 10);
});
return lightens.concat(darkens);
}
const client = require('webpack-theme-color-replacer/client')
/* eslint-disable import/no-extraneous-dependencies */
import generate from '@ant-design/colors/lib/generate';
import client from 'webpack-theme-color-replacer/client'
export default {
primaryColor: '#1890ff',
getAntdSerials (color) {
// 淡化(即less的tint)
const lightens = new Array(9).fill().map((t, i) => {
return client.varyColor.lighten(color, i / 10)
})
// 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值
const darkens = new Array(6).fill().map((t, i) => {
return client.varyColor.darken(color, i / 10)
})
return lightens.concat(darkens)
return generate(color)
},
changeColor (newColor) {
const lastColor = this.lastColor || this.primaryColor
......@@ -20,8 +14,9 @@ export default {
oldColors: this.getAntdSerials(lastColor), // current colors array. The same as `matchColors`
newColors: this.getAntdSerials(newColor || this.primaryColor) // new colors array, one-to-one corresponde with `oldColors`
}
const promise = client.changer.changeColor(options)
const promise = client.changer.changeColor(options, Promise);
this.lastColor = lastColor
return promise
}
}
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