JSFiddle - React, Tailwind, and code Playground

by Roman Zhak

HTML

<div class="parent">
  <div class="rect"></div>
  <div class="rect"></div>
  <div class="rect"></div>
</div>

CSS

.rect {
    width: 100px;
    height: 100px;
    margin: 5px;
    background-color: green;
}

JavaScript

"use strict";

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"); } }

var querySelectorAll = document.querySelectorAll;

var __each = function __each(array, callback) {
  // maybe is like array
  if (array.length) {
    for (var i = 0, _length = array.length; i < _length; i++) {
      callback.call(this, array[i]);
    }
  }
  return array;
};

var Lite = (function () {
  function Lite(selector, parent) {
    _classCallCheck(this, Lite);
    console.log(parent)
    this.el = querySelectorAll.call(parent && parent.el[0] || document, selector);
  }

  _createClass(Lite, [{
    key: "style",
    value: function style() {
      var _this = this;

      var styles = arguments[0] === undefined ? {} : arguments[0];

      var _loop = function (key) {
        __each(_this.el, function (el) {
          el.style[key] = styles[key];
        });
      };

      for (var key in styles) {
        _loop(key);
      }
      return this;
    }
  }]);

  return Lite;
})();

new Lite('.rect', new Lite('.parent')).style({width: '200px'})