{"name":"react-docgen-external-proptypes-handler","version":"1.0.3","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":"39156864ab1242e2cdcb1e0340d6b3bb575b756e","_id":"react-docgen-external-proptypes-handler@1.0.3","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-jWFA7NCdSnNs9Yr7xAhcUJEwH7qhIKxsyXF5yzzriFiBBfGIlkdzslGWRW4GFD5B8Fu24MTDM1G5q8M3L8+Qdw==","shasum":"53ce11d4ec86c67596558da0464f0ec15b6e0d64","tarball":"http://registry-npm.ywwl.com/react-docgen-external-proptypes-handler/download/react-docgen-external-proptypes-handler-1.0.3.tgz","fileCount":4,"unpackedSize":18473,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc+PaACRA9TVsSAnZWagAAH1UP/0o8OYhcPnH2ufBTPqlL\nfvZT5sjjSvjapyy98igfhL9RZZE5aiFSKsJ8VxOUmfGBnn5otyzjZ8L3zDbZ\nD7upH2dJQchoonB4TKuxoUJAEZ+WKvuIitB4NNDff+rgB+zn8jfP70s95p7h\nYq8cp3FF5BVsEvBno9fD3v9ZSBHh2c+AAQytwOrBN1tY/an6IH1iFO11jnUA\nB1LD1T2KR3Uag5F5nne3yh1gqtcikR/qtSUIjjwYd4Qt7HhApsncbk7kroYr\ndBcCU5CBJq9qCUfSQoyhR2s5uGyuySmGvy4VF5Uc4kcZBp6zkDY39lkCY67M\n0FRCFlDmCHjywYRfKSVsq9TPAUsVJ48Wcwol6TV/FH2perNtXDF8j6InYMzR\n4g6X+ZDZSNC23TvO+/avsJZcB5Mfi6oM9ruTwCTC9IZt6ngGANdO+JF27abW\nIZi5KEV4jjoTt7fy27jbVz9N/hcop/tzOYBgXFjy3SrH22MBmx15GhknTG5/\nDub8GVmltiD6pI0+NKihJ/R2EwVKm9QjQEEZ7N0bvlk+iFNci062LAOk5fQd\nmJKFRb4+StnDKwn/z5PLDcoDaIaFPFD4T+kRs49YQjBOOJRPjpa+lYEs64xX\nX5De4TyXREuM6/UF/EpksfgfmrVM86BiuMXptuFAqbKpDU3Cp6DtUMe0bsdd\nUbMf\r\n=09Kq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCH2YUqcTAuPkxmgI66dockiE1mgE2RsvB+74jc9Z9q8gIhAJwW97gMMWhQCPtdgS+gbS4PZJgRy/QK/88zupD/jH1A"}],"size":5609,"noattachment":false,"key":"/react-docgen-external-proptypes-handler/-/react-docgen-external-proptypes-handler-1.0.3.tgz"},"maintainers":[{"name":"siddharthkp","email":"siddharth.kshetrapal@gmail.com"}],"_npmUser":{"name":"siddharthkp","email":"siddharth.kshetrapal@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-docgen-external-proptypes-handler_1.0.3_1559819903529_0.4795168809197323"},"_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":1559819903741,"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","_cnpm_publish_time":1559819903741,"dist-tags":{"latest":"2.0.0"}}