@ozen-ui/kit
Version:
React component library
29 lines (28 loc) • 1.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderContent = renderContent;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var react_is_1 = require("react-is");
var mergeDeep_1 = require("../object/mergeDeep");
function renderContent(_a) {
var content = _a.content, props = _a.props;
// primitives: string or number
if (typeof content === 'string' || typeof content === 'number') {
return content;
}
// react-element
if ((0, react_is_1.isElement)(content)) {
return (0, react_1.cloneElement)(content, (0, mergeDeep_1.mergeDeep)(props, content.props));
}
// render-function
if (typeof content === 'function' && !(0, react_1.isValidElement)(content)) {
return content(props);
}
// react-component
if ((0, react_is_1.isValidElementType)(content)) {
var Content = content;
return react_1.default.createElement(Content, tslib_1.__assign({}, props));
}
return null;
}
;