mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-08 18:39:20 +08:00
* fix(button): add theme-aware preset color hover/active tokens
Add ${colorKey}Hover and ${colorKey}Active tokens that swap values based on dark/light mode for improved contrast and user experience.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: add preset color hover/active tokens for consistent button interaction
- Add xxxHover and xxxActive tokens for preset colors in genColorMapToken
- Override these tokens in dark mode to swap hover/active values
- Update ButtonToken type to include PresetColorHoverActiveMap
- Update button variant styles to use new hover/active tokens
- Fix #56656: button hover/active state inconsistency in dark mode
* test: add @csstools to compileModules
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* test: support .mjs files in Jest configuration
- Updated .jest.js transform pattern to include .mjs files
- Simplified .jest.node.js transform patterns
- Added jest-mjs-transformer.js for babel-jest mjs handling
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* test: remove unused jest-mjs-transformer.js
- Removed jest-mjs-transformer.js as it's no longer used
- .mjs files are now handled by the updated transform patterns in Jest configs
* test: add .mjs support to .jest.image.js
- Updated .jest.image.js transform pattern to include .mjs files
- fixes image test failures due to ES module parsing errors
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { generate } from '@ant-design/colors';
|
|
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
|
|
|
import type { MapToken, PresetColorType, SeedToken } from '../../interface';
|
|
import { PresetColors } from '../../interface/presetColors';
|
|
import defaultAlgorithm from '../default';
|
|
import { defaultPresetColors } from '../seed';
|
|
import genColorMapToken from '../shared/genColorMapToken';
|
|
import { generateColorPalettes, generateNeutralColorPalettes } from './colors';
|
|
|
|
const derivative: DerivativeFunc<SeedToken, MapToken> = (token, mapToken) => {
|
|
const colorPalettes = Object.keys(defaultPresetColors)
|
|
.map((colorKey) => {
|
|
const colors = generate(token[colorKey as keyof PresetColorType], { theme: 'dark' });
|
|
return Array.from({ length: 10 }, () => 1).reduce<Record<string, string>>((prev, _, i) => {
|
|
prev[`${colorKey}-${i + 1}`] = colors[i];
|
|
prev[`${colorKey}${i + 1}`] = colors[i];
|
|
return prev;
|
|
}, {});
|
|
})
|
|
.reduce((prev, cur) => {
|
|
prev = { ...prev, ...cur };
|
|
return prev;
|
|
}, {});
|
|
|
|
const mergedMapToken = mapToken ?? defaultAlgorithm(token);
|
|
|
|
const colorMapToken = genColorMapToken(token, {
|
|
generateColorPalettes,
|
|
generateNeutralColorPalettes,
|
|
});
|
|
|
|
const presetColorHoverActiveTokens = PresetColors.reduce<Record<string, string>>(
|
|
(prev, colorKey) => {
|
|
const colorBase = token[colorKey as keyof PresetColorType];
|
|
if (colorBase) {
|
|
const colorPalette = generateColorPalettes(colorBase);
|
|
prev[`${colorKey}Hover`] = colorPalette[7];
|
|
prev[`${colorKey}Active`] = colorPalette[5];
|
|
}
|
|
return prev;
|
|
},
|
|
{},
|
|
);
|
|
|
|
return {
|
|
...mergedMapToken,
|
|
|
|
// Dark tokens
|
|
...colorPalettes,
|
|
|
|
// Colors
|
|
...colorMapToken,
|
|
|
|
...presetColorHoverActiveTokens,
|
|
|
|
// Customize selected item background color
|
|
// https://github.com/ant-design/ant-design/issues/30524#issuecomment-871961867
|
|
colorPrimaryBg: colorMapToken.colorPrimaryBorder,
|
|
colorPrimaryBgHover: colorMapToken.colorPrimaryBorderHover,
|
|
};
|
|
};
|
|
|
|
export default derivative;
|