UNPKG

2.08 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4import classNames from 'classnames';
5import * as React from 'react';
6import { ConfigContext } from '../config-provider';
7import useStyle from './style';
8import { isPresetColor } from './utils';
9var Ribbon = function Ribbon(_ref) {
10 var _classNames;
11 var className = _ref.className,
12 customizePrefixCls = _ref.prefixCls,
13 style = _ref.style,
14 color = _ref.color,
15 children = _ref.children,
16 text = _ref.text,
17 _ref$placement = _ref.placement,
18 placement = _ref$placement === void 0 ? 'end' : _ref$placement;
19 var _React$useContext = React.useContext(ConfigContext),
20 getPrefixCls = _React$useContext.getPrefixCls,
21 direction = _React$useContext.direction;
22 var prefixCls = getPrefixCls('ribbon', customizePrefixCls);
23 var colorInPreset = isPresetColor(color);
24 var ribbonCls = classNames(prefixCls, prefixCls + "-placement-" + placement, (_classNames = {}, _defineProperty(_classNames, prefixCls + "-rtl", direction === 'rtl'), _defineProperty(_classNames, prefixCls + "-color-" + color, colorInPreset), _classNames), className);
25 var _useStyle = useStyle(prefixCls),
26 _useStyle2 = _slicedToArray(_useStyle, 2),
27 wrapSSR = _useStyle2[0],
28 hashId = _useStyle2[1];
29 var colorStyle = {};
30 var cornerColorStyle = {};
31 if (color && !colorInPreset) {
32 colorStyle.background = color;
33 cornerColorStyle.color = color;
34 }
35 return wrapSSR( /*#__PURE__*/React.createElement("div", {
36 className: classNames(prefixCls + "-wrapper", hashId)
37 }, children, /*#__PURE__*/React.createElement("div", {
38 className: classNames(ribbonCls, hashId),
39 style: _extends(_extends({}, colorStyle), style)
40 }, /*#__PURE__*/React.createElement("span", {
41 className: prefixCls + "-text"
42 }, text), /*#__PURE__*/React.createElement("div", {
43 className: prefixCls + "-corner",
44 style: cornerColorStyle
45 }))));
46};
47export default Ribbon;
\No newline at end of file