All files / react-dom/dist create-css-component.js

74.44% Statements 67/90
51.06% Branches 24/47
66.67% Functions 12/18
79.69% Lines 51/64
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137    1x   2x   1x   1x   1x   1x   1x   1x   1x   1x   1x   3x   1x   1x   1x                   1x     1x 1x 1x 1x 1x 1x 1x   1x 1x     1x   1x   1x   1x 1x 1x     1x                                   1x   1x   1x 1x 1x 1x   1x 1x 1x 1x   1x 1x                 1x 1x       1x             1x       1x       1x       1x        
'use strict';
 
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; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
var _react = require('react');
 
var _template = require('../../core/template');
 
var _matchAttribute = require('../../core/match-attribute');
 
var _matchAttribute2 = _interopRequireDefault(_matchAttribute);
 
var _bindAttrsToCssom = require('../../dom/dist/bind-attrs-to-cssom');
 
var _bindAttrsToCssom2 = _interopRequireDefault(_bindAttrsToCssom);
 
var _generateClassName = require('../../dom/dist/generate-class-name');
 
var _generateClassName2 = _interopRequireDefault(_generateClassName);
 
var _utils = require('./utils.js');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
function _possibleConstructorReturn(self, call) { Iif (!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) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
 
/**
 * @param {string} displayName
 * @param {string} selector
 * @param {string} className
 * @param {Object} props
 * @param {Object} attrs
 * @param {Object} invalidProps
 */
module.exports = function createCSSComponent(_ref) {
  var _class, _temp, _initialiseProps;
 
  var displayName = _ref.displayName,
      className = _ref.className,
      attributes = _ref.attributes,
      attrs = _ref.attrs,
      _ref$base = _ref.base,
      base = _ref$base === undefined ? 'div' : _ref$base,
      invalidProps = _ref.invalidProps;
 
  return _temp = _class = function (_Component) {
    _inherits(CSSComponent, _Component);
 
    function CSSComponent(props) {
      _classCallCheck(this, CSSComponent);
 
      var _this = _possibleConstructorReturn(this, (CSSComponent.__proto__ || Object.getPrototypeOf(CSSComponent)).call(this, props));
 
      _initialiseProps.call(_this);
 
      _this.attrs = (0, _bindAttrsToCssom2.default)(attrs);
      _this.applyAttrs(props);
      return _this;
    }
 
    _createClass(CSSComponent, [{
      key: 'componentWillUpdate',
      value: function componentWillUpdate(nextProps) {
        this.applyAttrs(nextProps);
      }
    }, {
      key: 'render',
      value: function render() {
        var props = this.props;
 
        return (0, _react.createElement)(this.base, _extends({
          ref: props.innerRef
        }, (0, _utils.omitBy)(props, this.shouldOmitProp), {
          className: this.generateClassName(this.props)
        }));
      }
    }]);
 
    return CSSComponent;
  }(_react.Component), _class.displayName = 'Styled(' + displayName + ')', _initialiseProps = function _initialiseProps() {
    var _this2 = this;
 
    this.className = className;
    this.attributes = attributes;
    this.base = base;
    this.invalidProps = invalidProps;
 
    this.applyAttrs = function (props) {
      var _iteratorNormalCompletion = true;
      var _didIteratorError = false;
      var _iteratorError = undefined;
 
      try {
        for (var _iterator = _this2.attrs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
          var attr = _step.value;
 
          attr.cssRule.style[attr.prop] = (0, _template.format)(attr.template, props);
        }
      } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
      } finally {
        try {
          Iif (!_iteratorNormalCompletion && _iterator.return) {
            _iterator.return();
          }
        } finally {
          Iif (_didIteratorError) {
            throw _iteratorError;
          }
        }
      }
    };
 
    this.shouldOmitProp = function (value, key) {
      return _this2.invalidProps[key] || key === 'innerRef';
    };
 
    this.matchAttributeToProp = function (attribute) {
      return (0, _matchAttribute2.default)(attribute, _this2.props[attribute.name]);
    };
 
    this.generateClassName = (0, _generateClassName2.default)({ className: className, attributes: attributes, attrs: this.attrs });
  }, _temp;
};
 
var getClassName = function getClassName(_ref2) {
  var className = _ref2.className;
  return className;
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jcmVhdGUtY3NzLWNvbXBvbmVudC5qcyJdLCJuYW1lcyI6WyJtb2R1bGUiLCJleHBvcnRzIiwiY3JlYXRlQ1NTQ29tcG9uZW50IiwiZGlzcGxheU5hbWUiLCJjbGFzc05hbWUiLCJhdHRyaWJ1dGVzIiwiYXR0cnMiLCJiYXNlIiwiaW52YWxpZFByb3BzIiwicHJvcHMiLCJhcHBseUF0dHJzIiwibmV4dFByb3BzIiwicmVmIiwiaW5uZXJSZWYiLCJzaG91bGRPbWl0UHJvcCIsImdlbmVyYXRlQ2xhc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