mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-15 13:38:29 +02:00

* feat: Adapt text color based on Tooltip.color * feat: add default textcolor * feat: Adjust the range of using white * feat: Adjust color algorithm * test: update snap --------- Co-authored-by: 刘欢 <lh01217311@antgroup.com>
28 lines
990 B
TypeScript
28 lines
990 B
TypeScript
import type * as React from 'react';
|
|
import classNames from 'classnames';
|
|
|
|
import { isPresetColor } from '../_util/colors';
|
|
import { ColorGenInput } from '../color-picker/interface';
|
|
import { generateColor } from '../color-picker/util';
|
|
|
|
export function parseColor(prefixCls: string, color?: string) {
|
|
const isInternalColor = isPresetColor(color);
|
|
|
|
const className = classNames({
|
|
[`${prefixCls}-${color}`]: color && isInternalColor,
|
|
});
|
|
|
|
const overlayStyle: React.CSSProperties = {};
|
|
const arrowStyle: React.CSSProperties = {};
|
|
const rgb = generateColor(color as ColorGenInput).toRgb();
|
|
const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
|
|
const textColor = luminance < 0.5 ? '#FFF' : '#000';
|
|
if (color && !isInternalColor) {
|
|
overlayStyle.background = color;
|
|
overlayStyle['--ant-tooltip-color'] = textColor;
|
|
// @ts-ignore
|
|
arrowStyle['--antd-arrow-background-color'] = color;
|
|
}
|
|
|
|
return { className, overlayStyle, arrowStyle };
|
|
}
|