Skip to content

Commit

Permalink
Include all shadow variables in theme object (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
colebemis committed Jun 16, 2021
1 parent afb6fe5 commit dc17a49
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/forty-books-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Include all shadow variables in theme object
41 changes: 41 additions & 0 deletions src/__tests__/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {isShadowValue} from '../utils/theme'

describe('isShadowValue', () => {
it('accepts transparent', () => {
expect(isShadowValue('0 0 0 transparent')).toBe(true)
})

it('accepts hex colors', () => {
expect(isShadowValue('0 0 0 #ff0000')).toBe(true)
expect(isShadowValue('0 0 0 #ff0')).toBe(true)
})

it('accepts rgba colors', () => {
expect(isShadowValue('0 0 0 rgb(255, 0, 0)')).toBe(true)
expect(isShadowValue('0 0 0 rgba(255,0,0,0.2)')).toBe(true)
})

it('accepts px values', () => {
expect(isShadowValue('12px 24px 0 #000')).toBe(true)
})

it('accepts em values', () => {
expect(isShadowValue('0.5em 1em 0 #000')).toBe(true)
})

it('accepts inset values', () => {
expect(isShadowValue('inset 12px 24px 0 #000')).toBe(true)
})

it('rejects individual colors', () => {
expect(isShadowValue('red')).toBe(false)
expect(isShadowValue('#f00')).toBe(false)
expect(isShadowValue('rgb(255, 0, 0)')).toBe(false)
})

it('rejects individual numeric values', () => {
expect(isShadowValue('0')).toBe(false)
expect(isShadowValue('12px')).toBe(false)
expect(isShadowValue('0.5em')).toBe(false)
})
})
2 changes: 1 addition & 1 deletion src/utils/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function fontStack(fonts) {
// will not be needed.

function isShadowValue(value) {
return typeof value === 'string' && /(inset\s|)([0-9.empx\s]+){1,4}rgb[a]?\(.*\)/.test(value)
return typeof value === 'string' && /(inset\s|)([0-9.]+(\w*)\s){1,4}(rgb[a]?\(.*\)|\w+)/.test(value)
}

function isColorValue(value) {
Expand Down

1 comment on commit dc17a49

@vercel
Copy link

@vercel vercel bot commented on dc17a49 Jun 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.