|
1 | 1 | import React from 'react'; |
2 | 2 | import styled from 'styled-components'; |
3 | 3 | import PropTypes from 'prop-types'; |
| 4 | +import { Box } from 'rebass'; |
4 | 5 |
|
5 | 6 | const Anchor = ({ |
6 | | - href, imgSrc, imgAlt, children, newpage, ...rest |
| 7 | + href, imgSrc, imgAlt, children, newpage, display, textColor, ...rest |
7 | 8 | }) => ( |
8 | | - <StyledAnchor |
9 | | - href={href} |
10 | | - target={newpage ? '_blank' : ''} |
11 | | - rel={newpage ? 'noopener' : ''} |
12 | | - {...rest} |
13 | | - > |
14 | | - { |
15 | | - imgSrc |
16 | | - && <img alt={imgAlt} src={imgSrc} {...rest} /> |
17 | | - } |
18 | | - {children} |
19 | | - </StyledAnchor> |
| 9 | + <Box css={`display: ${display}`} {...rest}> |
| 10 | + <StyledAnchor |
| 11 | + href={href} |
| 12 | + target={newpage ? '_blank' : ''} |
| 13 | + rel={newpage ? 'noopener' : ''} |
| 14 | + textColor={textColor} |
| 15 | + {...rest} |
| 16 | + > |
| 17 | + { |
| 18 | + imgSrc |
| 19 | + && <img alt={imgAlt} src={imgSrc} {...rest} /> |
| 20 | + } |
| 21 | + {children} |
| 22 | + </StyledAnchor> |
| 23 | + </Box> |
20 | 24 | ); |
21 | 25 |
|
22 | 26 | const StyledAnchor = styled.a` |
23 | 27 | justify-content: center; |
24 | 28 | align-items: center; |
25 | | - text-decoration: none; |
26 | 29 | cursor: ${props => (props.href ? 'pointer' : 'default')}; |
27 | | - display: ${props => (props.display)}; |
28 | | - text-decoration: ${props => (props.underline)}; |
29 | | - color: ${props => props.theme.colors.secondary}; |
30 | | -
|
31 | | - &:hover { |
32 | | - color: ${props => props.theme.colors.primary}; |
33 | | - } |
| 30 | + text-decoration: ${props => (props.underline ? 'underline' : 'none')}; |
| 31 | + color: ${props => (props.textColor ? props.theme.colors.black : props.theme.colors.primary)}; |
34 | 32 |
|
35 | 33 | img { |
36 | | - width: ${props => (props.imgwidth)}; |
| 34 | + max-width: 100%; |
37 | 35 | height: ${props => (props.imgheight)}; |
38 | 36 | } |
39 | 37 | `; |
40 | 38 |
|
41 | 39 | Anchor.defaultProps = { |
42 | | - display: 'inline-block', |
43 | | - underline: null, |
| 40 | + display: 'inline', |
| 41 | + underline: false, |
44 | 42 | newpage: null, |
45 | 43 | href: '#', |
46 | | - imgwidth: '100px', |
47 | 44 | imgheight: '40px', |
48 | 45 | imgAlt: '', |
| 46 | + textColor: false, |
49 | 47 | }; |
50 | 48 |
|
51 | 49 | Anchor.propTypes = { |
52 | 50 | display: PropTypes.string, |
53 | 51 | underline: PropTypes.bool, |
54 | 52 | newpage: PropTypes.bool, |
55 | 53 | href: PropTypes.string, |
56 | | - imgwidth: PropTypes.string, |
57 | 54 | imgheight: PropTypes.string, |
58 | 55 | imgAlt: PropTypes.string, |
| 56 | + textColor: PropTypes.bool, |
59 | 57 | }; |
60 | 58 |
|
61 | 59 | export default Anchor; |
0 commit comments