Browse Source

feat: move colorLink to seedToken (#43183)

* feat: move colorLink to seedToken

* feat: follow colorInfo
pull/43189/head
MadCcc 1 year ago
committed by GitHub
parent
commit
358905027a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      components/theme/__tests__/token.test.tsx
  2. 23
      components/theme/interface/alias.ts
  3. 27
      components/theme/interface/maps/colors.ts
  4. 8
      components/theme/interface/seeds.ts
  5. 1
      components/theme/themes/seed.ts
  6. 8
      components/theme/themes/shared/genColorMapToken.ts
  7. 4
      components/theme/util/alias.ts

60
components/theme/__tests__/token.test.tsx

@ -10,6 +10,23 @@ import genRadius from '../themes/shared/genRadius';
const { useToken } = theme;
describe('Theme', () => {
const getHookToken = (config?: ThemeConfig) => {
let token: any;
const Demo = () => {
const { token: hookToken } = useToken();
token = hookToken;
return null;
};
render(
<ConfigProvider theme={config}>
<Demo />
</ConfigProvider>,
);
delete token._hashId;
delete token._tokenKey;
return token;
};
it('useTheme', () => {
const { result } = renderHook(() => useToken());
@ -224,23 +241,6 @@ describe('Theme', () => {
});
describe('getDesignToken', () => {
const getHookToken = (config?: ThemeConfig) => {
let token: any;
const Demo = () => {
const { token: hookToken } = useToken();
token = hookToken;
return null;
};
render(
<ConfigProvider theme={config}>
<Demo />
</ConfigProvider>,
);
delete token._hashId;
delete token._tokenKey;
return token;
};
it('default', () => {
const token = theme.getDesignToken();
const hookToken = getHookToken();
@ -276,4 +276,30 @@ describe('Theme', () => {
expect(token.colorPrimary).toEqual('#1668dc');
});
});
describe('colorLink', () => {
it('should follow colorPrimary by default', () => {
const token = getHookToken();
expect(token.colorLink).toEqual(token.colorInfo);
expect(token.colorLinkHover).toEqual(token.colorInfoHover);
expect(token.colorLinkActive).toEqual(token.colorInfoActive);
const token2 = getHookToken({ token: { colorPrimary: '#189cff' } });
expect(token2.colorLink).toEqual(token2.colorInfo);
expect(token2.colorLinkHover).toEqual(token2.colorInfoHover);
expect(token2.colorLinkActive).toEqual(token2.colorInfoActive);
const token3 = getHookToken({ algorithm: [theme.darkAlgorithm] });
expect(token3.colorLink).toEqual(token3.colorInfo);
expect(token3.colorLinkHover).toEqual(token3.colorInfoHover);
expect(token3.colorLinkActive).toEqual(token3.colorInfoActive);
});
it('should be calculated correctly', () => {
const token = getHookToken({ token: { colorLink: '#189cff' } });
expect(token.colorLink).toEqual('#189cff');
expect(token.colorLinkHover).toEqual('#69c8ff');
expect(token.colorLinkActive).toEqual('#0978d9');
});
});
});

23
components/theme/interface/alias.ts

@ -119,6 +119,7 @@ export interface AliasToken extends MapToken {
* @descEN Weak action. Such as `allowClear` or Alert close button
*/
colorIcon: string;
/** */
/**
* @nameZH
@ -128,28 +129,6 @@ export interface AliasToken extends MapToken {
*/
colorIconHover: string;
/**
* @nameZH
* @nameEN Hyperlink color
* @desc
* @descEN Control the color of hyperlink.
*/
colorLink: string;
/**
* @nameZH
* @nameEN Hyperlink hover color
* @desc
* @descEN Control the color of hyperlink when hovering.
*/
colorLinkHover: string;
/**
* @nameZH
* @nameEN Hyperlink active color
* @desc
* @descEN Control the color of hyperlink when clicked.
*/
colorLinkActive: string;
/**
* @nameZH
* @nameEN Highlight color

27
components/theme/interface/maps/colors.ts

@ -531,13 +531,38 @@ interface ColorErrorMapToken {
colorErrorTextActive: string; // 10
}
export interface ColorLinkMapToken {
/**
* @nameZH
* @nameEN Hyperlink color
* @desc
* @descEN Control the color of hyperlink.
*/
colorLink: string;
/**
* @nameZH
* @nameEN Hyperlink hover color
* @desc
* @descEN Control the color of hyperlink when hovering.
*/
colorLinkHover: string;
/**
* @nameZH
* @nameEN Hyperlink active color
* @desc
* @descEN Control the color of hyperlink when clicked.
*/
colorLinkActive: string;
}
export interface ColorMapToken
extends ColorNeutralMapToken,
ColorPrimaryMapToken,
ColorSuccessMapToken,
ColorWarningMapToken,
ColorErrorMapToken,
ColorInfoMapToken {
ColorInfoMapToken,
ColorLinkMapToken {
/**
* @nameZH
* @desc

8
components/theme/interface/seeds.ts

@ -63,6 +63,14 @@ export interface SeedToken extends PresetColorType {
*/
colorBgBase: string;
/**
* @nameZH
* @nameEN Hyperlink color
* @desc
* @descEN Control the color of hyperlink.
*/
colorLink: string;
// ---------- Font ---------- //
/**

1
components/theme/themes/seed.ts

@ -26,6 +26,7 @@ const seedToken: SeedToken = {
colorWarning: '#faad14',
colorError: '#ff4d4f',
colorInfo: '#1677ff',
colorLink: '',
colorTextBase: '',
colorBgBase: '',

8
components/theme/themes/shared/genColorMapToken.ts

@ -28,6 +28,10 @@ export default function genColorMapToken(
const infoColors = generateColorPalettes(colorInfoBase);
const neutralColors = generateNeutralColorPalettes(colorBgBase, colorTextBase);
// Color Link
const colorLink = seed.colorLink || seed.colorInfo;
const linkColors = generateColorPalettes(colorLink);
return {
...neutralColors,
@ -86,6 +90,10 @@ export default function genColorMapToken(
colorInfoText: infoColors[9],
colorInfoTextActive: infoColors[10],
colorLinkHover: linkColors[4],
colorLink: linkColors[6],
colorLinkActive: linkColors[7],
colorBgMask: new TinyColor('#000').setAlpha(0.45).toRgbString(),
colorWhite: '#fff',
};

4
components/theme/util/alias.ts

@ -43,10 +43,6 @@ export default function formatToken(derivativeToken: RawMergedToken): AliasToken
const aliasToken: AliasToken = {
...mergedToken,
colorLink: mergedToken.colorInfoText,
colorLinkHover: mergedToken.colorInfoHover,
colorLinkActive: mergedToken.colorInfoActive,
// ============== Background ============== //
colorFillContent: mergedToken.colorFillSecondary,
colorFillContentHover: mergedToken.colorFill,

Loading…
Cancel
Save