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.tsx
Size: Mime:
/**
 * @file @invalid @fixme is not routing correctly
 * @see https://bitbucket.org/skava-admin/mono/src/d2ea5248362f096a0f3272dacbca0951a95ab192/modules/link/?at=xxx-appollo-rest-data-sources
 */
import React from 'react'
import {
  Link as ReactRouterLink,
  NavLink as ReactRouterNavLink,
} from 'react-router-dom'
import { isNil, isTrue } from 'exotic'
import { LinkProps } from './typings'

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.PureComponent<LinkProps> {
  // eslint-disable-next-line
  render() {
    let {
      // actual target
      to,
      href,
      url,
      link,
      onClick,
      // label
      text,
      children,
      //
      className,
      //
      isExternal,
      //
      missingLinkTag,
      //
      target,
      //
      nofollow,
      shouldNotFollow,
      ...remainingProps
    } = this.props

    to = to || href || url || link || onClick

    // <a text="eh">
    // <a children="eh">
    // <a>{'eh'}</a>
    // when passing text in via children
    if (isNil(text)) {
      // || to
      text = children || undefined
    }

    if (to && missingLinkTag === true) {
      const Tag = missingLinkTag
      return <Tag>{to}</Tag>
    }

    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 = {
      ...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 <a {...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))
  }
}

export { Link }
export default Link