You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Docs] Allow passing a prop type or interface directly to the props option in the docs #1688
I have a shared TS interface definition that I used throughout a component and it's sub-components. I'd like to display this interface and any prop comments in the props table.
With all the conversions of typescript allowing us to create re-usable prop types, this is becoming more necessary. I'd like to bump the urgency of it. Otherwise I've been needing to write out the prop definitions directly in the Doc text.
where display is a prop that uses a type much like you're describing
(type EuiColorPickerDisplay = 'default' | 'inline')
I'm trying to understand where this additional type/interface display comes in. If the type is in use, it'll display the usage ('type' column) in the relevant prop context. If the type is not used by any props in the table, why does it need to be there?
I could see a case for adding a column to the existing table to show the name of the type/interface that the prop uses. Otherwise, the inserted type probably deserves it own table as the columns wouldn't really match the existing, but it still seems to lack context.
"interesting workaround" may be too much credit. Would still prefer finding a more 'official' way, but it's probably something that transpiles to that structure.
Having the "base" component type extend additional types and interfaces doesn't quite get what we need. We need the additional type to be more standalone and include all of its props regardless if other types have props of the same name.
@chandlerprall had a workaround mentioned earlier in this thread, and noted:
Would still prefer finding a more 'official' way, but it's probably something that transpiles to that structure.
@ashikmeerankutty We have people on vacation, etc., so it might be a couple days before your main PR gets merged. In meantime, let's focus on this work if you haven't started yet.
@thompsongl Typescript strips all the types and interfaces. So the only way I think of is to transform those types or interface to some objects. And append it to AST. I don't know if that is possible. Is there any possibility for that ?
I can get the interfaces and types from typescript. So create a component with that interface automatically whenever an interface is found Sound ok. I will check that out.
I found a solution for this issue. Its another babel plugin that finds all the interfaces and types in a file and converts it to an object with ___docgen property and append it to the AST.
So we can access props info by just passing the interface to guideSectionPage
It will create results like this for interfaces.
In case of types I have no idea how the result must looks like.
This is a follow up for #3554. So should I commit changes to that branch itself ?
Activity
cchaos commentedon May 7, 2019
With all the conversions of typescript allowing us to create re-usable prop types, this is becoming more necessary. I'd like to bump the urgency of it. Otherwise I've been needing to write out the prop definitions directly in the Doc text.
thompsongl commentedon Oct 3, 2019
Finally looking into this.
Given a props table like
where
displayis a prop that uses a type much like you're describing(
type EuiColorPickerDisplay = 'default' | 'inline')I'm trying to understand where this additional type/interface display comes in. If the type is in use, it'll display the usage ('type' column) in the relevant prop context. If the type is not used by any props in the table, why does it need to be there?
I could see a case for adding a column to the existing table to show the name of the type/interface that the prop uses. Otherwise, the inserted type probably deserves it own table as the columns wouldn't really match the existing, but it still seems to lack context.
thompsongl commentedon Oct 18, 2019
@chandlerprall came up with an interesting workaround for this:
https://github.com/elastic/eui/pull/2449/files#diff-6d519fe9c30948f504b374b032e26e21R13-R15
chandlerprall commentedon Oct 18, 2019
"interesting workaround" may be too much credit. Would still prefer finding a more 'official' way, but it's probably something that transpiles to that structure.
cchaos commentedon Oct 28, 2019
Yeah, the workaround is working for me but would like a more automatic way so we don't have to create the special props files.
thompsongl commentedon Jul 6, 2020
@ashikmeerankutty Re: #3056 (comment)
Having the "base" component type extend additional types and interfaces doesn't quite get what we need. We need the additional type to be more standalone and include all of its props regardless if other types have props of the same name.
@chandlerprall had a workaround mentioned earlier in this thread, and noted:
This may be worth more exploration.
thompsongl commentedon Jul 17, 2020
@ashikmeerankutty We have people on vacation, etc., so it might be a couple days before your main PR gets merged. In meantime, let's focus on this work if you haven't started yet.
ashikmeerankutty commentedon Jul 17, 2020
@thompsongl Typescript strips all the types and interfaces. So the only way I think of is to transform those types or interface to some objects. And append it to AST. I don't know if that is possible. Is there any possibility for that ?
thompsongl commentedon Jul 17, 2020
Yeah, I think a transformation of some kind is in line with our thinking. That is how the current workaround is done: https://github.com/chandlerprall/eui/blob/6183abfbc1e3268a63375ae91aa0c7b739043d50/src-docs/src/views/datagrid/props.tsx
Basically the type/interface gets converted to a component so the parser picks it up. We'd just need it to be more automated.
ashikmeerankutty commentedon Jul 17, 2020
I can get the interfaces and types from typescript. So create a component with that interface automatically whenever an interface is found Sound ok. I will check that out.
ashikmeerankutty commentedon Jul 19, 2020
I found a solution for this issue. Its another babel plugin that finds all the interfaces and types in a file and converts it to an object with
___docgenproperty and append it to the AST.So we can access props info by just passing the interface to guideSectionPage
It will create results like this for interfaces.
In case of
typesI have no idea how the result must looks like.This is a follow up for #3554. So should I commit changes to that branch itself ?
ashikmeerankutty commentedon Jul 20, 2020
For the above example of type. I was able to generate doc info as following:
And this can be used as stated in the issue. I can change the result into any structure.
thompsongl commentedon Jul 20, 2020
Great! Thanks for exploring this. What plugin is used to get this result?
Let's make this its own PR. If necessary, have the PR point to the 3554 branch as the merge target for now.
ashikmeerankutty commentedon Jul 20, 2020
Its a custom plugin. I will make a separate PR
thompsongl commentedon Jul 20, 2020
Nice! Thanks