Allow negating utilities using min/max/clamp (#9237)

* Allow negating utilities using min/max/clamp

* Update changelog
This commit is contained in:
Jordan Pittman 2022-09-01 12:15:23 -04:00 • committed by GitHub
parent 8b1bf8006d
commit 17b81b4150
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View file

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add a standalone CLI build for 32-bit Linux on ARM (`node16-linux-armv7`) ([#9084](https://github.com/tailwindlabs/tailwindcss/pull/9084))
- Add future flag to disable color opacity utility plugins ([#9088](https://github.com/tailwindlabs/tailwindcss/pull/9088))
- Add negative value support for `outline-offset` ([#9136](https://github.com/tailwindlabs/tailwindcss/pull/9136))
- Allow negating utilities using min/max/clamp ([#9237](https://github.com/tailwindlabs/tailwindcss/pull/9237))
### Fixed

View file

@ -10,7 +10,15 @@ export default function (value) {
return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
}
if (value.includes('var(') || value.includes('calc(')) {
return `calc(${value} * -1)`
// What functions we support negating numeric values for
// var() isn't inherently a numeric function but we support it anyway
// The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
// to produce generally useful results and that will be covered already
let numericFunctions = ['var', 'calc', 'min', 'max', 'clamp']
for (const fn of numericFunctions) {
if (value.includes(`${fn}(`)) {
return `calc(${value} * -1)`
}
}
}

View file

@ -146,6 +146,42 @@ test('a value that includes a calc', () => {
})
})
test('a value that includes min/max/clamp functions', () => {
let config = {
content: [{ raw: html`<div class="mt-min -mt-min mt-max -mt-max mt-clamp -mt-clamp"></div>` }],
theme: {
margin: {
min: 'min(100vmin, 3rem)',
max: 'max(100vmax, 3rem)',
clamp: 'clamp(1rem, 100vh, 3rem)',
},
},
}
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchCss(css`
.mt-min {
margin-top: min(100vmin, 3rem);
}
.-mt-min {
margin-top: calc(min(100vmin, 3rem) * -1);
}
.mt-max {
margin-top: max(100vmax, 3rem);
}
.-mt-max {
margin-top: calc(max(100vmax, 3rem) * -1);
}
.mt-clamp {
margin-top: clamp(1rem, 100vh, 3rem);
}
.-mt-clamp {
margin-top: calc(clamp(1rem, 100vh, 3rem) * -1);
}
`)
})
})
test('a keyword value', () => {
let config = {
content: [{ raw: html`<div class="-mt-auto mt-auto"></div>` }],