ant-design/components/badge/Ribbon.tsx
偏右 3ef6ea3ead
refactor: 📦 some styles to reduce css bundle size (#27129)
* refactor: some styles to reduce css bundle size

* test: update snapshot

* fix snapshot

* fix test case

* fix addonAfter

* fix firefox style

* reduce riddon css size

* fix Input.Group border radius

* remove unused css selectors

* fix test cov

* fix search button hover border

* fix rtl textarea clear icon style

* update demos

* fix search rtl style

* fix input search style
2020-10-13 21:16:20 +08:00

59 lines
1.7 KiB
TypeScript

import * as React from 'react';
import classNames from 'classnames';
import { LiteralUnion } from '../_util/type';
import { PresetColorType } from '../_util/colors';
import { ConfigContext } from '../config-provider';
import { isPresetColor } from './utils';
type RibbonPlacement = 'start' | 'end';
export interface RibbonProps {
className?: string;
prefixCls?: string;
style?: React.CSSProperties; // style of ribbon element, not the wrapper
text?: React.ReactNode;
color?: LiteralUnion<PresetColorType, string>;
children?: React.ReactNode;
placement?: RibbonPlacement;
}
const Ribbon: React.FC<RibbonProps> = function Ribbon({
className,
prefixCls: customizePrefixCls,
style,
color,
children,
text,
placement = 'end',
}) {
const { getPrefixCls, direction } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('ribbon', customizePrefixCls);
const colorInPreset = isPresetColor(color);
const ribbonCls = classNames(
prefixCls,
`${prefixCls}-placement-${placement}`,
{
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-color-${color}`]: colorInPreset,
},
className,
);
const colorStyle: React.CSSProperties = {};
const cornerColorStyle: React.CSSProperties = {};
if (color && !colorInPreset) {
colorStyle.background = color;
cornerColorStyle.color = color;
}
return (
<div className={`${prefixCls}-wrapper`}>
{children}
<div className={ribbonCls} style={{ ...colorStyle, ...style }}>
<span className={`${prefixCls}-text`}>{text}</span>
<div className={`${prefixCls}-corner`} style={cornerColorStyle} />
</div>
</div>
);
};
export default Ribbon;