ant-design/components/tooltip/util.ts
lijianan 9dc33bda54
chore: set default value for style (#38689)
* fix: set default value for style

* Update components/tooltip/util.ts

Co-authored-by: afc163 <afc163@gmail.com>

Co-authored-by: afc163 <afc163@gmail.com>
2022-11-18 18:37:18 +08:00

25 lines
750 B
TypeScript

/* 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),
});
const overlayStyle: React.CSSProperties = {};
const arrowStyle: React.CSSProperties = {};
if (color && !PresetColorRegex.test(color)) {
overlayStyle.background = color;
// @ts-ignore
arrowStyle['--antd-arrow-background-color'] = color;
}
return { className, overlayStyle, arrowStyle };
}