Skip to content

Fix transparent not working as a color value for shorthands #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/__tests__/colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import transformCss from '..'

it('transforms hex colors', () => {
expect(transformCss([['color', '#f00']])).toEqual({ color: '#f00' })
})

it('transforms rgb colors', () => {
expect(transformCss([['color', 'rgb(255, 0, 0)']])).toEqual({
color: 'rgb(255, 0, 0)',
})
})

it('transforms transparent color', () => {
expect(transformCss([['color', 'transparent']])).toEqual({
color: 'transparent',
})
})

it('transforms border shorthand with transparent color', () => {
expect(transformCss([['border', '2px dashed transparent']])).toEqual({
borderColor: 'transparent',
borderStyle: 'dashed',
borderWidth: 2,
})
})

it('transforms background shorthand with transparent color', () => {
expect(transformCss([['background', 'transparent']])).toEqual({
backgroundColor: 'transparent',
})
})
10 changes: 0 additions & 10 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ it('transforms strings', () => {
expect(transformCss([['color', 'red']])).toEqual({ color: 'red' })
})

it('transforms hex colors', () => {
expect(transformCss([['color', '#f00']])).toEqual({ color: '#f00' })
})

it('transforms rgb colors', () => {
expect(transformCss([['color', 'rgb(255, 0, 0)']])).toEqual({
color: 'rgb(255, 0, 0)',
})
})

it('converts to camel-case', () => {
expect(transformCss([['background-color', 'red']])).toEqual({
backgroundColor: 'red',
Expand Down
4 changes: 3 additions & 1 deletion src/tokenTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const cssFunctionNameRe = /^(rgba?|hsla?|hwb|lab|lch|gray|color)$/
const matchColor = node => {
if (
node.type === 'word' &&
(hexColorRe.test(node.value) || node.value in cssColorKeywords)
(hexColorRe.test(node.value) ||
node.value in cssColorKeywords ||
node.value === 'transparent')
) {
return node.value
} else if (node.type === 'function' && cssFunctionNameRe.test(node.value)) {
Expand Down