question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make PropsTable capable of accepting manual prop entries

See original GitHub issue

React Docgen is… imperfect.

But the PropsTable looks great. I’d love to manually maintain a props listing for the docs using PropsTable like this:

<PropsTable
  props={[
    {property: 'variant', type: 'enum', required: false, default: 'primary', description: 'Can also specify "secondary"'},
    // ... etc.
  ]}
/>

Thoughts?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:21
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
dfeecommented, Jan 11, 2019

Here is the solution (called SimplePropsTable): https://gist.github.com/dfee/856f78ad4182d079dafbba6c63992005

Practically speaking, it implements an interface that PropsTable could (should) take advantage of – so one day this could be built-in.

1reaction
wsmdcommented, Oct 10, 2018

I love the idea, @kentcdodds!

I’m currently working on a project that doesn’t use prop-types and is not statically typed either 😬. Having the ability to manually add prop definitions is definitely a great addition to Docz!

I started working on this idea, and made some very good progress!

Here are the results of what I have so far…

Given this markup:

<PropsTable
  props={[
    {
      property: "variant",
      type: {
        name: "enum",
        value: [
          { value: "primary" },
          { value: "secondary" },
          { value: "outline" }
        ]
      },
      required: false,
      defaultValue: {
        value: "primary"
      },
      description: 'Can also specify "secondary"'
    },
    {
      property: "disabled",
      type: {
        name: "boolean"
      },
      required: false,
      defaultValue: {
        value: "false"
      }
    }
  ]}
/>

The following is rendered:

screen shot 2018-10-09 at 1 49 15 am

It’s worth mentioning that Docz has some expectations around the component’s docgen info, so I started experimenting with some schema validation mechanism that I think would go hand in hand with this feature. This will:

  • prevent the rendering logic from throwing cryptic errors in case the schema passed via props doesn’t match what Docz expects (a valid react-docgen data structure, that is).
  • help developers debugging the invalid parts of the schema.

For example, when defining a prop of type enum, its value should be an array of objects that have a key value, like in the example above. The following will not be considered valid:

<PropsTable
  props={[{
    property: "variant",
    type: {
      name: "enum",
      value: ['primary', 'secondary']
    },
    // ...

In case it was entered, an error like this will be thrown :

screen shot 2018-10-09 at 2 00 32 am

Another example:

screen shot 2018-10-09 at 2 06 37 am

There’s still a lot of work to be done here, but I thought I’d share my proof of concept as well! 😅

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make PropsTable capable of accepting manual prop entries · Issue ...
I'm currently working on a project that doesn't use prop-types and is not statically typed either . Having the ability to manually add...
Read more >
pedronauck/docz (Raised $598.00) - Issuehunt
Funded#480created bycryzzchen. $37.00. Make PropsTable capable of accepting manual prop entries. Funded#360created bykentcdodds. $12.00. Recent activities.
Read more >
How passing props to component works in React
Master how to pass props (properties) to components in React with this useful beginner's guide, including demo code.
Read more >
10 Testing and Profiling Java Application Projects
To create a JUnit JDBC test fixture class: In the Applications window, select the project. Choose File > New > From Gallery.
Read more >
Glossary of Technical Theatre Terms - Stage Management
The ASM is reponsible for setting props used during the show, as well as carrying out a pre-show check list to ensure all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found