1 | "use client";
|
2 |
|
3 | import * as React from 'react';
|
4 | import classNames from 'classnames';
|
5 | import { isPresetColor } from '../_util/colors';
|
6 | import { ConfigContext } from '../config-provider';
|
7 | import useStyle from './style/ribbon';
|
8 | const Ribbon = props => {
|
9 | const {
|
10 | className,
|
11 | prefixCls: customizePrefixCls,
|
12 | style,
|
13 | color,
|
14 | children,
|
15 | text,
|
16 | placement = 'end',
|
17 | rootClassName
|
18 | } = props;
|
19 | const {
|
20 | getPrefixCls,
|
21 | direction
|
22 | } = React.useContext(ConfigContext);
|
23 | const prefixCls = getPrefixCls('ribbon', customizePrefixCls);
|
24 | const wrapperCls = `${prefixCls}-wrapper`;
|
25 | const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, wrapperCls);
|
26 | const colorInPreset = isPresetColor(color, false);
|
27 | const ribbonCls = classNames(prefixCls, `${prefixCls}-placement-${placement}`, {
|
28 | [`${prefixCls}-rtl`]: direction === 'rtl',
|
29 | [`${prefixCls}-color-${color}`]: colorInPreset
|
30 | }, className);
|
31 | const colorStyle = {};
|
32 | const cornerColorStyle = {};
|
33 | if (color && !colorInPreset) {
|
34 | colorStyle.background = color;
|
35 | cornerColorStyle.color = color;
|
36 | }
|
37 | return wrapCSSVar(React.createElement("div", {
|
38 | className: classNames(wrapperCls, rootClassName, hashId, cssVarCls)
|
39 | }, children, React.createElement("div", {
|
40 | className: classNames(ribbonCls, hashId),
|
41 | style: Object.assign(Object.assign({}, colorStyle), style)
|
42 | }, React.createElement("span", {
|
43 | className: `${prefixCls}-text`
|
44 | }, text), React.createElement("div", {
|
45 | className: `${prefixCls}-corner`,
|
46 | style: cornerColorStyle
|
47 | }))));
|
48 | };
|
49 | if (process.env.NODE_ENV !== 'production') {
|
50 | Ribbon.displayName = 'Ribbon';
|
51 | }
|
52 | export default Ribbon; |
\ | No newline at end of file |