fix: less var (#46250)

This commit is contained in:
MadCcc 2023-12-04 20:07:20 +08:00 committed by GitHub
parent 2d6ba24713
commit 7bd08ba257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 20 deletions

View File

@ -37,6 +37,7 @@ describe('Theme', () => {
expect(result.current!.token).toEqual( expect(result.current!.token).toEqual(
expect.objectContaining({ expect.objectContaining({
colorPrimary: '#1677ff', colorPrimary: '#1677ff',
'blue-6': '#1677ff',
}), }),
); );
}); });

View File

@ -27,6 +27,7 @@ export type {
} from './maps'; } from './maps';
export { PresetColors } from './presetColors'; export { PresetColors } from './presetColors';
export type { export type {
LegacyColorPalettes,
ColorPalettes, ColorPalettes,
PresetColorKey, PresetColorKey,
PresetColorType, PresetColorType,

View File

@ -1,4 +1,4 @@
import type { ColorPalettes } from '../presetColors'; import type { ColorPalettes, LegacyColorPalettes } from '../presetColors';
import type { SeedToken } from '../seeds'; import type { SeedToken } from '../seeds';
import type { ColorMapToken } from './colors'; import type { ColorMapToken } from './colors';
import type { FontMapToken } from './font'; import type { FontMapToken } from './font';
@ -37,6 +37,7 @@ export interface CommonMapToken extends StyleMapToken {
export interface MapToken export interface MapToken
extends SeedToken, extends SeedToken,
ColorPalettes, ColorPalettes,
LegacyColorPalettes,
ColorMapToken, ColorMapToken,
SizeMapToken, SizeMapToken,
HeightMapToken, HeightMapToken,

View File

@ -14,12 +14,19 @@ export const PresetColors = [
'gold', 'gold',
] as const; ] as const;
export type PresetColorKey = typeof PresetColors[number]; export type PresetColorKey = (typeof PresetColors)[number];
export type PresetColorType = Record<PresetColorKey, string>; export type PresetColorType = Record<PresetColorKey, string>;
type ColorPaletteKeyIndex = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; type ColorPaletteKeyIndex = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
export type LegacyColorPalettes = {
/**
* @deprecated
*/
[key in `${keyof PresetColorType}-${ColorPaletteKeyIndex}`]: string;
};
export type ColorPalettes = { export type ColorPalettes = {
[key in `${keyof PresetColorType}${ColorPaletteKeyIndex}`]: string; [key in `${keyof PresetColorType}${ColorPaletteKeyIndex}`]: string;
}; };

View File

@ -1,6 +1,12 @@
import { generate } from '@ant-design/colors'; import { generate } from '@ant-design/colors';
import type { DerivativeFunc } from '@ant-design/cssinjs'; import type { DerivativeFunc } from '@ant-design/cssinjs';
import type { ColorPalettes, MapToken, PresetColorType, SeedToken } from '../../interface'; import type {
ColorPalettes,
LegacyColorPalettes,
MapToken,
PresetColorType,
SeedToken,
} from '../../interface';
import { defaultPresetColors } from '../seed'; import { defaultPresetColors } from '../seed';
import genColorMapToken from '../shared/genColorMapToken'; import genColorMapToken from '../shared/genColorMapToken';
import { generateColorPalettes, generateNeutralColorPalettes } from './colors'; import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
@ -12,17 +18,21 @@ const derivative: DerivativeFunc<SeedToken, MapToken> = (token, mapToken) => {
const colors = generate(token[colorKey], { theme: 'dark' }); const colors = generate(token[colorKey], { theme: 'dark' });
return new Array(10).fill(1).reduce((prev, _, i) => { return new Array(10).fill(1).reduce((prev, _, i) => {
prev[`${colorKey}-${i + 1}`] = colors[i];
prev[`${colorKey}${i + 1}`] = colors[i]; prev[`${colorKey}${i + 1}`] = colors[i];
return prev; return prev;
}, {}) as ColorPalettes; }, {}) as ColorPalettes & LegacyColorPalettes;
}) })
.reduce((prev, cur) => { .reduce(
prev = { (prev, cur) => {
...prev, prev = {
...cur, ...prev,
}; ...cur,
return prev; };
}, {} as ColorPalettes); return prev;
},
{} as ColorPalettes & LegacyColorPalettes,
);
const mergedMapToken = mapToken ?? defaultAlgorithm(token); const mergedMapToken = mapToken ?? defaultAlgorithm(token);

View File

@ -1,7 +1,13 @@
import { generate } from '@ant-design/colors'; import { generate } from '@ant-design/colors';
import genControlHeight from '../shared/genControlHeight'; import genControlHeight from '../shared/genControlHeight';
import genSizeMapToken from '../shared/genSizeMapToken'; import genSizeMapToken from '../shared/genSizeMapToken';
import type { ColorPalettes, MapToken, PresetColorType, SeedToken } from '../../interface'; import type {
ColorPalettes,
LegacyColorPalettes,
MapToken,
PresetColorType,
SeedToken,
} from '../../interface';
import { defaultPresetColors } from '../seed'; import { defaultPresetColors } from '../seed';
import genColorMapToken from '../shared/genColorMapToken'; import genColorMapToken from '../shared/genColorMapToken';
import genCommonMapToken from '../shared/genCommonMapToken'; import genCommonMapToken from '../shared/genCommonMapToken';
@ -14,17 +20,21 @@ export default function derivative(token: SeedToken): MapToken {
const colors = generate(token[colorKey]); const colors = generate(token[colorKey]);
return new Array(10).fill(1).reduce((prev, _, i) => { return new Array(10).fill(1).reduce((prev, _, i) => {
prev[`${colorKey}-${i + 1}`] = colors[i];
prev[`${colorKey}${i + 1}`] = colors[i]; prev[`${colorKey}${i + 1}`] = colors[i];
return prev; return prev;
}, {}) as ColorPalettes; }, {}) as ColorPalettes & LegacyColorPalettes;
}) })
.reduce((prev, cur) => { .reduce(
prev = { (prev, cur) => {
...prev, prev = {
...cur, ...prev,
}; ...cur,
return prev; };
}, {} as ColorPalettes); return prev;
},
{} as ColorPalettes & LegacyColorPalettes,
);
return { return {
...token, ...token,