pedronauck/docz

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Make PropsTable capable of accepting manual prop entries #360

kentcdodds posted onGitHub

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?


@boostio funded this issue with $10. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

@ashikpaul has started working. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

@ashikpaul has stopped working. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

@wsmd has started working. Visit this issue on Issuehunt

posted by IssueHuntBot over 6 years ago

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:

<img width="849" alt="screen shot 2018-10-09 at 1 49 15 am" src="https://user-images.githubusercontent.com/2100222/46649243-5c461680-cb66-11e8-8a2d-6904dbafed9b.png">


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 :

<img width="695" alt="screen shot 2018-10-09 at 2 00 32 am" src="https://user-images.githubusercontent.com/2100222/46649647-d4610c00-cb67-11e8-8052-d791c9089905.png">

Another example:

<img width="688" alt="screen shot 2018-10-09 at 2 06 37 am" src="https://user-images.githubusercontent.com/2100222/46649691-fc506f80-cb67-11e8-89fa-70b06f120697.png">

There's still a lot of work to be done here, but I thought I'd share my proof of concept as well! πŸ˜…

posted by wsmd over 6 years ago

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.

posted by dfee about 6 years ago

@dfee I'm happy to put together a PR with your solution or help you to get one up so we can get this merged in. I'm assuming this is something @pedronauck is keen to have built in the default theme.

posted by cironunes about 6 years ago

@rororofff has funded $2.00 to this issue.


posted by IssueHuntBot almost 6 years ago

I just published react-docgen-props-table which ports a previous version of the Docz PropsTable component to work standalone.

<p align="center"> <img alt="Example" src="https://raw.githubusercontent.com/transitive-bullshit/react-docgen-props-table/master/example.png"> </p>

posted by transitive-bullshit almost 6 years ago

Fund this Issue

$12.00
Funded
Only logged in users can fund an issue

Pull requests

Recent activities

rororofff funded 2.00 for pedronauck/docz# 360
almost 6 years ago
boostio funded 10.00 for pedronauck/docz# 360
over 6 years ago