@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
32 lines • 1.44 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, { isValidElement } from 'react';
import classNames from 'classnames';
import Text from '../components/Text';
/**
* Convert a primitive into a component if needed.
*
* @param props - React FC Props.
* @param props.children - data value to be validated and wrapped into an element.
* @returns - FC of provided child if needed.
*/
var PrimitiveConverter = function (props) {
var children = props.children, className = props.className, _a = props.tagName, tagName = _a === void 0 ? 'p' : _a, _b = props.fontStyle, fontStyle = _b === void 0 ? 'body-primary' : _b;
var isElement = isValidElement(children);
var addedProps = {};
if (className) {
addedProps.className = isElement ? classNames(children['classNames'], className) : className;
}
return isElement ? (React.cloneElement(children, __assign({}, addedProps))) : (React.createElement(Text, __assign({}, addedProps, { tagName: tagName, type: fontStyle }), children));
};
export { PrimitiveConverter };
//# sourceMappingURL=component-conversions.js.map