UNPKG

@alicloud/console-components

Version:
60 lines (59 loc) 2.99 kB
"use strict"; 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); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // 判断button类组件是否是2-4汉字 var react_1 = __importDefault(require("react")); var hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics")); var classnames_1 = __importDefault(require("classnames")); var useCssVar_1 = require("./useCssVar"); var rxTwoToThreeCNChar = /^[\u4e00-\u9fa5]{2,3}$/; var rxFourCNChar = /^[\u4e00-\u9fa5]{4}$/; var isTwoToThreeCNChar = rxTwoToThreeCNChar.test.bind(rxTwoToThreeCNChar); var isFourCNChar = rxFourCNChar.test.bind(rxFourCNChar); var CNCHARHOC = function (WrappedComponents) { var Wrapper = react_1.default.forwardRef(function (props, ref) { var _a, _b; var children = props.children, className = props.className; var theme = useCssVar_1.useCssVar('--alicloudfe-components-theme').trim(); // 判断是否是2-3个汉字 if ( // xconsole相关主题不需要该功能 theme !== 'wind' && !theme.startsWith('xconsole') && typeof children === 'string' && isTwoToThreeCNChar(children)) { return (react_1.default.createElement(WrappedComponents, __assign({}, props, { className: classnames_1.default('isTwoToThreeCNCharBtn', className), ref: ref }), children)); } // 判断是否是4个汉字 if ( // xconsole相关主题不需要该功能 theme !== 'wind' && !theme.startsWith('xconsole') && typeof children === 'string' && isFourCNChar(children)) { return (react_1.default.createElement(WrappedComponents, __assign({}, props, { className: classnames_1.default('isFourCNCharBtn', className), ref: ref }), children)); } // 判断是否只有图标 if (react_1.default.Children.count(children) === 1 && ((_b = (_a = children) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.displayName) === 'Config(Icon)') { return (react_1.default.createElement(WrappedComponents, __assign({}, props, { className: classnames_1.default('isOnlyIcon', className), ref: ref }), children)); } return (react_1.default.createElement(WrappedComponents, __assign({}, props, { className: className, ref: ref }), children)); }); hoist_non_react_statics_1.default(Wrapper, WrappedComponents); return Wrapper; }; exports.default = CNCHARHOC;