@talend/react-cmf
Version:
A framework built on top of best react libraries
61 lines (60 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _component = _interopRequireDefault(require("./component"));
var _useContext = require("./useContext");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* The Inject component let you use the registry to render named component
* using the registry. It will not break the app if component is not found
* but it will display an error.
* @module react-cmf/lib/Inject
* @example
import { Inject } from '@talend/react-cmf';
// this is not the best example but it show the concept
function MyComponent(props) {
return (
<Inject component="Action" onClick={props.onClick}>
<Inject component="Icon" icon={props.icon} />
</Inject>
);
}
*/function NotFoundComponent({
error
}) {
// eslint-disable-next-line no-console
console.error(error);
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: "alert alert-danger",
children: error.message
});
}
NotFoundComponent.propTypes = {
error: _propTypes.default.string.isRequired
};
function Inject({
component,
...props
}) {
const context = (0, _useContext.useCMFContext)();
try {
const Component = _component.default.get(component, context);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
...props
});
} catch (error) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(NotFoundComponent, {
error: error
});
}
}
Inject.propTypes = {
component: _propTypes.default.string.isRequired
};
Inject.NotFoundComponent = NotFoundComponent;
var _default = exports.default = Inject;
//# sourceMappingURL=Inject.component.js.map