Skip to content

Conversation

bebraw
Copy link
Collaborator

@bebraw bebraw commented Sep 17, 2018

This PR adds componentNameResolver and getDefaultExportForFile helpers for writing custom component name resolvers (important for styled components and such).

If the parser detects a styled component, it will use filename instead
of StyledComponentClass. This gives basic support for Styled Components
in the parser.
@bebraw bebraw force-pushed the fix-styled-components branch from 8adf68e to 80ff4de Compare September 19, 2018 07:59
@bebraw
Copy link
Collaborator Author

bebraw commented Sep 19, 2018

I updated the PR so it's mergeable. Let me know if you want something more generic. We could expose the matching mechanism if you don't like the coupling.

@pvasek
Copy link
Collaborator

pvasek commented Sep 19, 2018

You read my mind. This seems too hard coded. I guess it would make sense to have it in ParserOptions but I have no idea how to name it.

@bebraw
Copy link
Collaborator Author

bebraw commented Sep 19, 2018

@pvasek How about resolveComponentName(exp, source) in parserOptions? Then we pass it as an optional resolveComponentName callback to computeComponentName. If it's defined, then we run it before other logic and return possible result, otherwise it falls back to default logic. That would be enough for my purposes.

@pvasek
Copy link
Collaborator

pvasek commented Sep 19, 2018

@bebraw That could work but I guess if that callback return null it should be ignored and name should be calculated as it is now. Is it correct? So you can "overwrite" only name you want and keep rest of the logic otherwise.

@bebraw
Copy link
Collaborator Author

bebraw commented Sep 19, 2018 via email

@pvasek
Copy link
Collaborator

pvasek commented Sep 19, 2018 via email

@bebraw
Copy link
Collaborator Author

bebraw commented Sep 20, 2018

@pvasek I generalized the interface. Now the styled components bit lives outside of the parser core and can be added through a small function. I also added a helper to make it convenient to implement matchers like that.

@bebraw bebraw changed the title Add filename based support for styled components General API for overriding component names Sep 20, 2018
@pvasek pvasek merged commit 816d358 into styleguidist:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants