Skip to content

Commit db475be

Browse files
Support arbitrary values + calc + theme with quotes (#7462)
* Support arbitrary values + calc + theme with quotes * Update changelog
1 parent f116f9f commit db475be

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))
13+
- Support arbitrary values + calc + theme with quotes ([#7462](https://github.com/tailwindlabs/tailwindcss/pull/7462))
1314

1415
## [3.0.22] - 2022-02-11
1516

src/lib/defaultExtractor.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const PATTERNS = [
88
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
99
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source, // bg-[url('...'),url('...')]
1010
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source, // bg-[url("..."),url("...")]
11+
/([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source, // h-[calc(100%-theme('spacing.1'))]
12+
/([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source, // h-[calc(100%-theme("spacing.1"))]
1113
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
1214
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
1315
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source, // `[attr:value]`

tests/arbitrary-values.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,32 @@ it('should be possible to read theme values in arbitrary values (with quotes)',
341341
`)
342342
})
343343
})
344+
345+
it('should be possible to read theme values in arbitrary values (with quotes) when inside calc or similar functions', () => {
346+
let config = {
347+
content: [
348+
{
349+
raw: html`<div
350+
class="w-[calc(100%-theme('spacing.1'))] w-[calc(100%-theme('spacing[0.5]'))]"
351+
></div>`,
352+
},
353+
],
354+
theme: {
355+
spacing: {
356+
0.5: 'calc(.5 * .25rem)',
357+
1: 'calc(1 * .25rem)',
358+
},
359+
},
360+
}
361+
362+
return run('@tailwind utilities', config).then((result) => {
363+
return expect(result.css).toMatchFormattedCss(css`
364+
.w-\[calc\(100\%-theme\(\'spacing\.1\'\)\)\] {
365+
width: calc(100% - calc(1 * 0.25rem));
366+
}
367+
.w-\[calc\(100\%-theme\(\'spacing\[0\.5\]\'\)\)\] {
368+
width: calc(100% - calc(0.5 * 0.25rem));
369+
}
370+
`)
371+
})
372+
})

tests/default-extractor.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const input =
2626
<div class="hover:font-bold"></div>
2727
<div class="content-['>']"></div>
2828
<div class="[--y:theme(colors.blue.500)]">
29+
<div class="w-[calc(100%-theme('spacing.1'))]">
30+
<div class='w-[calc(100%-theme("spacing.2"))]'>
2931
3032
<script>
3133
let classes01 = ["text-[10px]"]
@@ -90,6 +92,8 @@ const includes = [
9092
`hover:test`,
9193
`overflow-scroll`,
9294
`[--y:theme(colors.blue.500)]`,
95+
`w-[calc(100%-theme('spacing.1'))]`,
96+
`w-[calc(100%-theme("spacing.2"))]`,
9397
]
9498

9599
const excludes = [

0 commit comments

Comments
 (0)