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 = exports.Link = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactRouterDom = require("react-router-dom");

var _exotic = require("exotic");

var _types = require("../view-container/types");

var _jsxFileName = "/Users/michaelfrohberg/Training/mono/packages/modules/link-container/index.js";

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

function _extends() {
  _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;
  };

  return _extends.apply(this, arguments);
}

function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};

  var target = _objectWithoutPropertiesLoose(source, excluded);

  var key, i;

  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);

    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }

  return target;
}

function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;

  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }

  return target;
}

const IS_TEST = process.env.NODE_ENV === 'test';

const isValueExternal = to => to.includes('http') || to.includes('mailto') || to.includes('tel');
/**
 * @see https://github.com/ReactTraining/react-router/issues/2051
 */


class Link extends _react.default.PureComponent {
  /**
   * href, url, to, address
   */
  render() {
    let _this$props = this.props,
        to = _this$props.to,
        href = _this$props.href,
        url = _this$props.url,
        link = _this$props.link,
        onClick = _this$props.onClick,
        text = _this$props.text,
        children = _this$props.children,
        className = _this$props.className,
        isExternal = _this$props.isExternal,
        missingLinkTag = _this$props.missingLinkTag,
        target = _this$props.target,
        nofollow = _this$props.nofollow,
        shouldNotFollow = _this$props.shouldNotFollow,
        remainingProps = _objectWithoutProperties(_this$props, ["to", "href", "url", "link", "onClick", "text", "children", "className", "isExternal", "missingLinkTag", "target", "nofollow", "shouldNotFollow"]);

    to = to || href || url || link || onClick; // <a text="eh">
    // <a children="eh">
    // <a>{'eh'}</a>
    // when passing text in via children

    if ((0, _exotic.isNil)(text)) {
      // || to
      text = children || null;
    }

    if (to && missingLinkTag === true) {
      const Tag = missingLinkTag;
      return _react.default.createElement(Tag, {
        __source: {
          fileName: _jsxFileName,
          lineNumber: 131
        },
        __self: this
      }, to);
    }

    if (process.env.NODE_ENV !== 'production') {
      if (!to) {
        throw new Error('/MISSING-LINK' + JSON.stringify(this.props));
      }
    } // if (isNil(to)) {
    //   to = href || url
    // }
    // check if external


    if (isValueExternal(to)) {
      isExternal = true;
    }

    const attributes = Object.assign({}, remainingProps, {
      target,
      className,
      children: text
    });

    if (nofollow === true || shouldNotFollow === true) {
      attributes.rel = 'no-follow';
    }

    if ((0, _exotic.isTrue)(isExternal) || IS_TEST) {
      attributes.href = to;
      return _react.default.createElement("a", _extends({}, attributes, {
        __source: {
          fileName: _jsxFileName,
          lineNumber: 161
        },
        __self: this
      }));
    } else {
      attributes.to = {
        pathname: to
      };
    }

    const view = _react.default.createElement(_reactRouterDom.NavLink, _extends({}, attributes, {
      __source: {
        fileName: _jsxFileName,
        lineNumber: 169
      },
      __self: this
    }));

    return view; // <Link to={to}>{text}</Link>, <a href="">{text}</a>
    // if (isRelative(url))
    // if (isAbsolute(url))
    // if (routes.includes(url))
  }

}

exports.Link = Link;
Link.propTypes = {
  /**
   * @type {String || Object || Array || URL}
   */
  to: _types.any,

  /**
   * @type {String || Object}
   */
  className: _types.any,

  /**
   * @type {String || Object}
   */
  activeClassName: _types.any,
  // === label

  /**
   * @alias text
   */
  children: _types.any,

  /**
   * @alias label
   * @alias title
   */
  text: _types.string,

  /**
   * @optional
   */
  isExternal: _types.boolean,

  /**
   * @description can set the prefix for the url
   */
  urlBase: _types.string,

  /**
   * @description open in a new tab/window/same window
   */
  target: _types.string,

  /**
   * === synonymous, use oneOf, not multiple
   */
  href: _types.string,
  link: _types.string,
  url: _types.string,
  onClick: _types.func,

  /**
   * @type {Function | Object | String}
   */
  styles: _types.string,

  /**
   * @version 0 - was boolean
   * @version 1 - is string or node
   */
  missingLinkTag: (0, _types.oneOfType)([_types.string, _types.node]),

  /**
   * @example <Link nofollow />
   */
  nofollow: _types.boolean,

  /**
   * @alias shouldNotBeFollowedByRobots
   * @example <Link shouldNotFollow />
   */
  shouldNotFollow: _types.boolean // eslint-disable-next-line

};
var _default = Link;
exports.default = _default;