react-elegant-ui
Version:
Elegant UI components, made by BEM best practices for react
32 lines • 1.21 kB
JavaScript
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 from 'react';
import { cn } from '@bem-react/classname';
import { excludeProps } from '../excludeProps';
import { withHOCConstructor } from './withHOCConstructor';
// TODO: introduce option `visualModifiers` to get props by names from array and build className from its
/**
* Make visual HOC which by match exclude specified props and convert to className
*/
export var withClassnameHOC = function (blockName, matchProps) {
return withHOCConstructor({
matchProps: matchProps,
privateProps: Object.keys(matchProps)
}, function (Component) {
return function (props) {
var className = props.className;
var newProps = excludeProps(props, Object.keys(matchProps));
return /*#__PURE__*/React.createElement(Component, __assign({}, newProps, {
className: cn(blockName)(matchProps, [className])
}));
};
});
};