forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRibbon.tsx
52 lines (46 loc) · 1.7 KB
/
Ribbon.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { LiteralUnion } from '../_util/type';
import { PresetColorType } from '../_util/colors';
import { isPresetColor } from './utils';
import { defaultConfigProvider } from '../config-provider';
import { HTMLAttributes, FunctionalComponent, VNodeTypes, inject, CSSProperties } from 'vue';
type RibbonPlacement = 'start' | 'end';
export interface RibbonProps extends HTMLAttributes {
prefixCls?: string;
text?: VNodeTypes;
color?: LiteralUnion<PresetColorType, string>;
placement?: RibbonPlacement;
}
const Ribbon: FunctionalComponent<RibbonProps> = (props, { attrs, slots }) => {
const { prefixCls: customizePrefixCls, color, text, placement = 'end' } = props;
const { class: className, style } = attrs;
const children = slots.default?.();
const { getPrefixCls, direction } = inject('configProvider', defaultConfigProvider);
const prefixCls = getPrefixCls('ribbon', customizePrefixCls);
const colorInPreset = isPresetColor(color);
const ribbonCls = [
prefixCls,
`${prefixCls}-placement-${placement}`,
{
[`${prefixCls}-rtl`]: direction === 'rtl',
[`${prefixCls}-color-${color}`]: colorInPreset,
},
className,
];
const colorStyle: CSSProperties = {};
const cornerColorStyle: CSSProperties = {};
if (color && !colorInPreset) {
colorStyle.background = color;
cornerColorStyle.color = color;
}
return (
<div class={`${prefixCls}-wrapper`}>
{children}
<div class={ribbonCls} style={{ ...colorStyle, ...(style as CSSProperties) }}>
<span class={`${prefixCls}-text`}>{text}</span>
<div class={`${prefixCls}-corner`} style={cornerColorStyle} />
</div>
</div>
);
};
Ribbon.displayName = 'ABadgeRibbon';
export default Ribbon;