UNPKG

1.71 kBJavaScriptView Raw
1"use client";
2
3import * as React from 'react';
4import classNames from 'classnames';
5import { isPresetColor } from '../_util/colors';
6import { ConfigContext } from '../config-provider';
7import useStyle from './style/ribbon';
8const 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(/*#__PURE__*/React.createElement("div", {
38 className: classNames(wrapperCls, rootClassName, hashId, cssVarCls)
39 }, children, /*#__PURE__*/React.createElement("div", {
40 className: classNames(ribbonCls, hashId),
41 style: Object.assign(Object.assign({}, colorStyle), style)
42 }, /*#__PURE__*/React.createElement("span", {
43 className: `${prefixCls}-text`
44 }, text), /*#__PURE__*/React.createElement("div", {
45 className: `${prefixCls}-corner`,
46 style: cornerColorStyle
47 }))));
48};
49if (process.env.NODE_ENV !== 'production') {
50 Ribbon.displayName = 'Ribbon';
51}
52export default Ribbon;
\No newline at end of file