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
Parse colors even when variable has fallback that is a variable
  • Loading branch information
thecrypticace committed Sep 20, 2023
commit 4a0220c119d8251176ac5223edc671057ebfb5d1
2 changes: 1 addition & 1 deletion src/util/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
let VALUE = /(?:\d+|\d*\.\d+)%?/
let SEP = /(?:\s*,\s*|\s+)/
let ALPHA_SEP = /\s*[,/]\s*/
let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/
let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)(?:,(?:[^ )]*?|var\(--[^ )]*?\)))?\)/

let RGB = new RegExp(
`^(rgba?)\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`
Expand Down
18 changes: 18 additions & 0 deletions tests/opacity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,3 +1045,21 @@ it('can replace the potential alpha value in rgba/hsla syntax', async () => {
}
`)
})

it('variables with variable fallback values can use opacity modifier', async () => {
let config = {
content: [
{
raw: html`<div class="bg-[rgb(var(--some-var,var(--some-other-var)))]/50"></div>`,
},
],
}

let result = await run(`@tailwind utilities;`, config)

expect(result.css).toMatchFormattedCss(css`
.bg-\[rgb\(var\(--some-var\,var\(--some-other-var\)\)\)\]\/50 {
background-color: rgb(var(--some-var, var(--some-other-var)) / 0.5);
}
`)
})