Skip to content

Commit a300955

Browse files
authored
Merge pull request #1102 from primer/VanAnderson/implement-functional-color-vars-5
Implement functional color variables part 5 [Flash, Header]
2 parents 7fd57c8 + 1f1d387 commit a300955

File tree

7 files changed

+70
-15
lines changed

7 files changed

+70
-15
lines changed

.changeset/shy-experts-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': patch
3+
---
4+
5+
Use functional color variables in Flash

.changeset/stupid-eagles-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/components': patch
3+
---
4+
5+
Use functional color variables in Header

src/Flash.tsx

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,40 @@ import {COMMON, get, SystemCommonProps} from './constants'
44
import sx, {SxProp} from './sx'
55

66
const variants = variant({
7-
scale: 'flash'
7+
variants: {
8+
default: {
9+
color: 'alert.info.text',
10+
backgroundColor: 'alert.info.bg',
11+
borderColor: 'alert.info.border',
12+
svg: {
13+
color: 'alert.info.icon'
14+
}
15+
},
16+
success: {
17+
color: 'alert.success.text',
18+
backgroundColor: 'alert.success.bg',
19+
borderColor: 'alert.success.border',
20+
svg: {
21+
color: 'alert.success.icon'
22+
}
23+
},
24+
danger: {
25+
color: 'alert.error.text',
26+
backgroundColor: 'alert.error.bg',
27+
borderColor: 'alert.error.border',
28+
svg: {
29+
color: 'alert.error.icon'
30+
}
31+
},
32+
warning: {
33+
color: 'alert.warn.text',
34+
backgroundColor: 'alert.warn.bg',
35+
borderColor: 'alert.warn.border',
36+
svg: {
37+
color: 'alert.warn.icon'
38+
}
39+
}
40+
}
841
})
942

1043
const Flash = styled.div<
@@ -15,7 +48,7 @@ const Flash = styled.div<
1548
SxProp
1649
>`
1750
position: relative;
18-
color: ${get('colors.text.grayDark')};
51+
color: ${get('colors.text.primary')};
1952
padding: ${get('space.3')};
2053
border-style: solid;
2154
border-width: ${props => (props.full ? '1px 0px' : '1px')};
@@ -27,7 +60,6 @@ const Flash = styled.div<
2760
}
2861
2962
svg {
30-
color: ${props => get(`flashIcon.${props.variant}`)(props.theme)};
3163
margin-right: ${get('space.2')};
3264
}
3365

src/Header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const Header = styled.div<StyledHeaderProps>`
1717
padding: ${get('space.3')};
1818
font-size: ${get('fontSizes.1')};
1919
line-height: ${get('lineHeights.default')};
20-
color: ${get('colors.whitefade70')};
21-
background-color: ${get('colors.bg.grayDark')};
20+
color: ${get('colors.header.text')};
21+
background-color: ${get('colors.header.bg')};
2222
align-items: center;
2323
flex-wrap: nowrap;
2424
@@ -57,7 +57,7 @@ const HeaderLink = styled.a.attrs<StyledHeaderLinkProps>(({to}) => {
5757
}
5858
})<StyledHeaderLinkProps>`
5959
font-weight: ${get('fontWeights.bold')};
60-
color: ${get('colors.text.white')};
60+
color: ${get('colors.header.logo')};
6161
white-space: nowrap;
6262
cursor: pointer;
6363
text-decoration: none;
@@ -66,7 +66,7 @@ const HeaderLink = styled.a.attrs<StyledHeaderLinkProps>(({to}) => {
6666
6767
&:hover,
6868
&:focus {
69-
color: ${get('colors.whitefade70')};
69+
color: ${get('colors.header.text')};
7070
}
7171
7272
${COMMON};

src/__tests__/Flash.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import {Flash} from '..'
33
import {COMMON} from '../constants'
4-
import theme, {colors} from '../theme'
4+
import theme from '../theme'
55
import {render, behavesAsComponent, checkExports} from '../utils/testing'
66
import {render as HTMLRender, cleanup} from '@testing-library/react'
77
import {axe, toHaveNoViolations} from 'jest-axe'
@@ -29,9 +29,18 @@ describe('Flash', () => {
2929
})
3030

3131
it('respects the "variant" prop', () => {
32-
expect(render(<Flash variant="warning" theme={theme} />)).toHaveStyleRule('background-color', colors.yellow[1])
33-
expect(render(<Flash variant="danger" theme={theme} />)).toHaveStyleRule('background-color', '#FFE3E6')
34-
expect(render(<Flash variant="success" theme={theme} />)).toHaveStyleRule('background-color', colors.green[1])
35-
expect(render(<Flash theme={theme} />)).toHaveStyleRule('background-color', colors.blue[1])
32+
expect(render(<Flash variant="warning" theme={theme} />)).toHaveStyleRule(
33+
'background-color',
34+
theme.colors.alert.warn.bg
35+
)
36+
expect(render(<Flash variant="danger" theme={theme} />)).toHaveStyleRule(
37+
'background-color',
38+
theme.colors.alert.error.bg
39+
)
40+
expect(render(<Flash variant="success" theme={theme} />)).toHaveStyleRule(
41+
'background-color',
42+
theme.colors.alert.success.bg
43+
)
44+
expect(render(<Flash theme={theme} />)).toHaveStyleRule('background-color', theme.colors.alert.info.bg)
3645
})
3746
})

src/__tests__/__snapshots__/Flash.tsx.snap

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports[`Flash renders consistently 1`] = `
99
border-width: 1px;
1010
border-radius: 6px;
1111
margin-top: 0;
12+
color: #24292e;
1213
background-color: #dbedff;
1314
border-color: rgba(4,66,137,0.2);
1415
}
@@ -18,10 +19,13 @@ exports[`Flash renders consistently 1`] = `
1819
}
1920
2021
.c0 svg {
21-
color: rgba(4,66,137,0.6);
2222
margin-right: 8px;
2323
}
2424
25+
.c0 svg {
26+
color: rgba(4,66,137,0.6);
27+
}
28+
2529
<div
2630
className="c0"
2731
/>

src/__tests__/__snapshots__/Header.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exports[`Header Header.Link renders consistently 1`] = `
4444
4545
.c0:hover,
4646
.c0:focus {
47-
color: rgba(255,255,255,0.70);
47+
color: rgba(255,255,255,0.7);
4848
}
4949
5050
<a
@@ -62,7 +62,7 @@ exports[`Header renders consistently 1`] = `
6262
padding: 16px;
6363
font-size: 14px;
6464
line-height: 1.5;
65-
color: rgba(255,255,255,0.70);
65+
color: rgba(255,255,255,0.7);
6666
background-color: #24292e;
6767
-webkit-align-items: center;
6868
-webkit-box-align: center;

0 commit comments

Comments
 (0)