|
1 | 1 | const path = require('path') |
2 | 2 | const webpack = require('webpack') |
3 | 3 | const ThemeColorReplacer = require('webpack-theme-color-replacer') |
| 4 | +const generate = require('@ant-design/colors/lib/generate').default |
4 | 5 |
|
5 | 6 | function resolve (dir) { |
6 | 7 | return path.join(__dirname, dir) |
@@ -29,7 +30,20 @@ module.exports = { |
29 | 30 | // 生成仅包含颜色的替换样式(主题色等) |
30 | 31 | new ThemeColorReplacer({ |
31 | 32 | fileName: 'css/theme-colors.css', |
32 | | - matchColors: getAntdSerials('#1890ff') // 主色系列 |
| 33 | + matchColors: getAntdSerials('#1890ff'), // 主色系列 |
| 34 | + // 改变样式选择器,解决样式覆盖问题 |
| 35 | + changeSelector (selector) { |
| 36 | + switch (selector) { |
| 37 | + case '.ant-calendar-today .ant-calendar-date': |
| 38 | + return ':not(.ant-calendar-selected-date)' + selector |
| 39 | + case '.ant-btn:focus,.ant-btn:hover': |
| 40 | + return '.ant-btn:focus:not(.ant-btn-primary),.ant-btn:hover:not(.ant-btn-primary)' |
| 41 | + case '.ant-btn.active,.ant-btn:active': |
| 42 | + return '.ant-btn.active:not(.ant-btn-primary),.ant-btn:active:not(.ant-btn-primary)' |
| 43 | + default : |
| 44 | + return selector |
| 45 | + } |
| 46 | + } |
33 | 47 | }) |
34 | 48 | ] |
35 | 49 | }, |
@@ -106,12 +120,10 @@ module.exports = { |
106 | 120 | } |
107 | 121 |
|
108 | 122 | function getAntdSerials (color) { |
109 | | - var lightens = new Array(9).fill().map((t, i) => { |
| 123 | + // 淡化(即less的tint) |
| 124 | + const lightens = new Array(9).fill().map((t, i) => { |
110 | 125 | return ThemeColorReplacer.varyColor.lighten(color, i / 10) |
111 | 126 | }) |
112 | | - // 此处为了简化,采用了darken。实际按color.less需求可以引入tinycolor, colorPalette变换得到颜色值 |
113 | | - var darkens = new Array(6).fill().map((t, i) => { |
114 | | - return ThemeColorReplacer.varyColor.darken(color, i / 10) |
115 | | - }) |
116 | | - return lightens.concat(darkens) |
| 127 | + const colorPalettes = generate(color) |
| 128 | + return lightens.concat(colorPalettes) |
117 | 129 | } |
0 commit comments