Skip to content

Commit 8012d18

Browse files
committed
Handle variable colors that have variable fallback values (#12049)
* Parse colors even when variable has fallback that is a variable * Update changelog
1 parent 38fd41e commit 8012d18

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
## [3.3.3] - 2023-07-13
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
@@ -1113,3 +1113,21 @@ crosscheck(({ stable, oxide }) => {
11131113
`)
11141114
})
11151115
})
1116+
1117+
it('variables with variable fallback values can use opacity modifier', async () => {
1118+
let config = {
1119+
content: [
1120+
{
1121+
raw: html`<div class="bg-[rgb(var(--some-var,var(--some-other-var)))]/50"></div>`,
1122+
},
1123+
],
1124+
}
1125+
1126+
let result = await run(`@tailwind utilities;`, config)
1127+
1128+
expect(result.css).toMatchFormattedCss(css`
1129+
.bg-\[rgb\(var\(--some-var\,var\(--some-other-var\)\)\)\]\/50 {
1130+
background-color: rgb(var(--some-var, var(--some-other-var)) / 0.5);
1131+
}
1132+
`)
1133+
})

0 commit comments

Comments
 (0)