A Pen by damian

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

Technologies

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

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

<body>

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

  

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




</body>

</html>

/*Downloaded from https://www.codeseek.co/0damian/a-pen-by-damian-wPgvwZ */
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; }

// - Container
//   - List
//     - Recipe
//   - Form
var list = function (_React$Component) {
  _inherits(list, _React$Component);

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

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

    _this.handleTransfer = _this.handleTransfer.bind(_this);
    _this.handleCancel = _this.handleCancel.bind(_this);
    _this.handleDelete = _this.handleDelete.bind(_this);
    _this.state = {};
    return _this;
  }

  return list;
}(React.Component);

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

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

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

    _this2.toggleIngr = _this2.toggleIngr.bind(_this2);
    _this2.toggleForm = _this2.toggleForm.bind(_this2);
    _this2.state = {
      formIsVisible: 0,
      ingrIsVisible: 0,
      active: 1
    };
    return _this2;
  }

  _createClass(item, [{
    key: "render",
    value: function render() {
      var ingrList = String(this.props.ingredients).replace(/\,/g, ', ');
      var ingrNodes = this.props.ingredients.map(function (ingr) {
        return React.createElement(
          "li",
          null,
          ingr
        );
      });
      return React.createElement(
        "div",
        { className: "recipe" },
        React.createElement(
          "h2",
          { onClick: this.toggleIngr },
          this.props.title
        ),
        React.createElement(
          "div",
          {
            className: "recipe-body",
            style: this.state.ingrVis ? { display: 'block' } : { display: 'none' }
          },
          React.createElement(
            "ul",
            null,
            ingrNodes
          ),
          React.createElement(
            "p",
            null,
            this.props.instructions
          ),
          React.createElement(
            "button",
            { onClick: this.toggleForm },
            "Edit"
          ),
          React.createElement(
            "button",
            {
              className: "delete",
              onClick: this.handleDelete
            },
            "Delete"
          )
        )
      );
    }
  }]);

  return item;
}(React.Component);

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

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

    var _this3 = _possibleConstructorReturn(this, (itemForm.__proto__ || Object.getPrototypeOf(itemForm)).call(this, props));

    _this3.handleTitleChange = _this3.handleTitleChange.bind(_this3);
    _this3.handleIngrChange = _this3.handleIngrChange.bind(_this3);
    _this3.handleInstChange = _this3.handleInstChange.bind(_this3);
    _this3.handleSubmit = _this3.handleSubmit.bind(_this3);
    _this3.handleCancel = _this3.handleCancel.bind(_this3);
    _this3.handleDelete = _this3.handleDelete.bind(_this3);
    _this3.state = {
      title: '',
      ingredients: '',
      instructions: ''
    };
    return _this3;
  }

  _createClass(itemForm, [{
    key: "render",
    value: function render() {
      return React.createElement(
        "div",
        { className: "form-container" },
        React.createElement(
          "form",
          null,
          React.createElement(
            "label",
            { "for": "title" },
            "Title",
            React.createElement("input", {
              type: "text",
              name: "title",
              ref: "titleInput",
              placeholder: this.props.title,
              onChange: this.handleTitleChange
            })
          ),
          React.createElement(
            "label",
            { "for": "ingredients" },
            "Ingredients",
            React.createElement("input", {
              type: "text",
              name: "ingredients",
              ref: "ingredientsInput",
              placeholder: this.props.ingredients,
              onChange: this.handleIngrChange
            })
          ),
          React.createElement(
            "label",
            { "for": "instructions" },
            "Instructions",
            React.createElement("textarea", {
              name: "instructions",
              rows: "3",
              ref: "instructionsInput",
              placeholder: this.props.instructions,
              onChange: this.handleInstChange
            })
          ),
          React.createElement(
            "button",
            {
              type: "submit",
              onClick: this.handleCancel
            },
            "Cancel"
          ),
          React.createElement(
            "button",
            {
              type: "submit",
              onClick: this.handleSubmit,
              disabled: !this.state.title.length || !this.state.ingredients.length || !this.state.instructions.length
            },
            "Save"
          )
        )
      );
    }
  }]);

  return itemForm;
}(React.Component);

Comments