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

Make PropsTable capable of accepting manual prop entries #360

Closed
kentcdodds opened this issue Sep 24, 2018 · 9 comments
Closed

Make PropsTable capable of accepting manual prop entries #360

kentcdodds opened this issue Sep 24, 2018 · 9 comments
Labels
difficult: low docz-default-theme Issues related to package docz-default-theme enhancement

Comments

@kentcdodds
Copy link
Contributor

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?

kentcdodds pushed a commit to kentcdodds/docz that referenced this issue Sep 24, 2018
This is more just a proof of concept. I didn't actually pull this down and it's clearly not been formatted with prettier.
@IssueHuntBot
Copy link

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

@IssueHuntBot
Copy link

@Ashikpaul has started working. Visit this issue on Issuehunt

@IssueHuntBot
Copy link

@Ashikpaul has stopped working. Visit this issue on Issuehunt

@pedronauck pedronauck added difficult: low docz-default-theme Issues related to package docz-default-theme enhancement labels Sep 27, 2018
@IssueHuntBot
Copy link

@wsmd has started working. Visit this issue on Issuehunt

@wsmd
Copy link

wsmd commented Oct 9, 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! 😅

@dfee
Copy link

dfee commented 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.

@cironunes
Copy link

@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.

@IssueHuntBot
Copy link

@rororofff has funded $2.00 to this issue.


@transitive-bullshit
Copy link
Contributor

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

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficult: low docz-default-theme Issues related to package docz-default-theme enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants