Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Ensure default alpha is 1.0 when using new <alpha-value> format wit…
…h the theme function
  • Loading branch information
thecrypticace committed Jun 15, 2022
commit 691c30a37f51bed2e22d22b443735c45b1ad9e75
12 changes: 9 additions & 3 deletions src/lib/evaluateTailwindFunctions.js
Original file line number Diff line number Diff line change
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
30 changes: 30 additions & 0 deletions tests/evaluateTailwindFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,36 @@ 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 {
background: theme(colors.blue.400);
color: theme(colors.blue.500);
}
`

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

return runFull(input, {
theme: {
colors: {
blue: {
400: 'rgb(0 0 255 / <alpha-value>)',
500: 'rgb(var(--foo) / <alpha-value>)',
},
},
},
}).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