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

Nested union type in react-native docs #13

Closed
brentvatne opened this issue May 6, 2015 · 4 comments
Closed

Nested union type in react-native docs #13

brentvatne opened this issue May 6, 2015 · 4 comments

Comments

@brentvatne
Copy link
Member

In ViewStyleProps I would like to change transform to the following:

  transform: ReactPropTypes.arrayOf(
    ReactPropTypes.oneOfType([
      ReactPropTypes.shape({rotation: ReactPropTypes.number}),
      ReactPropTypes.shape({scaleX: ReactPropTypes.number}),
      ReactPropTypes.shape({scaleY: ReactPropTypes.number}),
      ReactPropTypes.shape({translateX: ReactPropTypes.number}),
      ReactPropTypes.shape({translateY: ReactPropTypes.number})
    ])
  ),

The current output from docgen is this:

screen shot 2015-05-06 at 10 24 12 am

I would prefer for it to be this:

screen shot 2015-05-06 at 10 25 50 am

@fkling - am I doing something incorrectly here? If a patch is necessary, could you point me in the right direction?

Thanks!

Related: facebook/react-native#1157

@fkling
Copy link
Member

fkling commented May 6, 2015

I assume that whatever renders the docs is not set up to render unions. The output from react-docgen should be something like

    "transform": {
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "union",
          "value": [
            {
              "name": "shape",
              "value": {
                "rotation": {
                  "name": "number"
                }
              }
            },
            {
              "name": "shape",
              "value": {
                "scaleX": {
                  "name": "number"
                }
              }
            },
            {
              "name": "shape",
              "value": {
                "scaleY": {
                  "name": "number"
                }
              }
            },
            {
              "name": "shape",
              "value": {
                "translateX": {
                  "name": "number"
                }
              }
            },
            {
              "name": "shape",
              "value": {
                "translateY": {
                  "name": "number"
                }
              }
            }
          ]
        }
      },
      "required": false,
      "description": ""
    }
  }

So all you have to do is iterate over value and build the output you want.

@brentvatne
Copy link
Member Author

Thanks! Fixed here: facebook/react-native#1181

@fkling
Copy link
Member

fkling commented May 6, 2015

Awesome!

@mikeaustin
Copy link

I'm using styleguidist which uses react-docgen, but it still outputs "union" for Flow types such as ("foo" | "bar"). Is there a plugin or patch or something to make it list the union types?

I realize this in an old thread, but if there is an answer, I assume it would be useful to others.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants