uber / react-view

React View is an interactive playground, documentation and code generator for your components.
https://react-view.pages.dev
MIT License
697 stars 41 forks source link

Things to improve #2

Open tajo opened 4 years ago

tajo commented 4 years ago
awdyson commented 4 years ago

Any chance we could get a roadmap at some point?

Appreciate the work by the way 😃

tajo commented 4 years ago

Maybe. Most of these are long-terms goals since they are not acute pain points for us. extract-react-types-loader might be more near-term. Hopefully, there will be some outside contributions too.

raunofreiberg commented 4 years ago

How would one go about using extract-react-types-loader to show TypeScript types? Would appreciate some pointers 🙂

tajo commented 4 years ago

How would one go about using extract-react-types-loader to show TypeScript types? Would appreciate some pointers 🙂

First you extract the types from the component file.

Then we pass it to the Editor component.

PropsTooltip has some vendored code that creates the definition out of that extract-react-types-loader datastructure.

You can see it at baseweb.design when you hover over components:

Screen Shot 2020-01-08 at 10 31 44 AM

We use flow but should be almost same for typescript. Ideally, we don't want to vendor that code and enable this in a simpler way.

raunofreiberg commented 4 years ago

Thanks for the help!

If I may pick your brain — what do you think about using the extracted TypeScript (or Flow) types as props to react-view? It's probably harder to do with complex union types, but for primitives (string, boolean) it would likely avoid duplication.

tajo commented 4 years ago

If I may pick your brain — what do you think about using the extracted TypeScript (or Flow) types as props to react-view? It's probably harder to do with complex union types, but for primitives (string, boolean) it would likely avoid duplication.

It would be more trouble than help. The type extraction via extract-react-types-loader is far from being reliable and fails to extract props even in this case

const Component: React.FC<PropsT & { additionalProp: string }>

Even if it worked more reliably you still have to deal with more complex types like enums that often come with imports. And even "simple" boolean and string props sometimes need additional meta settings like defaultValue or stateful.

So in the best case scenario it would be some hybrid model. You would still have to maintain some configuration for each component.

Anyway, once you have these config files, you can actually use them for other things as well. For example, we generate these tables out of them (while using flow types as an additional information since they don't always work). And there are some other neat tools I want to build that will leverage the react-view props format.