Skip to content

Commit

Permalink
Ensure default alpha is 1.0 when using new <alpha-value> format wit…
Browse files Browse the repository at this point in the history
…h the theme function
  • Loading branch information
thecrypticace committed Jun 15, 2022
1 parent 3cf48bf commit 204e9d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib/evaluateTailwindFunctions.js
Expand Up @@ -183,9 +183,15 @@ export default function ({ tailwindConfig: config }) {
throw node.error(error)
}

if (alpha !== undefined) {
value = parseColorFormat(value)
value = withAlphaValue(value, alpha, value)
let maybeColor = parseColorFormat(value)
let isColorFunction = maybeColor !== undefined && typeof maybeColor === 'function'

if (alpha !== undefined || isColorFunction) {
if (alpha === undefined) {
alpha = 1.0
}

value = withAlphaValue(maybeColor, alpha, maybeColor)
}

return value
Expand Down
31 changes: 31 additions & 0 deletions tests/evaluateTailwindFunctions.test.js
Expand Up @@ -1025,6 +1025,37 @@ test('Theme function can extract alpha values for colors (8)', () => {
})
})

test('Theme functions replace the alpha value placeholder even with no alpha provided', () => {
let input = css`
.foo {
color: theme(colors.blue.500);
}
`

let output = css`
.foo {
color: rgb(var(--foo) / 1);
}
`

return runFull(input, {
theme: {
colors: {
blue: {
500: 'rgb(var(--foo) / <alpha-value>)',
},
},

opacity: {
myalpha: '50%',
},
},
}).then((result) => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
})
})

test('Theme functions can reference values with slashes in brackets', () => {
let input = css`
.foo1 {
Expand Down

0 comments on commit 204e9d1

Please sign in to comment.