Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 76ba529

Browse files
committed
Add support for completely arbitrary width/height
1 parent 3ea5421 commit 76ba529

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

src/corePlugins/height.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { asLength, nameClass } = require('../pluginUtils')
1+
const { asValue, nameClass } = require('../pluginUtils')
22

33
module.exports = function ({ matchUtilities, jit: { theme } }) {
44
matchUtilities({
55
h: (modifier, { theme }) => {
6-
let value = asLength(modifier, theme['height'])
6+
let value = asValue(modifier, theme['height'])
77

88
if (value === undefined) {
99
return []

src/corePlugins/width.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { asLength, nameClass } = require('../pluginUtils')
1+
const { asValue, nameClass } = require('../pluginUtils')
22

33
module.exports = function ({ matchUtilities, jit: { theme } }) {
44
matchUtilities({
55
w: (modifier, { theme }) => {
6-
let value = asLength(modifier, theme['width'])
6+
let value = asValue(modifier, theme['width'])
77

88
if (value === undefined) {
99
return []

src/pluginUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ function asValue(modifier, lookup = {}, { validate = () => true, transform = (v)
111111
return undefined
112112
}
113113

114-
return transform(value)
114+
// add spaces around operators inside calc() that do not follow an operator or (
115+
return transform(value).replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
115116
}
116117

117118
function asUnit(modifier, units, lookup = {}) {
@@ -124,8 +125,7 @@ function asUnit(modifier, units, lookup = {}) {
124125
)
125126
},
126127
transform: (value) => {
127-
// add spaces around operators inside calc() that do not follow an operator or (
128-
return value.replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
128+
return value
129129
},
130130
})
131131
}

tests/08-arbitrary-values.test.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@
1616
.mt-\[clamp\(30px\2c 100px\)\] {
1717
margin-top: clamp(30px, 100px);
1818
}
19+
.h-\[3\.23rem\] {
20+
height: 3.23rem;
21+
}
22+
.h-\[calc\(100\%\+1rem\)\] {
23+
height: calc(100% + 1rem);
24+
}
25+
.h-\[var\(--height\)\] {
26+
height: var(--height);
27+
}
1928
.w-\[3\.23rem\] {
2029
width: 3.23rem;
2130
}
2231
.w-\[calc\(100\%\+1rem\)\] {
2332
width: calc(100% + 1rem);
2433
}
34+
.w-\[var\(--width\)\] {
35+
width: var(--width);
36+
}
2537
.rotate-\[23deg\] {
2638
--tw-rotate: 23deg;
2739
}

tests/08-arbitrary-values.test.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<div class="border-[2.5px]"></div>
1717
<div class="w-[3.23rem]"></div>
1818
<div class="w-[calc(100%+1rem)]"></div>
19+
<div class="w-[var(--width)]"></div>
20+
<div class="h-[3.23rem]"></div>
21+
<div class="h-[calc(100%+1rem)]"></div>
22+
<div class="h-[var(--height)]"></div>
1923
<div class="space-x-[20cm]"></div>
2024
<div class="space-x-[calc(20%-1cm)]"></div>
2125
<div class="grid-cols-[200px,repeat(auto-fill,minmax(15%,100px)),300px]"></div>

0 commit comments

Comments
 (0)