1

I would like to make a demo page for my React component.

And I want to make it like http://www.material-ui.com/#/components/flat-button, which has:

  1. some description of props. I would like to use markdown
  2. demo of component
  3. the code that shown demo section

Currently, I have a file like this (Typescript)

import * as React from "react";

export default class SimpleExamples extends React.Component<{}, {}> {

    constructor(props: {}) {
        super(props);
    }

    handleChange(event: React.ChangeEvent<HTMLElement>): void {
        // Do something here
    }

    render() {
        return (
            <div>
                <p><code>MyComponent </code> is bla bla bla with <code>value</code> prop and <code>onChange</code> prop.</p>
                <p> You can make it like this or like that ... etc </p>
                <MyComponent value={this.state.value} onChange={event => this.handleChange(event) } />
                <br />

                <div style={{ marginTop: 12, marginBottom: 12 }}>
                    <CodeExample />
                </div>;
            </div>
        );
    }
}

It looks messy, and CodeExample shows the whole file which is I don't want.

I want it to show just the demo like this:

<MyComponent value={this.state.value} onChange={event => this.handleChange(event) } />

I thought about split the demo to a seperate file. But then, there will be a lot of them.

Any idea to achieve that? Thanks in advance!

Tan Dat
  • 2,888
  • 1
  • 17
  • 39

1 Answers1

0

There are many alternatives. You can roll your own demo if you build the component with nwb namely this feature here.

You can build your component and demo in the same project and deploy them seperately and host it on the projects github pages

But NWB does not provide Markdown support out of the box for the demo. If you want to do something a little bit more elaborate you can use docusaurus (recently released by facebook) or even storybook (no markdown though)

Docusaurus

  • Powered by Markdown

Save time and focus on your project's documentation. Simply write docs and blog posts with Markdown and Docusaurus will publish a set of static html files ready to serve.

  • Built Using React

Extend or customize your project's layout by reusing React. Docusaurus can be extended while reusing the same header and footer.

  • Ready for Translations
  • Document versioning
  • Document search

Personally I've used NWB and Docusaurus and I think I'll stick with Docusaurus for now. But I think it really depends on what you want to do with the demo. If you have a ton of functional features to show than I'd recommend storybook, if it's mainly API based NWB/Docusaurus

João Cunha
  • 9,929
  • 4
  • 40
  • 61