Adding override option to widget config
This commit is contained in:
parent
70628da819
commit
1876f89c89
|
@ -59,22 +59,32 @@ const isReactComponent = component => {
|
|||
*/
|
||||
export const getWidget = arg => {
|
||||
|
||||
const instantiate = (widget, config) => {
|
||||
const instantiate = (widget, config, type) => {
|
||||
// Check if user forced explicit type
|
||||
if (typeof widget === 'string' || widget instanceof String) {
|
||||
// Built-in
|
||||
return React.createElement(BUILTIN_WIDGETS[widget], config);
|
||||
} else if (isReactComponent(widget)) {
|
||||
return React.createElement(widget, config);
|
||||
} else if (typeof widget === 'function' || widget instanceof Function) {
|
||||
return <WrappedWidget widget={widget} config={config} />
|
||||
} else {
|
||||
throw `${widget} is not a valid plugin`
|
||||
} else {
|
||||
// Plugin
|
||||
if (type?.toLowerCase() === 'react') {
|
||||
return React.createElement(widget, config);
|
||||
} else {
|
||||
// Auto-detect
|
||||
if (isReactComponent(widget)) {
|
||||
return React.createElement(widget, config);
|
||||
} else if (typeof widget === 'function' || widget instanceof Function) {
|
||||
return <WrappedWidget widget={widget} config={config} />
|
||||
} else {
|
||||
throw `${widget} is not a valid plugin`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// First, check 'top-level' vs. 'nested object' case
|
||||
if (arg.widget) {
|
||||
const { widget, ...config } = arg;
|
||||
return instantiate(widget, config);
|
||||
const { widget, type, ...config } = arg;
|
||||
return instantiate(widget, config, type);
|
||||
} else {
|
||||
// No object with args -> instantiate arg directly
|
||||
return instantiate(arg);
|
||||
|
|
Loading…
Reference in New Issue