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

propTypes not showing unless defaultProps for Prop #326

Closed
bluetidepro opened this issue Feb 14, 2017 · 3 comments
Closed

propTypes not showing unless defaultProps for Prop #326

bluetidepro opened this issue Feb 14, 2017 · 3 comments

Comments

@bluetidepro
Copy link
Collaborator

bluetidepro commented Feb 14, 2017

My issue/problem:

It seems like propTypes Don't show up unless there is a defaultProps for that prop. Is this intended? Is there a fix for this?

Details:

  • Using "webpack": "1.12.14"
  • Here is my styleguide.config.js:
const path = require('path');
const webpack = require('webpack');
const _ = require('lodash');

const BASE_PATH = path.join(__dirname, './src');

module.exports = {
  title: 'Styleguide Title',
  components: './src/components/**/*.js',
  updateWebpackConfig(webpackConfig, env) {
    webpackConfig.eslint = {
      configFile: './.eslintrc',
    };
    webpackConfig.devtool = '#cheap-module-source-map';
    webpackConfig.module.preLoaders = [
      {
        test: /\.js$/,
        exclude: [
          /node_modules/,
        ],
        loader: 'eslint-loader'
      }
    ];
    webpackConfig.module.loaders.push(
      {
        test: /\.js?$/,
        include: BASE_PATH,
        loader: 'babel'
      }
    );
    webpackConfig.plugins.push(
      new webpack.DefinePlugin({
        ICONS_FILE: JSON.stringify('icons.svg'),
        WEBPACK__NODE_PRODUCTION: process.env.NODE_ENV === 'production',
      })
    );
    webpackConfig.resolve.alias = _.extend(webpackConfig.resolve.alias, {
      'bambu-colors': path.join(BASE_PATH, '/styles/Colors')
    });
    return webpackConfig;
  },
};
  • Here is a snippet of my component:
/**
 * The Badge
 */
class Badge extends React.PureComponent {
  static propTypes () {
    return {
      /**
       * The background of the Badge
       */
      background: PropTypes.string,
      /**
       * The text color for the Badge
       */
      color: PropTypes.string,
      /**
       * The text displayed inside the Badge
       */
      text: PropTypes.string,
    };
  }

  static get defaultProps () {
    return {
      background: null,
      color: Colors.WHITE,
    };
  }

  render () {
      ...
  }
}

export default Badge;
  • And it outputs like this (screenshot):

screen shot 2017-02-14 at 1 54 51 pm

@bluetidepro
Copy link
Collaborator Author

Oh, and I just noticed it seems like descriptions are not being pulled in, either.

@sapegin
Copy link
Member

sapegin commented Feb 14, 2017

Looks like react-docgen doesn’t understand your propTypes so it catches your props only from defaultProps and shows only default values because of that.

Actually I don’t see any reason to use a function here (didn’t know that this is possible for classes — do they even work?). Could you try to use an object like in this example.

@bluetidepro
Copy link
Collaborator Author

Ahhh, that did it. Thanks @sapegin!

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

No branches or pull requests

2 participants