nope/resources/ui/dynamic/dynamicRenderer.tsx
2020-10-29 19:20:42 +01:00

28 lines
975 B
TypeScript

import React from "react";
import { Alert } from "react-bootstrap";
import { COMPONENTS } from './components';
import { IDynamicRenderSettings } from './interfaces/IDynamicRenderSettings';
class DynamicRenderer extends React.Component<IDynamicRenderSettings, {}> {
constructor(props) {
super(props);
}
public render() {
if (typeof this.props.component === 'string'){
if (typeof COMPONENTS[this.props.component] !== "undefined") {
return React.createElement(COMPONENTS[this.props.component],{ ...this.props.props});
}
// component doesn't exist yet
return (<>
<Alert variant={'danger'}>
Componenten with id {this.props.component} not defined in <code>COMPONENTS</code>
</Alert>
</>);
}
return React.createElement(this.props.component,{ ...this.props.props});
}
}
export default DynamicRenderer;