UNPKG

@alicloud/console-components

Version:

Alibaba Cloud React Components

34 lines (33 loc) 1.41 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 cls from 'classnames'; import hoistNonReactStatics from 'hoist-non-react-statics'; import { ETheme } from '../enum'; import { useCssTheme } from '../hook'; import ConfigProvider from '../config-provider'; // eslint-disable-next-line @typescript-eslint/naming-convention export default function hocWithThemeClass(Comp) { // 使用 useCssVar 为它动态添加类名 var Wrapped = ConfigProvider.config(forwardRef(function (props, ref) { var theme = useCssTheme(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore return React.createElement(Comp, __assign({}, __assign(__assign({}, props), { ref: ref, className: cls(props.className, { 'is-wind': theme === ETheme.WIND, 'is-hybridcloud': theme.startsWith(ETheme.HYBRID), 'is-yunxiao': theme.startsWith(ETheme.YUNXIAO) }) }))); })); hoistNonReactStatics(Wrapped, Comp); return Wrapped; }