Super React Gist - Example

In this example below you will see how to do a Super React Gist - Example with some HTML / CSS and Javascript

Example based on super-react-gist. A simple and flexible component that allows you to embed GitHub Gists in React projects.

Thumbnail
This awesome code was written by George G. Gkasdrogkas, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright George G. Gkasdrogkas ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Super React Gist - Example</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
  
  
</head>

<body>

   <div id="root">
  <!-- This div's content will be managed by React. -->
</div>
  <script src='https://unpkg.com/react/umd/react.development.js'></script>
<script src='https://unpkg.com/react-dom/umd/react-dom.development.js'></script>
<script src='https://unpkg.com/super-react-gist/umd/super-react-gist.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/georgegkas/super-react-gist-example-zpzMzz */
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Demo = function (_React$Component) {
  _inherits(Demo, _React$Component);

  function Demo() {
    _classCallCheck(this, Demo);

    return _possibleConstructorReturn(this, (Demo.__proto__ || Object.getPrototypeOf(Demo)).apply(this, arguments));
  }

  _createClass(Demo, [{
    key: 'render',
    value: function render() {
      return React.createElement(
        'div',
        null,
        React.createElement(
          'h1',
          null,
          'super-react-gist'
        ),
        React.createElement(
          'p',
          null,
          'Simple and flexible component that allows you to embed ',
          React.createElement(
            'a',
            { href: 'https://gist.github.com/' },
            'GitHub Gists'
          ),
          ' in ',
          React.createElement(
            'a',
            { href: 'https://reactjs.org/' },
            'React'
          ),
          ' projects.'
        ),
        React.createElement(
          'p',
          null,
          'This demo illustrate a basic usage of ',
          React.createElement(
            'strong',
            null,
            'super-react-app'
          ),
          ' component.'
        ),
        React.createElement(
          'h2',
          null,
          'Render one file'
        ),
        React.createElement(
          'p',
          null,
          'With ',
          React.createElement(
            'strong',
            null,
            'super-react-app'
          ),
          ' you are able to render a single file from a gist repository.'
        ),
        React.createElement(Gist, { url: 'https://gist.github.com/GeorgeGkas/5f55a83909a3f5b766934ffe802d30df#file-start-js' }),
        React.createElement(
          'h2',
          null,
          'Render multiple files'
        ),
        React.createElement(
          'p',
          null,
          'You are not restricted to use only one ',
          React.createElement(
            'strong',
            null,
            'super-react-app'
          ),
          ' component in your project. '
        ),
        React.createElement(Gist, { url: 'https://gist.github.com/GeorgeGkas/5f55a83909a3f5b766934ffe802d30df#file-start-js' }),
        React.createElement(Gist, { url: 'https://gist.github.com/GeorgeGkas/5f55a83909a3f5b766934ffe802d30df#file-multiple-js' }),
        React.createElement(
          'h2',
          null,
          'Render using ',
          React.createElement(
            'code',
            null,
            'file'
          ),
          ' prop'
        ),
        React.createElement(
          'p',
          null,
          'Works both on ',
          React.createElement(
            'strong',
            null,
            'public'
          ),
          ' and ',
          React.createElement(
            'strong',
            null,
            'secret'
          ),
          ' gists.'
        ),
        React.createElement(
          'p',
          null,
          'Oh snap! *face-palm*! In case you didn\'t notice we can only use the above method to render files that do not contain any uppercase letter. For instance, if our Gist repo contains a file ',
          React.createElement(
            'code',
            null,
            'CaMelCase.js'
          ),
          ', then providing just the permalink will not work!'
        ),
        React.createElement(
          'p',
          null,
          React.createElement(
            'strong',
            null,
            'Q'
          ),
          ': How can we render this ',
          React.createElement(
            'code',
            null,
            'CaMelCase.js'
          ),
          ' file?'
        ),
        React.createElement(
          'p',
          null,
          React.createElement(
            'strong',
            null,
            'A'
          ),
          ': By providing a ',
          React.createElement(
            'code',
            null,
            'file'
          ),
          ' prop to our ',
          React.createElement(
            'code',
            null,
            'Gist'
          ),
          ' component to indicate which file we want to include.'
        ),
        React.createElement(
          'p',
          null,
          'This is how we do it:'
        ),
        React.createElement(Gist, { url: 'https://gist.github.com/GeorgeGkas/5f55a83909a3f5b766934ffe802d30df', file: 'CaMelCase.js' }),
        React.createElement(
          'h2',
          null,
          'Render the whole Gist'
        ),
        React.createElement(
          'p',
          null,
          'Of course, we can also embed the whole Gist repository just by copying the Gist URL.'
        ),
        React.createElement(Gist, { url: 'https://gist.github.com/GeorgeGkas/5f55a83909a3f5b766934ffe802d30df' }),
        React.createElement(
          'h2',
          null,
          'Combine all the above techniques'
        ),
        React.createElement(
          'p',
          null,
          React.createElement(
            'em',
            null,
            'This example is left as an exercise to the reader.'
          )
        )
      );
    }
  }]);

  return Demo;
}(React.Component);

ReactDOM.render(React.createElement(Demo, null), document.getElementById('root'));

Comments