Allow filtering by parent interface or type declaration #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability to filter props based on where they were declared.
Solves: #56 (comment), #49 (comment)
Problem
Currently we have no way of filtering props based on where they were declared. The common problem is props that extend
HTMLAttributes<T>
interface, e.g.:Filtering them using
skipPropsWithoutDoc
is not enough as some aria attributes have documentation and forces the users to write documentation for props. UsingskipPropsWithName
can cause problems if names of props are the same (e.g. customonClick
,onFocus
handlers).Proposed solution
TypeScript allows us to get the place where the prop was declared (I believe the only valid places are InterfaceDeclaration and TypeDeclaration). We could pass the name of the type the prop was declared in and filename where the declaration of the type is placed to
propFilter
so that users have more control of which props end up in documentation. Proposed change is to addparent
object toPropItem
interface of filter function ((props: PropItem, component: Component) => boolean
)I've added test to cover use case of filtering
HTMLAttributes
and verified using StyleGuidist that they are not documented using custom interface extending fromHTMLAttributes
and using a component created viastyled-components
(which automatically addHTMLAttributes
to html components)Before:
![before](https://user-images.githubusercontent.com/7580355/43990970-8cc2aba6-9d63-11e8-8f90-8c1368b792d0.png)
After:
![after](https://user-images.githubusercontent.com/7580355/43990972-92170822-9d63-11e8-879b-b0a68cb1c592.png)
using following
styleguide.config.js
: