Skip to content

Commit

Permalink
Handle variable colors that have variable fallback values (#12049)
Browse files Browse the repository at this point in the history
* Parse colors even when variable has fallback that is a variable

* Update changelog
  • Loading branch information
thecrypticace committed Sep 20, 2023
1 parent 5366d24 commit d3f2221
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
- Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709))
- Make `content` optional for presets in TypeScript types ([#11730](https://github.com/tailwindlabs/tailwindcss/pull/11730))
- Handle variable colors that have variable fallback values ([#12049](https://github.com/tailwindlabs/tailwindcss/pull/12049))

### Added

Expand Down
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);
}
`)
})

0 comments on commit d3f2221

Please sign in to comment.