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.objectContaining({
colorPrimary: '#1677ff',
'blue-6': '#1677ff',
}),
);
});

View File

@ -27,6 +27,7 @@ export type {
} from './maps';
export { PresetColors } from './presetColors';
export type {
LegacyColorPalettes,
ColorPalettes,
PresetColorKey,
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 { ColorMapToken } from './colors';
import type { FontMapToken } from './font';
@ -37,6 +37,7 @@ export interface CommonMapToken extends StyleMapToken {
export interface MapToken
extends SeedToken,
ColorPalettes,
LegacyColorPalettes,
ColorMapToken,
SizeMapToken,
HeightMapToken,

View File

@ -14,12 +14,19 @@ export const PresetColors = [
'gold',
] as const;
export type PresetColorKey = typeof PresetColors[number];
export type PresetColorKey = (typeof PresetColors)[number];
export type PresetColorType = Record<PresetColorKey, string>;
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 = {
[key in `${keyof PresetColorType}${ColorPaletteKeyIndex}`]: string;
};

View File

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

View File

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