UNPKG

@alicloud/console-components

Version:

Alibaba Cloud React Components

46 lines (45 loc) 2.44 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React, { forwardRef } from 'react'; import hoistNonReactStatics from 'hoist-non-react-statics'; import cls from 'classnames'; import { ETheme } from '../enum'; import { isCnChars2Or3, isCnChars4 } from '../utils'; import { useCssTheme } from '../hook'; /** * 判断 button 类组件是否是 2-4 汉字 and ⁉️ */ // eslint-disable-next-line @typescript-eslint/naming-convention export default function hocCnChar(WrappedComponents) { var Wrapper = forwardRef(function (props, ref) { var _a; var children = props.children, className = props.className; var theme = useCssTheme(); // 判断是否是 2-3 个汉字 // xconsole 相关主题不需要该功能 if (theme !== ETheme.WIND && !theme.startsWith(ETheme.XCONSOLE) && typeof children === 'string' && isCnChars2Or3(children)) { return React.createElement(WrappedComponents, __assign({}, __assign(__assign({}, props), { className: cls('isTwoToThreeCNCharBtn', className), ref: ref })), children); } // 判断是否是 4 个汉字 // xconsole 相关主题不需要该功能 if (theme !== ETheme.WIND && !theme.startsWith(ETheme.XCONSOLE) && typeof children === 'string' && isCnChars4(children)) { return React.createElement(WrappedComponents, __assign({}, __assign(__assign({}, props), { className: cls('isFourCNCharBtn', className), ref: ref })), children); } // 判断是否只有图标 if (React.Children.count(children) === 1 && ((_a = children === null || children === void 0 ? void 0 : children.type) === null || _a === void 0 ? void 0 : _a.displayName) === 'Config(Icon)') { return React.createElement(WrappedComponents, __assign({}, __assign(__assign({}, props), { className: cls('isOnlyIcon', className), ref: ref })), children); } return React.createElement(WrappedComponents, __assign({}, props, { className: className, ref: ref }), children); }); hoistNonReactStatics(Wrapper, WrappedComponents); return Wrapper; }