Skip to content

Commit d3f2221

Browse files
Handle variable colors that have variable fallback values (#12049)
* Parse colors even when variable has fallback that is a variable * Update changelog
1 parent 5366d24 commit d3f2221

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
1818
- Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709))
1919
- Make `content` optional for presets in TypeScript types ([#11730](https://github.com/tailwindlabs/tailwindcss/pull/11730))
20+
- Handle variable colors that have variable fallback values ([#12049](https://github.com/tailwindlabs/tailwindcss/pull/12049))
2021

2122
### Added
2223

src/util/color.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
55
let VALUE = /(?:\d+|\d*\.\d+)%?/
66
let SEP = /(?:\s*,\s*|\s+)/
77
let ALPHA_SEP = /\s*[,/]\s*/
8-
let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/
8+
let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)(?:,(?:[^ )]*?|var\(--[^ )]*?\)))?\)/
99

1010
let RGB = new RegExp(
1111
`^(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*\\)$`

tests/opacity.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -1045,3 +1045,21 @@ it('can replace the potential alpha value in rgba/hsla syntax', async () => {
10451045
}
10461046
`)
10471047
})
1048+
1049+
it('variables with variable fallback values can use opacity modifier', async () => {
1050+
let config = {
1051+
content: [
1052+
{
1053+
raw: html`<div class="bg-[rgb(var(--some-var,var(--some-other-var)))]/50"></div>`,
1054+
},
1055+
],
1056+
}
1057+
1058+
let result = await run(`@tailwind utilities;`, config)
1059+
1060+
expect(result.css).toMatchFormattedCss(css`
1061+
.bg-\[rgb\(var\(--some-var\,var\(--some-other-var\)\)\)\]\/50 {
1062+
background-color: rgb(var(--some-var, var(--some-other-var)) / 0.5);
1063+
}
1064+
`)
1065+
})

0 commit comments

Comments
 (0)