2022-09-22 16:55:55 +08:00
|
|
|
/* eslint-disable import/prefer-default-export */
|
|
|
|
|
|
|
|
import type * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { PresetColorTypes } from '../_util/colors';
|
|
|
|
|
|
|
|
const PresetColorRegex = new RegExp(`^(${PresetColorTypes.join('|')})(-inverse)?$`);
|
|
|
|
|
|
|
|
export function parseColor(prefixCls: string, color?: string) {
|
|
|
|
const className = classNames({
|
|
|
|
[`${prefixCls}-${color}`]: color && PresetColorRegex.test(color),
|
|
|
|
});
|
|
|
|
|
2022-11-18 18:37:18 +08:00
|
|
|
const overlayStyle: React.CSSProperties = {};
|
|
|
|
const arrowStyle: React.CSSProperties = {};
|
2022-09-22 16:55:55 +08:00
|
|
|
|
|
|
|
if (color && !PresetColorRegex.test(color)) {
|
2022-11-18 18:37:18 +08:00
|
|
|
overlayStyle.background = color;
|
2022-09-22 16:55:55 +08:00
|
|
|
// @ts-ignore
|
2022-11-18 18:37:18 +08:00
|
|
|
arrowStyle['--antd-arrow-background-color'] = color;
|
2022-09-22 16:55:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return { className, overlayStyle, arrowStyle };
|
|
|
|
}
|