{"name":"react-docgen-external-proptypes-handler","version":"1.0.2","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":"55b6e06394991cef7e536215d7d56a93ecc43965","_id":"react-docgen-external-proptypes-handler@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"10.14.0","_npmUser":{"name":"danez","email":"daniel@tschinder.de"},"dist":{"integrity":"sha512-vr8sXRp5hBmaEP0kdBED9p7mdnVX6LTRODNcGhUXUh1hBbGW2rgjm24e0eA4zVJs4cqCcA2pS0dEHujJ9rg3rw==","shasum":"457d3e82a6899695482f4912036cc940577ab0aa","tarball":"http://registry-npm.ywwl.com/react-docgen-external-proptypes-handler/download/react-docgen-external-proptypes-handler-1.0.2.tgz","fileCount":4,"unpackedSize":18152,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcExjuCRA9TVsSAnZWagAAD4AP/jNwy5dCBGWhJqjSDxaf\ni0/zHfFQnhsCJlaunLDwO5Cgp4t230PgKibg3N6SH7P6ZxNu2sv1aWgAp0C3\nS53tSTBuTQ3Hyi18lMOUuHog8d5/nyeZLQGeZ/6I5WY/pAGdeAh61I3teBqU\nq8dwAGG49GC1gxeRNOgXzURaGVQFMQCBT5iYPtb1ehK8qo9K9//FEslAtudc\nR9OWpmSp7B5dZ37l164OiEl6XBSRvywbAe9MZrGrpQR5UXdR+qhXtDTbhdJd\nW4cqSRUxlrepOFWn+bLqCPKUMH0KUSzoBWycB5CiX3E3eaxhucYY9ODJOOAd\nryg7ppmnIIGnn5ndajEZOrgoXZW2tszkYXCogvvNDDoCDm/mp0s1Fe74dhlC\nc8beBEqsE+UXr4j79tzsdoQ888bnsyfS5shh0GeBE9RO8LtjYe8MQ39Zwafd\n/QSiPNgs++2XdZ3sp2AH7RRX/wOMrkjWAbbZXUT4HfpmeG4zEgzXuoHyqnrD\naqUqBbFJJDQ4tWJ9TwoGuu4BETXTW/QuJhi/47Qy5wtJhOVK/ikcoTjFAWau\nm0t+ezfIvQFDlvN1gPSWyZ4zxFH+uBJyesB0jyXx5Z/jYnVuKgA5aUuOf2Pd\nR0pGPR9GNcIuORz0Kcj7njCrfgz3HLqxv9SlVCH1lLR8bC9TCgyPeUH0m604\nrvI/\r\n=CKZv\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBsTBm+mf5mJRiUDooK4xEqT/tL2LVCLLUX1iJuwJvHgIge06mslBye7g0GX/Ln4FBvNIJJhmOY2LNCpO6S7y9TU0="}],"size":5462,"noattachment":false,"key":"/react-docgen-external-proptypes-handler/-/react-docgen-external-proptypes-handler-1.0.2.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.2_1544755437939_0.4041516828948635"},"_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":1544755438101,"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","_cnpm_publish_time":1544755438101,"dist-tags":{"latest":"2.0.0"}}