mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 15:49:10 +08:00
a73abb9487
* feat: Badge.Ribbon, wip * feat: Badge.Ribbon * test: Badge.Ribbon * chore * test: update snapshot * fix: Badge.RibbonStyle IE 11 * chore * docs * chore * chore * refactor * docs * refactor: remove placement left & right * Update components/badge/index.zh-CN.md Co-authored-by: xrkffgg <xrkffgg@gmail.com> * Update components/badge/index.en-US.md Co-authored-by: xrkffgg <xrkffgg@gmail.com> * docs: demo change * docs * refactor: use css * refactor: use css rtl * refactor Co-authored-by: xrkffgg <xrkffgg@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 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, className, `${prefixCls}-placement-${placement}`, {
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
[`${prefixCls}-color-${color}`]: colorInPreset,
|
|
});
|
|
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 }}>
|
|
{text}
|
|
<div className={`${prefixCls}-corner`} style={cornerColorStyle} />
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Ribbon;
|