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    
@skava/ui / src / playground / Link / Link.js
Size: Mime:
"use strict";

var __rest = this && this.__rest || function (s, e) {
  var t = {};

  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  return t;
};

var __importDefault = this && this.__importDefault || function (mod) {
  return mod && mod.__esModule ? mod : {
    "default": mod
  };
};

Object.defineProperty(exports, "__esModule", {
  value: true
});
/* eslint brace-style: "OFF" */

const react_1 = __importDefault(require("react"));

const exotic_1 = require("exotic");
/**
 * @todo typings interface
 */
// import {
//   boolean,
//   string,
//   array,
//   obj,
//   func,
//   node,
//   any,
//   oneOfType,
// } from 'uxui-modules/view-container/types'
// /**
//  * href, url, to, address
//  */
// static propTypes = {
//   /**
//    * @type {String || Object || Array || URL}
//    */
//   to: any,
//   /**
//    * @type {String || Object}
//    */
//   className: any,
//   /**
//    * @type {String || Object}
//    */
//   activeClassName: any,
//   // === label
//   /**
//    * @alias text
//    */
//   children: any,
//   /**
//    * @alias label
//    * @alias title
//    */
//   text: string,
//   /**
//    * @optional
//    */
//   isExternal: boolean,
//   /**
//    * @description can set the prefix for the url
//    */
//   urlBase: string,
//   /**
//    * @description open in a new tab/window/same window
//    */
//   target: string,
//   /**
//    * === synonymous, use oneOf, not multiple
//    */
//   href: string,
//   link: string,
//   url: string,
//   onClick: func,
//   /**
//    * @type {Function | Object | String}
//    */
//   styles: string,
//   /**
//    * @version 0 - was boolean
//    * @version 1 - is string or node
//    */
//   missingLinkTag: oneOfType([string, node]),
//   /**
//    * @example <Link nofollow />
//    */
//   nofollow: boolean,
//   /**
//    * @alias shouldNotBeFollowedByRobots
//    * @example <Link shouldNotFollow />
//    */
//   shouldNotFollow: boolean,
// }


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_1.default.PureComponent {
  // eslint-disable-next-line
  render() {
    let _a = this.props,
        {
      // actual target
      to,
      href,
      url,
      link,
      onClick,
      // label
      text,
      children,
      //
      className,
      //
      isExternal,
      //
      missingLinkTag,
      //
      target,
      //
      nofollow,
      shouldNotFollow
    } = _a,
        remainingProps = __rest(_a, ["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 (exotic_1.isNil(text)) {
      // || to
      text = children || undefined;
    }

    if (to && missingLinkTag === true) {
      const Tag = missingLinkTag;
      return react_1.default.createElement(Tag, null, 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 (isTrue(isExternal) || IS_TEST) {

    /**
     * As per James guidance,
     * temparorly commenting the ReactRouterLink
     */


    attributes.href = to;
    return react_1.default.createElement("a", Object.assign({}, attributes)); // } else {
    //   attributes.to = {
    //     pathname: to,
    //   }
    // }
    // const view = <ReactRouterNavLink {...attributes} />
    // return view
    // <Link to={to}>{text}</Link>, <a href="">{text}</a>
    // if (isRelative(url))
    // if (isAbsolute(url))
    // if (routes.includes(url))
  }

}

exports.Link = Link;
exports.default = Link; //# sourceMappingURL=Link.js.map