Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Documentation in JS / TS #621

Open
AndrewKarasek opened this issue Oct 4, 2017 · 14 comments
Open

Generate Documentation in JS / TS #621

AndrewKarasek opened this issue Oct 4, 2017 · 14 comments

Comments

@AndrewKarasek
Copy link

AndrewKarasek commented Oct 4, 2017

Is there anyway to declare documentation for components in JS (or TS) rather than markdown?

Having free-text (md) feels quite chaotic - writing the documentation in JS would enable us to do linting, import & share stub data, testing and have typesafety in TS.

@sapegin
Copy link
Member

sapegin commented Oct 4, 2017

You can do most of that in Markdown as well:

The only thing is missed is TypeScript support. But even this maybe not very hard to implement if anyone wants to have it.

Markdown has many other benefits in my opinion, but if you want to use JavaScript, you probably will like Storybook more than Styleguidist.

@sapegin sapegin closed this as completed Oct 4, 2017
@AndrewKarasek
Copy link
Author

@sapegin yeah TS support is probably the biggest loss. Being tied to extra dependencies and frameworks is not ideal and taking devs out of their familiar environment (ts / js) to work in free text doesn't sound like the best way to go for us.

Unfortunately storybook doesn't fit our use case for a number of other reasons.

If we forked the repo and developed the option to declare docs in code would that be considered for merging into the main repo? Cheers!

@sapegin
Copy link
Member

sapegin commented Oct 4, 2017

This may be a good addition of course if it has a good API and won’t complicate the code much ;-)

Do you already have any ideas on the API? Can we somehow reuse it for interoperability with Storybook? (That would be amazing feature!)

@AndrewKarasek
Copy link
Author

AndrewKarasek commented Oct 4, 2017

I'll need to dig into it a bit but my gut thought is to just use a naming scheme to find the documentation and then just some react components to wrap the necessary pieces of documentation. For example:

Filename: Button.doc.js

import * as React from 'react';
import { Section, Copy, RenderedComponent } from 'react-styleguidist';
import MyButton from './MyButton';

import * as React from 'react';
import { Section, Copy, RenderedComponent } from 'react-styleguidist';
import MyButton from './MyButton';

export default () => {
  return (
    <Section>
      <Copy>
        Here I write some assocatiated copy for my component
      </Copy>
      <RenderedComponent>
        {/* 
          everything inside rendered component will get rendered in
          an editable sandbox
        */}
        <MyButton />
      </RenderedComponent>
    </Section>
  );
};

@sapegin
Copy link
Member

sapegin commented Oct 4, 2017

I’d propose a different approach: decouple current Markdown parsing logic and create a common format fur examples that Styleguidist will use internally. So we could create different “loaders” for Markdown, Storybook and something that you want.

So I’d rewrite you example like this:

import * as React from 'react';
import MyButton from './MyButton';

export default () => {
  return [
       'Here I write some assocatiated copy for my component',
       <MyButton />,
      {
        type: 'example',
        options: { static: true },
        code: <MyButton />
      }
  ];
};

The first two are shortcuts to the full form in the last example.

@dziamid
Copy link

dziamid commented Oct 6, 2017

Markdown has many other benefits in my opinion

@sapegin what are the benefits?

@sapegin
Copy link
Member

sapegin commented Oct 6, 2017

  • You can structure documentation as you like;
  • you can mix examples with text to better explain them;
  • you can decide how to render each example: with or without an editor, as static code, etc.
  • readable on GitHub or in an editor.

@Jayphen
Copy link

Jayphen commented Jun 10, 2018

@AndrewKarasek

If we forked the repo and developed the option to declare docs in code would that be considered for merging into the main repo? Cheers!

Did you end up creating this fork? I have been trying a styleguide-first approach to development, but the missing type safety and other editor features makes it more difficult than it could be.

@Chr1stian
Copy link

Chr1stian commented Jul 3, 2019

Now that the js and jsx tags are supported in Markdown, is it possible to also get a tsx tag?

@elevatebart
Copy link
Collaborator

@Chr1stian in order to make tsx available, we need to find a way to transpile it to evaluable javascript. I believe the ts compiler would do the job, but it is incredibly heavy.

I like the idea and might investigate.

@sapegin
Copy link
Member

sapegin commented Dec 15, 2019

@elevatebart Making compilers customizable would be a great feature and like not hard to implement as soon as we find a good API. The difficulty here is that it's not just Buble (which we need to change to Babel anyway) but also things like transpiling imports and wrapping code in a Fragment. All this should be customizable but at the same time easy to reuse. So extracting them to separate packages might be a good idea ;-)

@sapegin
Copy link
Member

sapegin commented Dec 15, 2019

By the way for loading TypeScript a Babel plugin might be enough if it's smaller.

@elevatebart
Copy link
Collaborator

Here is a couple of links for inspiration of a codeSplit compiler that works:

In vue-styleguidist, we precompile examples in the examples loader then load the compiler asynchronously in the component when users make a change to the code.

This would solve in part the weight issue.
What do you think of this approach ?

@sapegin
Copy link
Member

sapegin commented Dec 16, 2019

This looks very interesting! And we won't need to transpile imports once we use Babel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants