carteb / carte-blanche

An isolated development space with integrated fuzz testing for your components. See them individually, explore them in different states and quickly and confidently develop them.
https://www.youtube.com/watch?v=6g3-TQ6aaw8
MIT License
1.5k stars 47 forks source link

Support referenced and imported propTypes #338

Open tmc opened 8 years ago

tmc commented 8 years ago

givent

import React from 'react';

const user = React.PropTypes.shape({
  email_address: React.PropTypes.string,
  name: React.PropTypes.string,
})

export default class Foobar extends React.Component {
  static propTypes = {
    a1: user,
    a2: React.PropTypes.shape({
      email_address: React.PropTypes.string,
      name: React.PropTypes.string,
    })
  };
  render() { return (<p>.</p>); }
};

the a1 field is renders to 'No Control available' while a2 appropriately renders the expected form.

mxstbr commented 8 years ago

Interesting, that's highly likely a limitation of react-docgen which we can't really work around. Maybe switching to recon will fix this?

/cc @chrisui, ref #293

tmc commented 8 years ago

Being in an environment in which I'm generating propTypes from an IDL this is a pretty important limitation.

mxstbr commented 8 years ago

Okay, let's wait for @chrisui to be back from holiday (soon?) and then we'll look into this! :+1:

nikgraf commented 8 years ago

Would be an interesting contribution to https://github.com/reactjs/react-docgen

@fkling I'm curious about your thoughts on how easy/hard this would be. I would be happy to dig in and submit a PR.

fkling commented 8 years ago

Potentially the same issue as https://github.com/reactjs/react-docgen/issues/65 . Variables should be resolved. I guess one would just have to add a resolveToValue call here: https://github.com/reactjs/react-docgen/blob/master/src/handlers/propTypeHandler.js#L47

nikgraf commented 8 years ago

@fkling cool, thx for the hint. I will look into it later this week and create a PR 😊

tmc commented 8 years ago

@fkling / @nikgraf that does appear to fix this, FWIW