It would be really helpful if we could compose multiple Cx components into one functional component that accepts multiple parameters as JSX attributes and can have its own nested (child) components.
<LoadingOverlay loading={bind('$page.loading')} >
<Grid />
</LoadingOverlay/>
When creating a custom Cx component, normally we need to create a class that extends some of the base components and implements certain predefined methods, which adds complexity to the process.
Here is one possible implementation of LoadingOverlay
:
class LoadingOverlay extends PureContainer {
declareData() {
super.declareData(...arguments, {
loading: undefined
});
}
render (context, instance, key) {
let {data} = instance;
return <div key={key} className="cxb-loading-overlay-container">
{this.renderChildren(context, instance)}
{data.loading && <div className="cxe-loading-overlay">
<div className="cxe-loading-indicator">
{Icon.render('loading', {
style: {
width: '24px',
height: '24px',
position: 'relative',
top: '6px'
}
})
}
Loading...
</div>
</div>}
</div>;
}
}
For the example above, LoadingOverlay
had to inherit from PureContainer
and implement declareData
and render
methods.
And I would like to be able to use something simmilar to React's stateless functional components, like this:
const LoadingOverlay = (props) => {
return <div className="cxb-loading-overlay-container">
{props.children}
{data.loading && <div className="cxe-loading-overlay">
<div className="cxe-loading-indicator">
{Icon.render('loading', {
style: {
width: '24px',
height: '24px',
position: 'relative',
top: '6px'
}
})
}
Loading...
</div>
</div>}
</div>;
}
Is this possible in CxJS?