Skip to content

Commit 078186a

Browse files
authored
Add css functions to data types (#6258)
* update changelog * add tests to verify that `w-[0]` works * ensure that `min`, `max` and `clamp` also work with arbitrary values * update changelog
1 parent add8d62 commit 078186a

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Add `portrait` and `landscape` variants ([#6046](https://github.com/tailwindlabs/tailwindcss/pull/6046))
2121
- Add `text-decoration-style`, `text-decoration-thickness`, and `text-underline-offset` utilities ([#6004](https://github.com/tailwindlabs/tailwindcss/pull/6004))
2222
- Add `menu` reset to preflight ([#6213](https://github.com/tailwindlabs/tailwindcss/pull/6213))
23+
- Allow `0` as a valid `length` value ([#6233](https://github.com/tailwindlabs/tailwindcss/pull/6233))
24+
- Add css functions to data types ([#6258](https://github.com/tailwindlabs/tailwindcss/pull/6258))
2325

2426
### Changed
2527

src/util/dataTypes.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { parseColor } from './color'
22
import { parseBoxShadowValue } from './parseBoxShadowValue'
33

4+
let cssFunctions = ['min', 'max', 'clamp', 'calc']
5+
46
// Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
57

68
let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
@@ -51,11 +53,11 @@ export function url(value) {
5153
}
5254

5355
export function number(value) {
54-
return !isNaN(Number(value))
56+
return !isNaN(Number(value)) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?`).test(value))
5557
}
5658

5759
export function percentage(value) {
58-
return /%$/g.test(value) || /^calc\(.+?%\)/g.test(value)
60+
return /%$/g.test(value) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?%`).test(value))
5961
}
6062

6163
let lengthUnits = [
@@ -79,9 +81,9 @@ let lengthUnits = [
7981
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
8082
export function length(value) {
8183
return (
84+
value === 0 ||
8285
new RegExp(`${lengthUnitsPattern}$`).test(value) ||
83-
new RegExp(`^calc\\(.+?${lengthUnitsPattern}`).test(value) ||
84-
value === 0
86+
cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(value))
8587
)
8688
}
8789

tests/arbitrary-values.test.css

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
.min-h-\[var\(--height\)\] {
140140
min-height: var(--height);
141141
}
142+
.w-\[0\] {
143+
width: 0;
144+
}
142145
.w-\[3\.23rem\] {
143146
width: 3.23rem;
144147
}
@@ -767,6 +770,9 @@
767770
.text-\[length\:var\(--font-size\)\] {
768771
font-size: var(--font-size);
769772
}
773+
.text-\[min\(10vh\2c 100px\)\] {
774+
font-size: min(10vh, 100px);
775+
}
770776
.font-\[300\] {
771777
font-weight: 300;
772778
}

tests/arbitrary-values.test.html

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<div class="min-h-[calc(100%+1rem)]"></div>
6161
<div class="min-h-[var(--height)]"></div>
6262

63+
<div class="w-[0]"></div>
6364
<div class="w-[3.23rem]"></div>
6465
<div class="w-[calc(100%+1rem)]"></div>
6566
<div class="w-[calc(var(--10-10px,calc(-20px-(-30px--40px)))-50px)]"></div>
@@ -280,6 +281,7 @@
280281
<div class="text-[2.23rem]"></div>
281282
<div class="text-[length:var(--font-size)]"></div>
282283
<div class="text-[angle:var(--angle)]"></div>
284+
<div class="text-[min(10vh,100px)]"></div>
283285

284286
<div class="font-[300]"></div>
285287
<div class="font-[number:lighter]"></div>

0 commit comments

Comments
 (0)