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

Docs -> Form -> Props -> Size property - Showing lodash 'without' function #1563

Closed
FranciscoGileno opened this issue Apr 9, 2017 · 3 comments
Labels

Comments

@FranciscoGileno
Copy link

Steps

Go to Form documentation page. Look at Props table, size property.

Expected Result

Show the all possible sizes.

Actual Result

A lodash function: _.without(...)

image

Version

0.67.2

I would love to work on this. It seems to affect another pages as well. Can I have a try? Someone can point me to the right direction?

Thanks.

@FranciscoGileno FranciscoGileno changed the title Docs -> Form -> Props -> Size property - Showing loadash without function Docs -> Form -> Props -> Size property - Showing lodash 'without' function Apr 9, 2017
@levithomason
Copy link
Member

Would love a PR :)

When running the docs, docs/app/docgenInfo.json is generated which describes all components and props. Our docs parse this JSON object.

Specifically, ComponentProps.js handles rendering the props table. You'd be looking for the renderEnums method in that component. It has logic for parsing enums, but not all enums.

For info setting up and running this project, see the CONTRIBUTING.md.

@FranciscoGileno
Copy link
Author

Hi @levithomason, thanks for replying...

I spent some time having a look at it and I find this:

On docs/app/docgenInfo.json we pass three types of value to enums:

  1. An array of objects:
"value": [
  {
    "value": "'horizontally'",
    "computed": false
  },
  {
    "value": "'vertically'",
    "computed": false
  }
]
  1. A constant that represents an array:
"value": "SUI.FLOATS"
  1. A lodash function:
"value": "_.without(SUI.SIZES, 'medium')"

Items 1 and 2 are covered on ComponentProps.js in the expandEnums method:

expandEnums = (value) => {
  const parts = value.split('.')
  if (parts[0] === 'SUI') {
    return SUI[parts[1]]
  }
  return value
}

But clearly it is not prepared to parse the lodash function.

Is that right? I might have missed something.

Solutions

Since Eval is dangeours and slow I think we have to come up with another alternative.

I did not find anything good enough yet.

One solution would be to change how we represent constant arrays(without some item) in the docs/app/docgenInfo.json.

"_.without(SUI.SIZES, 'big', 'massive')" would become something like: SUI.SIZES:without['big', 'massive'], so we could implement the logic for parsing this, but honestly I think this is very limited and buggy.

Any thoughts?

@levithomason
Copy link
Member

The simplest way would be to inline the literal values in every array, though, that is a lot of repetition.

We use our own custom gulp plugin for parsing the react-docgen output. It would be somewhat safer to eval the json at that time as it is only done server side. That way, the output json would be an already parsed array.

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

No branches or pull requests

3 participants