Skip to content

Commit

Permalink
Use functional color variables in CounterLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
VanAnderson committed Mar 3, 2021
1 parent 108c273 commit 39371d9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-suits-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/components': patch
---

Use functional color variables in CounterLabel
10 changes: 5 additions & 5 deletions src/CounterLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const colorStyles = ({scheme, ...props}: StyledCounterLabelProps) => {
return {
color:
scheme === 'gray-light'
? get('colors.gray.9')(props)
? get('colors.counter.text')(props)
: scheme === 'gray'
? get('colors.white')(props)
: get('colors.gray.6')(props)
? get('colors.counter.primary.text')(props)
: get('colors.text.secondary.text')(props)
}
}

const bgStyles = ({scheme, ...props}: StyledCounterLabelProps) => {
return {
backgroundColor:
scheme === 'gray-light'
? get('colors.blackfade15')(props)
? get('colors.counter.bg')(props)
: scheme === 'gray'
? get('colors.gray.5')(props)
? get('colors.counter.primary.bg')(props)
: get('colors.counter.bg')(props)
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/__tests__/CounterLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {colors} from '../theme'
import {render as HTMLRender, cleanup} from '@testing-library/react'
import {axe, toHaveNoViolations} from 'jest-axe'
import 'babel-polyfill'
import {default as primitives} from '@primer/primitives'

expect.extend(toHaveNoViolations)

describe('CounterLabel', () => {
Expand All @@ -27,15 +29,25 @@ describe('CounterLabel', () => {
})

it('respects the gray "scheme" prop', () => {
expect(render(<CounterLabel scheme="gray" />)).toHaveStyleRule('color', colors.white.trim())
expect(render(<CounterLabel scheme="gray" />)).toHaveStyleRule('background-color', colors.gray[5].trim())
const p = primitives
expect(render(<CounterLabel scheme="gray" />)).toHaveStyleRule(
'color',
primitives.colors.light.counter.primary.text.trim()
)
expect(render(<CounterLabel scheme="gray" />)).toHaveStyleRule(
'background-color',
primitives.colors.light.counter.primary.bg.trim()
)
})

it('respects the gray-light "scheme" prop', () => {
expect(render(<CounterLabel scheme="gray-light" />)).toHaveStyleRule('color', colors.gray[9].trim())
expect(render(<CounterLabel scheme="gray-light" />)).toHaveStyleRule(
'color',
primitives.colors.light.counter.text.trim()
)
expect(render(<CounterLabel scheme="gray-light" />)).toHaveStyleRule(
'background-color',
colors.blackfade15.replace(/\s/g, '')
primitives.colors.light.counter.bg
)
})
})
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/CounterLabel.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`CounterLabel renders consistently 1`] = `
font-weight: 600;
line-height: 1;
border-radius: 20px;
color: #586069;
background-color: rgba(209,213,218,0.5);
}
Expand Down

0 comments on commit 39371d9

Please sign in to comment.