{"name":"react-docgen-external-proptypes-handler","version":"1.0.1","description":"evaluate variables from external files for react-docgen","main":"index.js","repository":{"type":"git","url":"git+https://github.com/siddharthkp/react-docgen-external-proptypes-handler.git"},"keywords":[],"author":{"name":"siddharthkp"},"license":"MIT","bugs":{"url":"https://github.com/siddharthkp/react-docgen-external-proptypes-handler/issues"},"homepage":"https://github.com/siddharthkp/react-docgen-external-proptypes-handler#readme","gitHead":"7800d5785b6bb0372a6b883895a8baa2627d5614","_id":"react-docgen-external-proptypes-handler@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.14.0","_npmUser":{"name":"danez","email":"daniel@tschinder.de"},"dist":{"integrity":"sha512-TebPaGDX0T57FlgZwDWN+qocD8qp9CEFTNZ1k//6wOdrzqdP8xn2MlZCen+5rIqQIYdx0p5u205vq1kdiHK7fA==","shasum":"1d7c1cc0200221fe50480fef80ad8c1bfa506e28","tarball":"http://registry-npm.ywwl.com/react-docgen-external-proptypes-handler/download/react-docgen-external-proptypes-handler-1.0.1.tgz","fileCount":4,"unpackedSize":18079,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcEbK0CRA9TVsSAnZWagAA8+IP/RUPqKVI7ZdhWMNKOm3u\nvISZPOc9IZ+XqsLVEFH9muoJi94TUE4W9p4J3sE63F8hzzBt93lxDiYyu/SO\nOpYLnOr6ajI/Y/zViFZxB+/fr5MEePaeQnX4dUKM6UBFP2OOfwLc/rljjy1z\nbv3dE+Q5EbHLi9Dx4F8dHGKgCtvFOA+PhiyuTq4YJvo3F9gsLwCDcHNsZZkS\nLz+o422Zp6/2A3KF7Oeldza39a1rpjENQkLyg5T/n4Bekgc8b0EFtgf1xTvj\nhCs9EJ6B2ZVBD/4y+RilPNzfID+Oi3szLG7DsXEHdmyD/4+uafy5pCr5Q4Gd\nw/ozvGRLA9+M0Yfo9pU1cBv5CoGGt7t2j+LMGTB0VzwCrWy0VM127PaSrqSW\nR91jNS8iQpNc+pEk+OnFTzl70yPcGBqg8d0VwVYGBUUV/SKcU0vqGh7VC4LU\niMd6NjCeI0Dvt7etYgbu7J1X4thkgjwew4IKWqKUgtRgIZMnff97HED26vfe\nsPP99fV8sjl2rAA48X3a0/aHcWBjmuPPMJO5fTHQLn9ByrJYr+SLDppLFbaT\n8I8TJx8qoPgwdy8QuQRaAVpJXAZOCY6EGEEZlOY8muAE1EHHtaWZ5EkEk4IL\noCbJA2ljean/zleKOxuqaiXL6IKYaTZ1Lq2DHOba1jygvMNUqo+++uQB4ZwG\n9Nj8\r\n=EK43\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHxJS+mTN0jDTrmg7UtJg7mvXoY87HheFgVgix8XAh9CAiEAlmn4f2AvmJWV0CYNpG0VgnFS7mInKT7HQAELOyK/1vc="}],"size":5430,"noattachment":false,"key":"/react-docgen-external-proptypes-handler/-/react-docgen-external-proptypes-handler-1.0.1.tgz"},"maintainers":[{"name":"siddharthkp","email":"siddharth.kshetrapal@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-docgen-external-proptypes-handler_1.0.1_1544663731682_0.280872354876903"},"_hasShrinkwrap":false,"readme":"# react-docgen-external-proptypes-handler\n > Evaluate variables from external files for react-docgen</b>\n \n**This handler does not work with react-docgen >= 5.0.0-beta.1 (yet). react-docgen as of this version will most probably include this functionality by default**\n\n#### credit\n\nAll credit goes to [Chandrasekhar Pasupuleti](https://github.com/pasupuletics) for sharing the implementation and [Daniel Tschinder](https://github.com/danez) for maintaining it.\n\n#### problem\n\n`react-docgen` doesn't allow you to use variables from other files to use in `propTypes`\n\nExample:\n\n```js\nimport iconNames from './icon-names.js'\n\nIcon.propTypes = {\n  /** Icon name */\n  name: PropTypes.oneOf(iconNames).isRequired\n}\n```\n\nThis doesn't work because it's parsed as a string and not an array\n\n```json\n\"props\": {\n  \"name\": {\n    \"type\": {\n      \"name\": \"enum\",\n      \"computed\": true,\n      \"value\": \"iconNames\"\n    },\n    \"required\": true,\n    \"description\": \"Icon name\"\n  },\n}\n```\n\n#### install\n\n```\nnpm i react-docgen-external-proptypes-handler --save-dev\n```\n\n#### convention\n\nIf you are importing a variable from an external file to use in `propTypes`, like in the example below, you need to follow a very specific convention to make it work.\n\nComponent code:\n\n```jsx\nimport React from 'react'\nimport PropTypes from 'prop-types'\n\n/* importing variable iconNames from .js file (js, jsx are supported, json is not) */\nimport iconNames from './icon-names.js'\n\nconst Icon = props => {\n  /*implementation logic*/\n}\n\nIcon.propTypes = {\n  /** Icon name */\n  name: PropTypes.oneOf(iconNames).isRequired\n}\n\nexport default Icon\n```\n\nIn the imported file, make sure the same variable is exported.\n\n```js\nconst iconNames = ['copy', 'trash', 'etc']\n/* same variable name */\nexport default iconNames\n```\n\n&nbsp;\n\n#### Usage\n\n```js\nconst docgen = require('react-docgen')\nconst externalProptypesHandler = require('./react-docgen-external-proptypes-handler')\n\nlet metadata = files.map(path => {\n  /* append display name handler to handlers list */\n  const handlers = docgen.defaultHandlers.concat(externalProptypesHandler(path))\n\n  /* read file to get source code */\n  const code = fs.readFileSync(path, 'utf8')\n\n  /* parse the component code to get metadata */\n  const data = docgen.parse(code, null, handlers)\n\n  return data\n})\n```\n\n##### Usage with react-styleguidist\n\nEnable `handlers` property in styleguidist config(`styleguidist.config.js`)\n```js\nmodule.export = {\n  handlers: componentPath =>\n    require('react-docgen').defaultHandlers.concat(\n        require('react-docgen-external-proptypes-handler')(componentPath),\n        require('react-docgen-displayname-handler').createDisplayNameHandler(componentPath)\n      )\n}\n```\n\n&nbsp;\n\n#### like it?\n\n:star: this repo\n\n#### license\n\nMIT © [siddharthkp](https://github.com/siddharthkp)\n","publish_time":1544663731850,"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","_cnpm_publish_time":1544663731850,"dist-tags":{"latest":"2.0.0"}}