A Pen by doubleswirve

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

Technologies

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

<head>
  <meta charset="UTF-8">
  <title>A Pen by  doubleswirve</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="app"></div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js'></script>

  

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




</body>

</html>

/*Downloaded from https://www.codeseek.co/doubleswirve/a-pen-by-doubleswirve-LRLYRb */
.col {
  float: left;
  width: 200px;
}
.sm {
  background: #f8f8f8;
  border: 2px solid #ccc;
  padding: 30px;
}
.bg {
  background: #f00;
  float: left;
  padding: 50px;
  width: 300px;
}
.bg-row {
  background: #ffa500;
  padding: 40px;
}
.row {
  overflow: auto;
}
.row .sm {
  float: left;
}


/*Downloaded from https://www.codeseek.co/doubleswirve/a-pen-by-doubleswirve-LRLYRb */
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 App = function (_React$Component) {
  _inherits(App, _React$Component);

  function App() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, App);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = App.__proto__ || Object.getPrototypeOf(App)).call.apply(_ref, [this].concat(args))), _this), _this.resizeCallback = function () {
      var isSmall = _this.state ? _this.state.isSmall : null;
      console.log('is small:', isSmall);
      if (window.matchMedia('(min-width: 600px)').matches) {
        if (isSmall || null === isSmall) {
          _this.setState({
            isSmall: false
          });
        }
      } else if (!isSmall || null === isSmall) {
        _this.setState({
          isSmall: true
        });
      }
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(App, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      window.addEventListener('resize', this.resizeCallback);
      this.resizeCallback();
    }
  }, {
    key: 'render',
    value: function render() {
      if (!this.state) {
        console.log('Not ready...');
        return React.createElement(
          'p',
          null,
          'Loading...'
        );
      }
      console.log('in App');
      if (!this.state.isSmall) {
        console.log('600 or greater...');
        return React.createElement(
          'div',
          null,
          React.createElement(
            'div',
            { className: 'col' },
            React.createElement(
              'div',
              { className: 'sm' },
              'small item'
            ),
            React.createElement(
              'div',
              { className: 'sm' },
              'small item'
            )
          ),
          React.createElement(
            'div',
            { className: 'bg' },
            'big item'
          )
        );
      } else {
        console.log('less than 600...');
        return React.createElement(
          'div',
          null,
          React.createElement(
            'div',
            { className: 'bg-row' },
            'big item'
          ),
          React.createElement(
            'div',
            { className: 'row' },
            React.createElement(
              'div',
              { className: 'sm' },
              'small item'
            ),
            React.createElement(
              'div',
              { className: 'sm' },
              'small item'
            )
          )
        );
      }
    }
  }]);

  return App;
}(React.Component);

ReactDOM.render(React.createElement(App, null), document.getElementById('app'));

Comments