-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate components #91
Comments
Exactly, along with the template itself. But that’s the ideal solution, anything that helps making authoring wrapper components would be a good start for this. Once that’s in we can iterate over it to improve it further.
There is not technical limitation here, since the TypeScript compiler API is capable of parsing interfaces & outputting classes (and when using libraries like [`ts-morph`](https://www.npmjs.com/package/ts-morph) makes working with it even easier). I'm not sure about the template, that probably requires using the [Angular Language Service API](https://github.com/angular/angular/blob/master/packages/language-service/src/types.ts), or alternatively manually outputting the string.
…On 18 Feb 2019, 22:36 +0200, Eswar Prakash ***@***.***>, wrote:
Happy to take a look at it. I am guessing you are keen to see if we can parse the prop interface definition to build the inputs and outputs for the component?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Sorry, no idea what happened to my comment. Guess I accidentally deleted it. I am interested in trying this out but need to have a go at the Typescript compiler bit first |
@bengry - So, after a bit of play around with ts-morph (which by the way is brilliant!) I think we need to put together some blue prints as to the input for the schematic that will help us identify which component file and prop type to process. At a high level, we have the following options:
Looking at the options: (1) is easier for the end user, since all they need to know is which component we need to generate. Harder for us, since we will need to walk the inheritance tree to find the prop type (2) is easier for us (maybe) and harder for the end user, since they will need to tell us the prop type to use by browsing the component docs in the MS site. I like (1) for obvious reasons. Do you have any other thoughts? |
I agree that (1) is probably better, especially long-term. It introduces a minor technical challenge of getting the type of props, but if needed - we could extract more from it, without breaking the API. |
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 relevantInput
s andOutput
s for the component, as well as bindings for the template etc.:string | number | boolean | object
should be added as-is. e.g:componentRef?: IRefObject<ICheckbox>
->@Input() componentRef?: ICheckboxProps['componentRef']
(...args: any[]) => void
should be added as@Output
s, 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 }>()
.(...args: any[]) => *non-void*
should be added as-is (see 1. above), also as@Input
s.IRenderFunction<T>
should be added asInputRendererOptions<T>
. If the prop name is prefixed with anon
, omit it (the Angular doesn't letInput
s be prefixed withon
), and camel-cased. e.g.:onRenderNavigation?: IRenderFunction<IPanelProps>
->@Input() renderNavigation?: InputRendererOptions<IPanelProps>
.Open issues:
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.@angular-react/fabric
can be used as reference.The text was updated successfully, but these errors were encountered: