Skip to content

Commit

Permalink
[JIT] Support CSS Variables in arbitrary calc (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Apr 30, 2021
1 parent 44eddad commit b80b5bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jit/pluginUtils.js
Expand Up @@ -112,7 +112,10 @@ function asValue(modifier, lookup = {}, { validate = () => true, transform = (v)
}

// add spaces around operators inside calc() that do not follow an operator or (
return transform(value).replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
return transform(value).replace(
/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
'$1 $2 '
)
}

function asUnit(modifier, units, lookup = {}) {
Expand Down
9 changes: 9 additions & 0 deletions jit/tests/arbitrary-values.test.css
Expand Up @@ -49,9 +49,18 @@
.w-\[calc\(100\%\+1rem\)\] {
width: calc(100% + 1rem);
}
.w-\[calc\(var\(--10-10px\2c calc\(-20px-\(-30px--40px\)\)\)-50px\)\] {
width: calc(var(--10-10px, calc(-20px - (-30px - -40px))) - 50px);
}
.w-\[var\(--width\)\] {
width: var(--width);
}
.w-\[var\(--width\2c calc\(100\%\+1rem\)\)\] {
width: var(--width, calc(100% + 1rem));
}
.w-\[calc\(100\%\/3-1rem\*2\)\] {
width: calc(100% / 3 - 1rem * 2);
}
.min-w-\[3\.23rem\] {
min-width: 3.23rem;
}
Expand Down
3 changes: 3 additions & 0 deletions jit/tests/arbitrary-values.test.html
Expand Up @@ -16,7 +16,10 @@
<div class="border-[2.5px]"></div>
<div class="w-[3.23rem]"></div>
<div class="w-[calc(100%+1rem)]"></div>
<div class="w-[calc(var(--10-10px,calc(-20px-(-30px--40px)))-50px)]"></div>
<div class="w-[var(--width)]"></div>
<div class="w-[var(--width,calc(100%+1rem))]"></div>
<div class="w-[calc(100%/3-1rem*2)]"></div>
<div class="min-w-[3.23rem]"></div>
<div class="min-w-[calc(100%+1rem)]"></div>
<div class="min-w-[var(--width)]"></div>
Expand Down

0 comments on commit b80b5bb

Please sign in to comment.