-
Couldn't load subscription status.
- Fork 71
Description
The issue
Currently creating @angular-react components is done manually, specially in @angular-react/fabric (but the same holds true for any library implementation).
This is fine for a few components, and didn't prove to be worth the effort of creating such a tool, but as the library grows, and more components are added - this seems like it would simplify the long-term maintenance, especially in regards to upgrading the underlying React UI framework (e.g. office-ui-fabric-react, Semantic-UI-React).
Proposed solution
There are a number of ways to go about this, but the most likely is to use Angular Schematics to generate components, which as part of the inputs will take some sort of identifier for a *Props interface (e.g. ICheckboxProps), and together with the TypeScript compiler API (or any of its wrappers) and add the relevant Inputs and Outputs for the component, as well as bindings for the template etc.:
- Props that are of type
string | number | boolean | objectshould be added as-is. e.g:componentRef?: IRefObject<ICheckbox>->@Input() componentRef?: ICheckboxProps['componentRef'] - Props that conform to
(...args: any[]) => voidshould be added as@Outputs, with the arguments added as an object with properties the same name as the function parameters. e.g.:onChange?: (ev?: React.FormEvent<HTMLElement | HTMLInputElement>, checked?: boolean) => void->@Output() readonly onChange = new EventEmitter<{ ev?: Event, checked?: boolean }>(). - Props that confirm to
(...args: any[]) => *non-void*should be added as-is (see 1. above), also as@Inputs. - Props that are of type
IRenderFunction<T>should be added asInputRendererOptions<T>. If the prop name is prefixed with anon, omit it (the Angular doesn't letInputs be prefixed withon), and camel-cased. e.g.:
onRenderNavigation?: IRenderFunction<IPanelProps>->@Input() renderNavigation?: InputRendererOptions<IPanelProps>. - (optional) copy the JDoc as-is.
Open issues:
- The proposed solution is very specific to
office-ui-fabric-react, as this is the only actively-maintained package wrapper - I think this is enough to support automating it, for the moment at least. - There are probably more things that could be automated as far as generation goes, but the above list is a (very) good start.
- For anything that's not defined above, examples and patterns from the existing code-base of
@angular-react/fabriccan be used as reference.