All files / src/components Url.js

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5
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                        3x   3x 1x     3x             4x                        
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import React, { PropTypes } from 'react';
import Link from './Link';
 
import type { UrlProps } from '../types';
 
export default function Url({ children, ...props }: UrlProps) {
  let url = children;
 
  if (!url.match(/^https?:\/\//)) {
    url = `http://${url}`;
  }
 
  return (
    <Link {...props} href={url}>
      {children}
    </Link>
  );
}
 
Url.propTypes = {
  children: PropTypes.string.isRequired,
  urlParts: PropTypes.shape({
    scheme: PropTypes.string,
    auth: PropTypes.string,
    host: PropTypes.string,
    port: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    path: PropTypes.string,
    query: PropTypes.string,
    fragment: PropTypes.string,
  }),
};