Commit 25c42c38 authored by hz's avatar hz

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

parent 5e99cb1f
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
import MergeLessPlugin from 'antd-pro-merge-less'; import MergeLessPlugin from 'antd-pro-merge-less';
// import AntDesignThemePlugin from 'antd-theme-webpack-plugin'; // 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 path from 'path';
import generate from '@ant-design/colors/lib/generate';
function getModulePackageName(module) { function getModulePackageName(module) {
if (!module.context) return null; if (!module.context) return null;
...@@ -42,7 +43,7 @@ export default config => { ...@@ -42,7 +43,7 @@ export default config => {
]); ]);
config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [{ config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [{
fileName: 'css/theme-colors.css', fileName: 'css/theme-colors.css',
matchColors: getAntdSerials('#1890ff'), // 主色系列 matchColors: generate('#1890ff'), // 主色系列
}]); }]);
// config.plugin('ant-design-theme').use(AntDesignThemePlugin, [ // config.plugin('ant-design-theme').use(AntDesignThemePlugin, [
// { // {
...@@ -85,14 +86,3 @@ export default config => { ...@@ -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);
}
...@@ -82,15 +82,14 @@ ...@@ -82,15 +82,14 @@
"resize-observer-polyfill": "^1.5.1", "resize-observer-polyfill": "^1.5.1",
"umi": "^2.4.4", "umi": "^2.4.4",
"umi-plugin-react": "^1.7.2", "umi-plugin-react": "^1.7.2",
"umi-request": "^1.0.5", "umi-request": "^1.0.5"
"webpack-theme-color-replacer": "^1.1.3"
}, },
"devDependencies": { "devDependencies": {
"@types/history": "^4.7.2", "@types/history": "^4.7.2",
"@types/react": "^16.8.1", "@types/react": "^16.8.1",
"@types/react-dom": "^16.0.11", "@types/react-dom": "^16.0.11",
"antd-pro-merge-less": "^1.0.0", "antd-pro-merge-less": "^1.0.0",
"antd-theme-webpack-plugin": "^1.2.0", "@ant-design/colors": "^3.1.0",
"babel-eslint": "^10.0.1", "babel-eslint": "^10.0.1",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"check-prettier": "^1.0.1", "check-prettier": "^1.0.1",
...@@ -127,7 +126,8 @@ ...@@ -127,7 +126,8 @@
"tslint": "^5.12.1", "tslint": "^5.12.1",
"tslint-config-prettier": "^1.17.0", "tslint-config-prettier": "^1.17.0",
"tslint-react": "^3.6.0", "tslint-react": "^3.6.0",
"umi-plugin-ga": "^1.1.3" "umi-plugin-ga": "^1.1.3",
"webpack-theme-color-replacer": "^1.1.4"
}, },
"optionalDependencies": { "optionalDependencies": {
"puppeteer": "^1.12.1" "puppeteer": "^1.12.1"
......
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 { export default {
primaryColor: '#1890ff', primaryColor: '#1890ff',
getAntdSerials (color) { getAntdSerials (color) {
// 淡化(即less的tint) return generate(color)
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)
}, },
changeColor (newColor) { changeColor (newColor) {
const lastColor = this.lastColor || this.primaryColor const lastColor = this.lastColor || this.primaryColor
...@@ -20,8 +14,9 @@ export default { ...@@ -20,8 +14,9 @@ export default {
oldColors: this.getAntdSerials(lastColor), // current colors array. The same as `matchColors` 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` 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 this.lastColor = lastColor
return promise 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