A Pen by Dan

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

Technologies

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

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

  
</head>

<body>

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

  

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




</body>

</html>

/*Downloaded from https://www.codeseek.co/-dan/a-pen-by-dan-XgKbep */
ul {
  display: flex;
  margin: 0;
  padding: 0;
  width: 100%;
  list-style: none;
  justify-content: space-around;
}

.node {
  flex: 1 0 0;
}

.info {
  text-align: center;
  padding: 10px;
  border: 1px solid grey;
}


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

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

    return _possibleConstructorReturn(this, (Node.__proto__ || Object.getPrototypeOf(Node)).call(this, props));
  }

  _createClass(Node, [{
    key: "render",
    value: function render() {
      if (this.props.node) {
        return React.createElement(
          "li",
          { className: "node" },
          React.createElement(
            "div",
            { className: "info" },
            this.props.node.name
          ),
          React.createElement(
            "ul",
            { className: "level" },
            this.props.node.parents.map(function (n) {
              return React.createElement(Node, { node: n });
            })
          )
        );
      } else {
        return "";
      }
    }
  }]);

  return Node;
}(React.Component);

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

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

    return _possibleConstructorReturn(this, (Tree.__proto__ || Object.getPrototypeOf(Tree)).call(this, props));
  }

  _createClass(Tree, [{
    key: "render",
    value: function render() {
      return React.createElement(
        "ul",
        { className: "root" },
        this.props.tree && React.createElement(Node, { root: true, node: this.props.tree })
      );
    }
  }]);

  return Tree;
}(React.Component);

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

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

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

    _this3.state = {
      tree: {
        name: 'Dan Handrea',
        parents: [{
          name: 'Vasile Handrea',
          parents: [{ name: 'Eugen Handrea', parents: [{ name: 'Gheorghe Handrea', parents: [] }, { name: 'Elena Handrea', parents: [] }] }, { name: 'Ioana Handrea', parents: [{ name: 'Vasile Roșu', parents: [] }, { name: 'Ioana Roșu', parents: [] }] }]
        }, {
          name: 'Rozalia Handrea (Ioniță)',
          parents: [{ name: 'Ioniță Mihai', parents: [{ name: 'Ion Ioniță', parents: [] }, { name: 'Frăsina Ioniță', parents: [] }] }, { name: 'Ionită Elisaveta', parents: [{ name: 'Gheorghe Panfil', parents: [] }, { name: 'Ioana Panfil', parents: [] }] }]
        }]
      }
    };
    return _this3;
  }

  _createClass(Application, [{
    key: "render",
    value: function render() {
      return React.createElement(Tree, { tree: this.state.tree });
    }
  }]);

  return Application;
}(React.Component);

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

Comments