Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import { DOMAttributes } from 'react'
  2.  
  3. interface IArrowLinkProps extends DOMAttributes<{}> {
  4. link?: string
  5. target?: string
  6. type?: string
  7. reverse?: boolean
  8. }
  9.  
  10.  
  11. import * as React from 'react'
  12. import { string } from 'prop-types'
  13. import { Link } from 'react-router-dom'
  14. import styled, { css } from 'styled-components'
  15.  
  16. import { EXTRA_TEXT } from '~/components/pru/ui-colors'
  17. import { clearBtn } from '~/utils/mixins'
  18. import { IArrowLinkProps } from './ArrowLink.d'
  19.  
  20. const arrowLinkCss = css`
  21. ${clearBtn} display: inline-block;
  22. font-family: 'Proba';
  23. font-size: 14px;
  24. line-height: 1.29;
  25. text-align: inherit;
  26. color: ${EXTRA_TEXT};
  27. border: 0;
  28. opacity: 0.7;
  29. transition: opacity 0.15s linear;
  30.  
  31. ${(props: IArrowLinkProps) => (props.reverse ? `display: inline-flex;
  32. align-items: center;
  33. flex-direction: row-reverse;
  34. justify-content: flex-end;` : ``)};
  35.  
  36. .arrow-svg {
  37. display: inline-block;
  38. color: inherit;
  39. margin-left: 9px;
  40. transition: transform 0.15s linear;
  41.  
  42. ${(props: IArrowLinkProps) => (props.reverse ? `transform: rotateY(180deg);margin-right: 6px;` : ``)};
  43. }
  44.  
  45. &:hover,
  46. &:focus,
  47. &:active {
  48. opacity: 1;
  49.  
  50. .arrow-svg {
  51. transform: ${(props: IArrowLinkProps) => (props.reverse ?
  52. `translateX(-3px) rotateY(180deg);` : `translateX(3px);`)};
  53. }
  54. }
  55.  
  56. &:focus {
  57. outline: none;
  58. }
  59. `
  60.  
  61. const NativeLink = styled.a`
  62. ${arrowLinkCss};
  63. `
  64.  
  65. const ReactLink = styled(Link)`
  66. ${arrowLinkCss};
  67. `
  68.  
  69. const Button = styled.button`
  70. ${arrowLinkCss};
  71. `
  72.  
  73. export default class ArrowLink extends React.PureComponent<IArrowLinkProps> {
  74. static propTypes = {
  75. link: string,
  76. target: string
  77. }
  78.  
  79. renderSvg() {
  80. return (
  81. <svg
  82. className="arrow-svg"
  83. width="9"
  84. height="9"
  85. xmlns="http://www.w3.org/2000/svg"
  86. >
  87. <g
  88. stroke="currentColor"
  89. strokeWidth=".875"
  90. fill="none"
  91. fillRule="evenodd"
  92. >
  93. <path d="M4.95 8.55l3.6-4.05L4.95.45M0 4.5h8.1" />
  94. </g>
  95. </svg>
  96. )
  97. }
  98.  
  99. render() {
  100. const { link, target, type = 'submit', children, ...props } = this.props
  101.  
  102. if (link && target === '_blank') {
  103. return (
  104. <NativeLink href={link} target="_blank" {...props}>
  105. {children}
  106. {this.renderSvg()}
  107. </NativeLink>
  108. )
  109. } else if (link) {
  110. return (
  111. <ReactLink to={link} {...props}>
  112. {children}
  113. {this.renderSvg()}
  114. </ReactLink>
  115. )
  116. } else {
  117. return (
  118. <Button type={type} {...props}>
  119. {children}
  120. {this.renderSvg()}
  121. </Button>
  122. )
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement