testing-library-docs icon indicating copy to clipboard operation
testing-library-docs copied to clipboard

Create a `Tab` on docusaurus for Typescript implementations

Open pedroapfilho opened this issue 5 years ago • 9 comments

I came across the Setup on the React docs, and I found this.

Using it with typescript is a little bit tricky for new comers, and I think that it may happen with a lot of people, so what if we use the new Markdown Feature for Docusaurus that allows us to create Tabs on the docs that are for JS, and use:

<Tabs
  groupId="test-utils"
  defaultValue="js"
  values={[
    {label: 'Javascript', value: 'js'},
    {label: 'Typescript', value: 'tsx'},
  ]}>
  <TabItem value="win">Code for JS here</TabItem>
  <TabItem value="mac">Code for TS here</TabItem>
</Tabs>

So we could have more people using it right with `Typescript.

Is it a good idea? I can implement it here at first, and then we take it as a default and implement it everywhere else, whenever we touch it.

Material-UI did it on their docs, and I find it so much better to use it like this. Idk if they use Docusaurus, but it's easily implementable..`

pedroapfilho avatar Nov 29 '20 18:11 pedroapfilho

Hi @pedroapfilho, thanks for opening this! It sounds good to me, we've already added Tabs and TabItem in some docs and there's also a code snippet for vscode to generate those. Since we don't have typescript blocks in the docs yet, maybe it would be better to have another opinion.. @nickmccurdy, @kentcdodds wdyt about this one?

MatanBobi avatar Nov 30 '20 08:11 MatanBobi

Seems to make sense to me if anyone's willing to do the work there.

kentcdodds avatar Nov 30 '20 17:11 kentcdodds

Alright, I'll start then!

pedroapfilho avatar Nov 30 '20 21:11 pedroapfilho

Would it be possible to have the TypeScript code typechecked and compiled to the JavaScript code automatically to keep the types and both code examples in sync?

nickserv avatar Nov 30 '20 21:11 nickserv

I'd be worried about the compiled version looking like.... compiled code 😅 But it's possible that the right babel plugins + prettier could be used to only remove types 🤔

kentcdodds avatar Nov 30 '20 22:11 kentcdodds

As far as I understand that's pretty much what @babel/preset-typescript does.

nickserv avatar Nov 30 '20 22:11 nickserv

@nickmccurdy Do you have any examples of it somewhere I can see?

pedroapfilho avatar Nov 30 '20 22:11 pedroapfilho

Examples of what?

nickserv avatar Nov 30 '20 22:11 nickserv

Of any docusaurus docs that has this setup

pedroapfilho avatar Nov 30 '20 22:11 pedroapfilho