Skip to content

Commit

Permalink
fix: less var (ant-design#46250)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadCcc authored Dec 4, 2023
1 parent 2d6ba24 commit 7bd08ba
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions components/theme/__tests__/token.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Theme', () => {
expect(result.current!.token).toEqual(
expect.objectContaining({
colorPrimary: '#1677ff',
'blue-6': '#1677ff',
}),
);
});
Expand Down
1 change: 1 addition & 0 deletions components/theme/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type {
} from './maps';
export { PresetColors } from './presetColors';
export type {
LegacyColorPalettes,
ColorPalettes,
PresetColorKey,
PresetColorType,
Expand Down
3 changes: 2 additions & 1 deletion components/theme/interface/maps/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -37,6 +37,7 @@ export interface CommonMapToken extends StyleMapToken {
export interface MapToken
extends SeedToken,
ColorPalettes,
LegacyColorPalettes,
ColorMapToken,
SizeMapToken,
HeightMapToken,
Expand Down
9 changes: 8 additions & 1 deletion components/theme/interface/presetColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
28 changes: 19 additions & 9 deletions components/theme/themes/dark/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

Expand Down
28 changes: 19 additions & 9 deletions components/theme/themes/default/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down

0 comments on commit 7bd08ba

Please sign in to comment.