Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _exotic = require("exotic");

var _classnames = _interopRequireDefault(require("classnames"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _default = css => {
  const constructWithOptions = (componentConstructor, tag, options = _exotic.EMPTY_OBJ) => {
    // ====== this is a dumb thing to do on production ======
    if (typeof tag !== 'string' && typeof tag !== 'function') {
      throw new Error(process.env.NODE_ENV !== 'production' ? `Cannot create styled-component for component: ${String(tag)}` : '');
    }
    /* This is callable directly as a template function */
    // $FlowFixMe: Not typed to avoid destructuring arguments


    const templateFunction = (...args) => componentConstructor(tag, options, css(...args));
    /* If config methods are called, wrap up a new template function and merge options */


    templateFunction.withConfig = config => constructWithOptions(componentConstructor, tag, _objectSpread({}, options, config));

    templateFunction.qa = qa => {
      // @todo - can disable here !!!!!!!
      // if (process.env.NODE_ENV !== 'production') {
      // templateFunction.attrs({ 'data-qa': qa })
      // }
      return templateFunction.attrs({
        'data-qa': qa
      });
    };

    templateFunction.children = children => {
      return templateFunction.attrs({
        'children': children
      });
    };

    templateFunction.className = className => templateFunction.attrs({
      className
    });

    templateFunction.attrs = (attrs = _exotic.EMPTY_OBJ) => {
      if ((0, _exotic.isString)(attrs.className)) {
        attrs.className = (0, _classnames.default)(attrs.className);
      }

      return constructWithOptions(componentConstructor, tag, _objectSpread({}, options, {
        attrs: _objectSpread({}, options.attrs || _exotic.EMPTY_OBJ, attrs)
      }));
    };

    return templateFunction;
  };

  return constructWithOptions;
};

exports.default = _default;