util.js 825 B

12345678910111213141516171819202122232425
  1. import classNames from 'classnames';
  2. import { isPresetColor } from '../_util/colors';
  3. import { generateColor } from '../color-picker/util';
  4. export function parseColor(prefixCls, color) {
  5. const isInternalColor = isPresetColor(color);
  6. const className = classNames({
  7. [`${prefixCls}-${color}`]: color && isInternalColor
  8. });
  9. const overlayStyle = {};
  10. const arrowStyle = {};
  11. const rgb = generateColor(color).toRgb();
  12. const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
  13. const textColor = luminance < 0.5 ? '#FFF' : '#000';
  14. if (color && !isInternalColor) {
  15. overlayStyle.background = color;
  16. overlayStyle['--ant-tooltip-color'] = textColor;
  17. // @ts-ignore
  18. arrowStyle['--antd-arrow-background-color'] = color;
  19. }
  20. return {
  21. className,
  22. overlayStyle,
  23. arrowStyle
  24. };
  25. }