A Pen by Jeff Christian

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

Technologies

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

<head>
  <meta charset="UTF-8">
  <title>A Pen by  Jeff Christian</title>
  
  
  
  
  
</head>

<body>

  <div id='container'></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/15chrjef/a-pen-by-jeff-christian-zNEgKb */
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

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 ModalTextArea = function (_React$Component) {
  _inherits(ModalTextArea, _React$Component);

  function ModalTextArea(props) {
    _classCallCheck(this, ModalTextArea);

    var _this = _possibleConstructorReturn(this, (ModalTextArea.__proto__ || Object.getPrototypeOf(ModalTextArea)).call(this, props));

    _this.state = {
      value: ''
    };
    return _this;
  }

  _createClass(ModalTextArea, [{
    key: 'handleChange',
    value: function handleChange(e) {
      this.setState({ value: e.target.value });
    }
  }, {
    key: 'render',
    value: function render() {
      return React.createElement('textarea', { value: this.state.value, onChange: this.handleChange.bind(this), style: { width: '99.3%', height: '98%' } });
    }
  }]);

  return ModalTextArea;
}(React.Component);

var ModalSelector = function ModalSelector(props) {
  console.log('hewraserawerawe', props);
  var background;
  if (props.selected === props.value) {
    background = { backgroundColor: 'blue', color: 'white' };
  } else {
    background = {};
  }
  return React.createElement(
    'div',
    {
      style: _extends({ cursor: 'pointer', border: '1px solid black' }, background),
      onClick: function onClick() {
        console.log('select row', props.selectRow, props.value);
        props.selectRow(props.value);
      }
    },
    'asdasdf'
  );
};

var Modal = function (_React$Component2) {
  _inherits(Modal, _React$Component2);

  function Modal(props) {
    _classCallCheck(this, Modal);

    var _this2 = _possibleConstructorReturn(this, (Modal.__proto__ || Object.getPrototypeOf(Modal)).call(this, props));

    _this2.state = {};
    console.log('modal props', _this2.props);
    return _this2;
  }

  _createClass(Modal, [{
    key: 'renderSelectors',
    value: function renderSelectors() {
      var _this3 = this;

      var myArray = [1, 2, 3, 4, 5];
      return myArray.map(function (row, i) {
        return React.createElement(ModalSelector, {
          selectRow: _this3.props.selectRow.bind(_this3, i),
          key: i,
          value: i,
          selected: _this3.props.selected
        });
      });
    }
  }, {
    key: 'render',
    value: function render() {
      return React.createElement(
        'div',
        { style: styles.modalStyle },
        React.createElement(
          'div',
          { style: { width: '20%', display: 'flex', flexDirection: 'column', height: '100%' } },
          this.renderSelectors()
        ),
        React.createElement(
          'div',
          { style: { width: '80%' } },
          React.createElement(ModalTextArea, null)
        )
      );
    }
  }]);

  return Modal;
}(React.Component);

var App = function (_React$Component3) {
  _inherits(App, _React$Component3);

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

    var _this4 = _possibleConstructorReturn(this, (App.__proto__ || Object.getPrototypeOf(App)).call(this));

    _this4.state = {
      showModal: false,
      selected: ''
    };
    return _this4;
  }

  _createClass(App, [{
    key: 'showModal',
    value: function showModal() {
      this.setState({
        showModal: !this.state.showModal
      });
    }
  }, {
    key: 'selectRow',
    value: function selectRow(value) {
      console.log('asdfasdfasd', value, this.props.selected);
      this.setState({
        selected: value
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var myModal = React.createElement(Modal, {
        selectRow: this.selectRow.bind(this),
        showModal: this.showModal.bind(this),
        selected: this.state.selected
      });
      var button = React.createElement('input', { onClick: this.showModal.bind(this), type: 'submit', value: 'Open' });
      var content = this.state.showModal === false ? button : myModal;

      return React.createElement(
        'div',
        { style: { display: 'flex', flex: 1, position: 'absolute', justifyContent: 'center', alignItems: 'center', height: '100%', width: '100%' } },
        content
      );
    }
  }]);

  return App;
}(React.Component);

var styles = {
  modalStyle: {
    display: 'flex',
    justifyContent: 'center',
    allignItems: 'center',
    border: '1px solid black',
    boxShadow: '1px 1px',
    height: '80%',
    width: '60%',
    flexDirection: 'row'
  }
};

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

Comments