Skip to content

Commit ad80cdd

Browse files
authored
Merge pull request #567 from primer/muted-link
Add muted prop to Link.
2 parents 720ce85 + 75ec795 commit ad80cdd

File tree

7 files changed

+67
-14
lines changed

7 files changed

+67
-14
lines changed

docs/content/Link.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ In special cases where you'd like a `<button>` styled like a `Link`, use `<Link
1111
## Default example
1212

1313
```jsx live
14-
<Link mb={1} href="https://github.com">Link</Link>
14+
<Link mb={1} href="https://github.com">
15+
Link
16+
</Link>
1517
```
1618

1719
## System props
@@ -20,8 +22,9 @@ Link components get `COMMON` and `TYPOGRAPHY` system props. Read our [System Pro
2022

2123
## Component props
2224

23-
| Name | Type | Default | Description |
24-
| :-------- | :------ | :-----: | :------------------------------------------ |
25-
| href | String | | URL to be used for the Link |
26-
| underline | Boolean | false | Adds underline to the Link |
27-
| as | String | 'a' | Can be 'a', 'button', 'input', or 'summary' |
25+
| Name | Type | Default | Description |
26+
| :-------- | :------ | :-----: | :------------------------------------------------ |
27+
| href | String | | URL to be used for the Link |
28+
| muted | Boolean | false | Uses light gray for Link color, and blue on hover |
29+
| underline | Boolean | false | Adds underline to the Link |
30+
| as | String | 'a' | Can be 'a', 'button', 'input', or 'summary' |

docs/src/@primer/gatsby-theme-doctocat/components/hero.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import loadable from '@loadable/component'
21
import {Box, Heading, Text} from '@primer/components'
32
import React from 'react'
43
import {Container} from '@primer/gatsby-theme-doctocat'

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ declare module '@primer/components' {
224224
extends CommonProps,
225225
TypographyProps,
226226
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> {
227+
muted?: boolean
227228
underline?: boolean
228229
}
229230

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/components",
3-
"version": "14.2.1",
3+
"version": "14.3.0",
44
"description": "Primer react components",
55
"main": "dist/index.umd.js",
66
"module": "dist/index.esm.js",

src/Link.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types'
22
import styled from 'styled-components'
33
import {system} from 'styled-system'
4-
import {COMMON, TYPOGRAPHY} from './constants'
4+
import {COMMON, TYPOGRAPHY, get} from './constants'
55
import theme from './theme'
66
import elementType from './utils/elementType'
77

@@ -24,24 +24,26 @@ const hoverColor = system({
2424
}
2525
})
2626

27-
const Link = styled.a`
27+
const Link = styled.a.attrs(props => ({
28+
color: props.color ? props.color : props.muted ? 'gray.6' : 'blue.5'
29+
}))`
2830
text-decoration: ${props => (props.underline ? 'underline' : 'none')};
2931
&:hover {
30-
text-decoration: underline;
31-
${hoverColor};
32+
text-decoration: ${props => (props.muted ? 'none' : 'underline')};
33+
${props => (props.hoverColor ? hoverColor : props.muted ? `color: ${get('colors.blue.5')(theme)}` : '')};
3234
}
3335
${props => (props.as === 'button' ? buttonStyles : '')};
3436
${TYPOGRAPHY} ${COMMON};
3537
`
3638

3739
Link.defaultProps = {
38-
theme,
39-
color: 'blue.5'
40+
theme
4041
}
4142

4243
Link.propTypes = {
4344
as: elementType,
4445
href: PropTypes.string,
46+
muted: PropTypes.bool,
4547
theme: PropTypes.object,
4648
underline: PropTypes.bool,
4749
...TYPOGRAPHY.propTypes,

src/__tests__/Link.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ describe('Link', () => {
4646
it('applies button styles when rendering a button element', () => {
4747
expect(render(<Link as="button" />)).toMatchSnapshot()
4848
})
49+
50+
it('respectes the "muted" prop', () => {
51+
expect(render(<Link muted />)).toMatchSnapshot()
52+
})
53+
54+
it('respectes the "color" prop when "muted" prop is also passed', () => {
55+
expect(render(<Link muted color="black" />)).toMatchSnapshot()
56+
})
4957
})

src/__tests__/__snapshots__/Link.js.snap

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,46 @@ exports[`Link renders without any props 1`] = `
6969
/>
7070
`;
7171

72+
exports[`Link respectes the "color" prop when "muted" prop is also passed 1`] = `
73+
.c0 {
74+
-webkit-text-decoration: none;
75+
text-decoration: none;
76+
color: #1b1f23;
77+
}
78+
79+
.c0:hover {
80+
-webkit-text-decoration: none;
81+
text-decoration: none;
82+
color: #0366d6;
83+
}
84+
85+
<a
86+
className="c0"
87+
color="black"
88+
muted={true}
89+
/>
90+
`;
91+
92+
exports[`Link respectes the "muted" prop 1`] = `
93+
.c0 {
94+
-webkit-text-decoration: none;
95+
text-decoration: none;
96+
color: #586069;
97+
}
98+
99+
.c0:hover {
100+
-webkit-text-decoration: none;
101+
text-decoration: none;
102+
color: #0366d6;
103+
}
104+
105+
<a
106+
className="c0"
107+
color="gray.6"
108+
muted={true}
109+
/>
110+
`;
111+
72112
exports[`Link respects hoverColor prop 1`] = `
73113
.c0 {
74114
-webkit-text-decoration: none;

0 commit comments

Comments
 (0)