UNPKG

@alicloud/console-components

Version:

Alibaba Cloud React Components

32 lines (31 loc) 1.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); }; /* eslint-disable react/display-name */ import React, { forwardRef } from 'react'; import cls from 'classnames'; import hoist from '../utils/hoist'; /** * 判断 button 类组件是否只有图标 */ // 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; // 判断是否只有图标 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)); }); return hoist(Wrapper, WrappedComponents); }