Open
Description
Prerequisites
- I have read the documentation
What theme are you using?
other
Is your feature request related to a problem? Please describe.
When building the Carbon theme (#3883), I met the following problem:
Suppose I want to implement the following oneOf UI:
- A key
oneOf
that told the user this is a oneOf - A gray background that indicates which part(in this case, the
loram
field) the oneOf is controlling.
Without modifying the default OneOfField
. I got:
The problem is: How can I change the UI without rewriting the entire OneOfField?
Describe the solution you'd like
Provide a OneOfTemplate/AnyOfTemplate, and replace the render part of the OneOfField
to:
const OneOfTemplateProps = {
widget: <Widget /* some props for widget*/ />,
content: option !== null && <_SchemaField {...this.props} schema={optionSchema!} />,
// ...other props for OneOfTemplate
}
return <OneOfTemplate {... OneOfTemplateProps}/>
Then I can create the target UI by implementing a template without touching the complicated logic:
function OneOfTemplate({widget, content}){
return (
<FormGroup {...someProps}>
<LayerBackground {...someProps}>
{widget}
{content}
</LayerBackground>
</FormGroup>
);
}
Describe alternatives you've considered
Rewrite the whole OneOfField can do this, but not good enough.