babel-plugin-react-code-block

0.3.1 • Public • Published

babel-plugin-react-code-block NPM Coverage

Display React functional examples with source code.

Table of Contents

Installation

npm

npm install babel-plugin-react-code-block

yarn

yarn add babel-plugin-react-code-block

Documentation

Create a code block component with a code property, which will be populated by this plugin:

import React from 'react'
 
export default ({children, code}) => {
  return (
    <div>
      {children}
      <code>{code}</code>
    </div>
  )
}

Note: In the above example component children is the passed in JSX that you want to render as a demo and code is the passed in JSX converted to a string so you can also print the code sample (which is run through prettier to make it look aesthetically pleasing).

In your Babel configuration include:

module.exports = {
  "plugins": [
    [
      "babel-plugin-react-code-block",
      {
        "component": "CodeBlock",
      },
    ],
  ],
}

Note: In the above configuration change CodeBlock to the name of your code block component. This plugin will simply apply the transform to any JSX elements matching the component name.

Code of Conduct

Please see the code of conduct.

Contributing

Please see the contributing guide.

License

MIT

Package Sidebar

Install

npm i babel-plugin-react-code-block

Weekly Downloads

0

Version

0.3.1

License

MIT

Unpacked Size

7.08 kB

Total Files

6

Last publish

Collaborators

  • dogmaiobot
  • sandersky