UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

40 lines (39 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.withClassnameHOC = void 0; var _react = _interopRequireDefault(require("react")); var _classname = require("@bem-react/classname"); var _excludeProps = require("../excludeProps"); var _withHOCConstructor = require("./withHOCConstructor"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var __assign = void 0 && (void 0).__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); }; // 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 */ var withClassnameHOC = function (blockName, matchProps) { return (0, _withHOCConstructor.withHOCConstructor)({ matchProps: matchProps, privateProps: Object.keys(matchProps) }, function (Component) { return function (props) { var className = props.className; var newProps = (0, _excludeProps.excludeProps)(props, Object.keys(matchProps)); return /*#__PURE__*/_react.default.createElement(Component, __assign({}, newProps, { className: (0, _classname.cn)(blockName)(matchProps, [className]) })); }; }); }; exports.withClassnameHOC = withClassnameHOC;