Fix resolution of alpha values inside color functions (#9008)

* Fix resolution of alpha values inside color functions

* Update changelog
This commit is contained in:
Jordan Pittman 2022-08-02 11:13:04 -04:00 committed by GitHub
parent 0b5bfc8065
commit 89b960d771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 1 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Dont prefix classes within reused arbitrary variants ([#8992](https://github.com/tailwindlabs/tailwindcss/pull/8992))
- Fix usage of alpha values inside single-named colors that are functions ([#9008](https://github.com/tailwindlabs/tailwindcss/pull/9008))
## [3.1.7] - 2022-07-29

View File

@ -180,7 +180,7 @@ function resolveFunctionKeys(object) {
val = val[path[index++]]
let shouldResolveAsFn =
isFunction(val) && (path.alpha === undefined || index < path.length - 1)
isFunction(val) && (path.alpha === undefined || index <= path.length - 1)
val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
}

View File

@ -761,3 +761,70 @@ it('Theme functions can reference values with slashes in brackets', () => {
`)
})
})
it('works with opacity values defined as a placeholder or a function in when colors is a function', () => {
let config = {
content: [
{
raw: html`
<div
class="bg-foo10 bg-foo20 bg-foo30 bg-foo40 bg-foo11 bg-foo21 bg-foo31 bg-foo41"
></div>
`,
},
],
theme: {
colors: () => ({
foobar1: ({ opacityValue }) => `rgb(255 100 0 / ${opacityValue ?? '100%'})`,
foobar2: `rgb(255 100 0 / <alpha-value>)`,
foobar3: {
100: ({ opacityValue }) => `rgb(255 100 0 / ${opacityValue ?? '100%'})`,
200: `rgb(255 100 0 / <alpha-value>)`,
},
}),
extend: {
backgroundColor: ({ theme }) => ({
foo10: theme('colors.foobar1'),
foo20: theme('colors.foobar2'),
foo30: theme('colors.foobar3.100'),
foo40: theme('colors.foobar3.200'),
foo11: theme('colors.foobar1 / 50%'),
foo21: theme('colors.foobar2 / 50%'),
foo31: theme('colors.foobar3.100 / 50%'),
foo41: theme('colors.foobar3.200 / 50%'),
}),
},
},
}
return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.bg-foo10 {
background-color: rgb(255 100 0 / 100%);
}
.bg-foo20 {
--tw-bg-opacity: 1;
background-color: rgb(255 100 0 / var(--tw-bg-opacity));
}
.bg-foo30 {
background-color: rgb(255 100 0 / 100%);
}
.bg-foo40 {
--tw-bg-opacity: 1;
background-color: rgb(255 100 0 / var(--tw-bg-opacity));
}
.bg-foo11 {
background-color: rgb(255 100 0 / 50%);
}
.bg-foo21 {
background-color: rgb(255 100 0 / 50%);
}
.bg-foo31 {
background-color: rgb(255 100 0 / 50%);
}
.bg-foo41 {
background-color: rgb(255 100 0 / 50%);
}
`)
})
})