2021-04-30 16:58:40 +02:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import path from 'path'
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2021-09-09 18:10:04 +02:00
|
|
|
import { run, html, css } from './util/run'
|
2021-04-02 11:16:15 -04:00
|
|
|
|
|
|
|
|
test('arbitrary values', () => {
|
|
|
|
|
let config = {
|
Remove AOT (#5340)
* make `jit` mode the default when no mode is specified
* unify JIT and AOT codepaths
* ensure `Object.entries` on undefined doesn't break
It could be that sometimes you don't have values in your config (e.g.: `presets: []`), this in turn will break some plugins where we assume we have a value.
* drop AOT specific tests
These tests are all covered by JIT mode already and were AOT specific.
* simplify tests, and add a few
Some of the tests were written for AOT specifically, some were missing. We also updated the way we write those tests, essentially making Tailwind a blackbox, by testing against the final output.
Now that JIT mode is the default, this is super fast because we only generate what is used, instead of partially testing in a 3MB file or building it all, then purging.
* add some todo's to make sure we warn in a few cases
* make `darkMode: 'media'`, the default
This also includes moving dark mode tests to its own dedicated file.
* remove PostCSS 7 compat mode
* update CLI to be JIT-first
* fix integration tests
This is not a _real_ fix, but it does solve the broken test for now.
* warn when using @responsive or @variants
* remove the JIT preview warning
* remove AOT-only code paths
* remove all `mode: 'jit'` blocks
Also remove `variants: {}` since they are not useful in `JIT` mode
anymore.
* drop unused dependencies
* rename `purge` to `content`
* remove static CDN builds
* mark `--purge` as deprecated in the CLI
This will still work, but a warning will be printed and it won't show up
in the `--help` output.
* cleanup nesting plugin
We don't have to duplicate it anymore since there is no PostCSS 7
version anymore.
* make sure integration tests run in band
* cleanup folder structure
* make sure nesting folder is available
* simplify resolving of purge/content information
2021-09-01 17:13:59 +02:00
|
|
|
content: [path.resolve(__dirname, './arbitrary-values.test.html')],
|
2021-04-02 11:16:15 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-03 13:48:16 +02:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
2021-04-02 11:16:15 -04:00
|
|
|
let expectedPath = path.resolve(__dirname, './arbitrary-values.test.css')
|
|
|
|
|
let expected = fs.readFileSync(expectedPath, 'utf8')
|
|
|
|
|
|
2021-04-02 13:51:48 -04:00
|
|
|
expect(result.css).toMatchFormattedCss(expected)
|
2021-04-02 11:16:15 -04:00
|
|
|
})
|
|
|
|
|
})
|
2021-09-09 18:10:04 +02:00
|
|
|
|
2021-11-29 15:25:43 +01:00
|
|
|
it('should be possible to differentiate between decoration utilities', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
2022-02-10 18:06:41 +01:00
|
|
|
raw: html` <div class="decoration-[#ccc] decoration-[3px]"></div> `,
|
2021-11-29 15:25:43 +01:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.decoration-\[\#ccc\] {
|
|
|
|
|
text-decoration-color: #ccc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.decoration-\[3px\] {
|
|
|
|
|
text-decoration-thickness: 3px;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-11-25 15:07:43 +01:00
|
|
|
it('should support modifiers for arbitrary values that contain the separator', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="hover:bg-[url('https://github.com/tailwindlabs.png')]"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.hover\:bg-\[url\(\'https\:\/\/github\.com\/tailwindlabs\.png\'\)\]:hover {
|
|
|
|
|
background-image: url('https://github.com/tailwindlabs.png');
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-24 18:45:42 +02:00
|
|
|
it('should support arbitrary values for various background utilities', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<!-- Lookup -->
|
|
|
|
|
<div class="bg-gradient-to-r"></div>
|
|
|
|
|
<div class="bg-red-500"></div>
|
|
|
|
|
|
|
|
|
|
<!-- By implicit type -->
|
|
|
|
|
<div class="bg-[url('/image-1-0.png')]"></div>
|
|
|
|
|
<div class="bg-[#ff0000]"></div>
|
2022-04-28 11:18:51 +01:00
|
|
|
<div class="bg-[rgb(var(--bg-color))]"></div>
|
|
|
|
|
<div class="bg-[hsl(var(--bg-color))]"></div>
|
2021-09-24 18:45:42 +02:00
|
|
|
|
|
|
|
|
<!-- By explicit type -->
|
|
|
|
|
<div class="bg-[url:var(--image-url)]"></div>
|
|
|
|
|
<div class="bg-[color:var(--bg-color)]"></div>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.bg-red-500 {
|
|
|
|
|
--tw-bg-opacity: 1;
|
|
|
|
|
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 12:08:48 +02:00
|
|
|
.bg-\[\#ff0000\] {
|
2021-09-24 18:45:42 +02:00
|
|
|
--tw-bg-opacity: 1;
|
|
|
|
|
background-color: rgb(255 0 0 / var(--tw-bg-opacity));
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 11:18:51 +01:00
|
|
|
.bg-\[rgb\(var\(--bg-color\)\)\] {
|
|
|
|
|
background-color: rgb(var(--bg-color));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bg-\[hsl\(var\(--bg-color\)\)\] {
|
|
|
|
|
background-color: hsl(var(--bg-color));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 12:08:48 +02:00
|
|
|
.bg-\[color\:var\(--bg-color\)\] {
|
2021-09-24 18:45:42 +02:00
|
|
|
background-color: var(--bg-color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.bg-gradient-to-r {
|
|
|
|
|
background-image: linear-gradient(to right, var(--tw-gradient-stops));
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 12:08:48 +02:00
|
|
|
.bg-\[url\(\'\/image-1-0\.png\'\)\] {
|
2021-09-24 18:45:42 +02:00
|
|
|
background-image: url('/image-1-0.png');
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 12:08:48 +02:00
|
|
|
.bg-\[url\:var\(--image-url\)\] {
|
2021-09-24 18:45:42 +02:00
|
|
|
background-image: var(--image-url);
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-24 18:18:48 +02:00
|
|
|
it('should not generate any css if an unknown typehint is used', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div class="inset-[hmm:12px]"></div>`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css``)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-24 18:28:08 +02:00
|
|
|
it('should handle unknown typehints', () => {
|
|
|
|
|
let config = { content: [{ raw: html`<div class="w-[length:12px]"></div>` }] }
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
2021-10-18 12:08:48 +02:00
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.w-\[length\:12px\] {
|
2021-09-24 18:28:08 +02:00
|
|
|
width: 12px;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-09 18:10:04 +02:00
|
|
|
it('should convert _ to spaces', () => {
|
2021-10-18 12:08:48 +02:00
|
|
|
// Using custom css function here, because otherwise with String.raw, we run
|
|
|
|
|
// into an issue with `\2c ` escapes. If we use `\2c ` then JS complains
|
|
|
|
|
// about strict mode. But `\\2c ` is not what it expected.
|
|
|
|
|
function css(templates) {
|
|
|
|
|
return templates.join('')
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 18:10:04 +02:00
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="grid-cols-[200px_repeat(auto-fill,minmax(15%,100px))_300px]"></div>
|
|
|
|
|
<div class="grid-rows-[200px_repeat(auto-fill,minmax(15%,100px))_300px]"></div>
|
|
|
|
|
<div class="shadow-[0px_0px_4px_black]"></div>
|
|
|
|
|
<div class="rounded-[0px_4px_4px_0px]"></div>
|
|
|
|
|
<div class="m-[8px_4px]"></div>
|
|
|
|
|
<div class="p-[8px_4px]"></div>
|
|
|
|
|
<div class="flex-[1_1_100%]"></div>
|
|
|
|
|
<div class="col-[span_3_/_span_8]"></div>
|
|
|
|
|
<div class="row-[span_3_/_span_8]"></div>
|
|
|
|
|
<div class="auto-cols-[minmax(0,_1fr)]"></div>
|
|
|
|
|
<div class="drop-shadow-[0px_1px_3px_black]"></div>
|
|
|
|
|
<div class="content-[_hello_world_]"></div>
|
2021-09-24 18:45:42 +02:00
|
|
|
<div class="content-[___abc____]"></div>
|
|
|
|
|
<div class="content-['__hello__world__']"></div>
|
2021-09-09 18:10:04 +02:00
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.col-\\[span_3_\\/_span_8\\] {
|
|
|
|
|
grid-column: span 3 / span 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.row-\\[span_3_\\/_span_8\\] {
|
|
|
|
|
grid-row: span 3 / span 8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.m-\\[8px_4px\\] {
|
|
|
|
|
margin: 8px 4px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.flex-\\[1_1_100\\%\\] {
|
|
|
|
|
flex: 1 1 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.auto-cols-\\[minmax\\(0\\2c _1fr\\)\\] {
|
|
|
|
|
grid-auto-columns: minmax(0, 1fr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.grid-cols-\\[200px_repeat\\(auto-fill\\2c minmax\\(15\\%\\2c 100px\\)\\)_300px\\] {
|
|
|
|
|
grid-template-columns: 200px repeat(auto-fill, minmax(15%, 100px)) 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.grid-rows-\\[200px_repeat\\(auto-fill\\2c minmax\\(15\\%\\2c 100px\\)\\)_300px\\] {
|
|
|
|
|
grid-template-rows: 200px repeat(auto-fill, minmax(15%, 100px)) 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.rounded-\\[0px_4px_4px_0px\\] {
|
|
|
|
|
border-radius: 0px 4px 4px 0px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.p-\\[8px_4px\\] {
|
|
|
|
|
padding: 8px 4px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shadow-\\[0px_0px_4px_black\\] {
|
|
|
|
|
--tw-shadow: 0px 0px 4px black;
|
2021-11-04 10:14:13 -04:00
|
|
|
--tw-shadow-colored: 0px 0px 4px var(--tw-shadow-color);
|
2021-09-09 18:10:04 +02:00
|
|
|
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
|
|
|
|
|
var(--tw-shadow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.drop-shadow-\\[0px_1px_3px_black\\] {
|
|
|
|
|
--tw-drop-shadow: drop-shadow(0px 1px 3px black);
|
2022-01-07 11:39:45 -05:00
|
|
|
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale)
|
|
|
|
|
var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia)
|
|
|
|
|
var(--tw-drop-shadow);
|
2021-09-09 18:10:04 +02:00
|
|
|
}
|
2021-09-24 18:45:42 +02:00
|
|
|
|
2021-09-09 18:10:04 +02:00
|
|
|
.content-\\[_hello_world_\\] {
|
2021-10-18 18:11:34 +02:00
|
|
|
--tw-content: hello world;
|
|
|
|
|
content: var(--tw-content);
|
2021-09-09 18:10:04 +02:00
|
|
|
}
|
2021-09-24 18:45:42 +02:00
|
|
|
|
|
|
|
|
.content-\\[___abc____\\] {
|
2021-10-18 18:11:34 +02:00
|
|
|
--tw-content: abc;
|
|
|
|
|
content: var(--tw-content);
|
2021-09-24 18:45:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.content-\\[\\'__hello__world__\\'\\] {
|
2021-10-18 18:11:34 +02:00
|
|
|
--tw-content: ' hello world ';
|
|
|
|
|
content: var(--tw-content);
|
2021-09-24 18:45:42 +02:00
|
|
|
}
|
2021-09-09 18:10:04 +02:00
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should not convert escaped underscores with spaces', () => {
|
|
|
|
|
let config = {
|
2021-10-18 12:08:48 +02:00
|
|
|
content: [{ raw: `<div class="content-['snake\\_case']"></div>` }],
|
2021-09-09 18:10:04 +02:00
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2021-10-18 12:08:48 +02:00
|
|
|
.content-\[\'snake\\_case\'\] {
|
2021-10-18 18:11:34 +02:00
|
|
|
--tw-content: 'snake_case';
|
|
|
|
|
content: var(--tw-content);
|
2021-09-09 18:10:04 +02:00
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-09-30 12:39:41 +02:00
|
|
|
|
Improve `addVariant` API (#5809)
* fix incorrect comment
Probably messed this up in another PR, so just a bit of cleaning.
* implement a formatVariantSelector function
This will be used to eventually simplify the addVariant API.
The idea is that it can take a list of strings that define a certain
format. Then it squashes everything to a single format how you would
expect it.
E.g.:
Input:
- '&:hover'
- '&:focus'
- '.dark &'
- ':merge(.group):hover &'
- ':merge(.group):focus &'
Output:
- ':merge(.group):focus:hover .dark &:focus:hover'
The API here is:
- `&`, this means "The parent" or "The previous selector" (you can
think of it like if you are using nested selectors)
- `:merge(.group)`, this means insert a `.group` if it doesn't exist
yet, but if it does exist already, then merge the new value with the
old value. This allows us to merge group-focus, group-hover into a
single `.group:focus:hover ...`
* add new `format`, `withRule` and `wrap` API for addVariant
* implement backwards compatibility
This will ensure that the backwards compatibility for `modifySelectors`
and direct mutations to the `container` will still work.
We will try to capture the changes made to the `rule.selector`, we will
also "backup" the existing selector. This allows us to diff the old and
new selectors and determine what actually happened.
Once we know this, we can restore the selector to the "old" selector and
add the diffed string e.g.: `.foo &`, to the `collectedFormats` as if
you called `format()` directly. This is a bunch of extra work, but it
allows us to be backwards compatible.
In the future we could also warn if you are using `modifySelectors`, but
it is going to be a little bit tricky, because usually that's
implemented by plugin authors and therefore you don't have direct
control over this. Maybe we can figure out the plugin this is used in
and change the warning somehow?
* fix incorrect test
This was clearly a bug, keyframes should not include escaped variants at
all. The reason this is here in the first place is because the nodes in
a keyframe are also "rule" nodes.
* swap the order of pseudo states
The current implementation had a strange side effect, that resulted in
incorrect class definitions. When you are combining the `:hover` and
`:focus` event, then there is no difference between `:hover:focus` and
`:focus:hover`.
However, when you use `:hover::file-selector-button` or `::file-selector-button:hover`,
then there is a big difference. In the first place, you can hover over the full file input
to apply changes to the `File selector button`.
In the second scenario you have to hover over the `File selector button` itself to apply changes.
You can think of it as function calls:
- focus(hover(text-center))
What you would expect is something like this:
`.focus\:hover\:text-center:hover:focus`, where `hover` is on the
inside, and `focus` is on the outside. However in the current
implementation this is implemented as
`.focus\:hover\:text-cener:focus:hover`
* add more variant tests for the new API
* update parallel variants tests to make use of new API
* implement core variants with new API
* simplify/cleanup existing plugin utils
We can get rid of this because we drastically simplified the new
addVariant API.
* add addVariant shorthand signature
The current API looks like this:
```js
addVariant('name', ({ format, wrap }) => {
// Wrap in an atRule
wrap(postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' }))
// "Mutate" the selector, for example prepend `.dark`
format('.dark &')
})
```
It is also pretty common to have this:
```js
addVariant('name', ({ format }) => format('.dark &'))
```
So we simplified this to:
```js
addVariant('name', '.dark &')
```
It is also pretty common to have this:
```js
addVariant('name', ({ wrap }) => wrap(postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' })))
```
So we simplified this to:
```js
addVariant('name', '@media (prefers-reduced-motion: reduce)')
```
* improve fontVariantNumeric implementation
We will use `@defaults`, so that only the resets are injected for the
utilities we actually use.
* fix typo
* allow for nested addVariant shorthand
This will allow to write something like:
```js
addVariant('name', `
@supports (hover: hover) {
@media (print) {
&:hover
}
}
`)
// Or as a one-liner
addVariant('name', '@supports (hover: hover) { @media (print) { &:hover } }')
```
* update changelog
2021-10-18 11:26:11 +02:00
|
|
|
it('should warn and not generate if arbitrary values are ambiguous', () => {
|
2021-09-30 12:39:41 +02:00
|
|
|
// If we don't protect against this, then `bg-[200px_100px]` would both
|
|
|
|
|
// generate the background-size as well as the background-position utilities.
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="bg-[200px_100px]"></div>` }],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css``)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-10-22 14:43:46 +02:00
|
|
|
|
|
|
|
|
it('should support colons in URLs', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{ raw: html`<div class="bg-[url('https://www.spacejam.com/1996/img/bg_stars.gif')]"></div>` },
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.bg-\[url\(\'https\:\/\/www\.spacejam\.com\/1996\/img\/bg_stars\.gif\'\)\] {
|
|
|
|
|
background-image: url('https://www.spacejam.com/1996/img/bg_stars.gif');
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should support unescaped underscores in URLs', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{ raw: html`<div class="bg-[url('brown_potato.jpg'),_url('red_tomato.png')]"></div>` },
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(`
|
|
|
|
|
.bg-\\[url\\(\\'brown_potato\\.jpg\\'\\)\\2c _url\\(\\'red_tomato\\.png\\'\\)\\] {
|
|
|
|
|
background-image: url('brown_potato.jpg'), url('red_tomato.png');
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-01-03 11:29:18 +01:00
|
|
|
|
|
|
|
|
it('should be possible to read theme values in arbitrary values (without quotes)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="w-[theme(spacing.1)] w-[theme(spacing[0.5])]"></div>` }],
|
|
|
|
|
theme: {
|
|
|
|
|
spacing: {
|
|
|
|
|
0.5: 'calc(.5 * .25rem)',
|
|
|
|
|
1: 'calc(1 * .25rem)',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.w-\[theme\(spacing\.1\)\] {
|
|
|
|
|
width: calc(1 * 0.25rem);
|
|
|
|
|
}
|
|
|
|
|
.w-\[theme\(spacing\[0\.5\]\)\] {
|
|
|
|
|
width: calc(0.5 * 0.25rem);
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should be possible to read theme values in arbitrary values (with quotes)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="w-[theme('spacing.1')] w-[theme('spacing[0.5]')]"></div>` }],
|
|
|
|
|
theme: {
|
|
|
|
|
spacing: {
|
|
|
|
|
0.5: 'calc(.5 * .25rem)',
|
|
|
|
|
1: 'calc(1 * .25rem)',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.w-\[theme\(\'spacing\.1\'\)\] {
|
|
|
|
|
width: calc(1 * 0.25rem);
|
|
|
|
|
}
|
|
|
|
|
.w-\[theme\(\'spacing\[0\.5\]\'\)\] {
|
|
|
|
|
width: calc(0.5 * 0.25rem);
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-02-14 15:44:27 -05:00
|
|
|
|
|
|
|
|
it('should be possible to read theme values in arbitrary values (with quotes) when inside calc or similar functions', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div
|
|
|
|
|
class="w-[calc(100%-theme('spacing.1'))] w-[calc(100%-theme('spacing[0.5]'))]"
|
|
|
|
|
></div>`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
theme: {
|
|
|
|
|
spacing: {
|
|
|
|
|
0.5: 'calc(.5 * .25rem)',
|
|
|
|
|
1: 'calc(1 * .25rem)',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.w-\[calc\(100\%-theme\(\'spacing\.1\'\)\)\] {
|
|
|
|
|
width: calc(100% - calc(1 * 0.25rem));
|
|
|
|
|
}
|
|
|
|
|
.w-\[calc\(100\%-theme\(\'spacing\[0\.5\]\'\)\)\] {
|
|
|
|
|
width: calc(100% - calc(0.5 * 0.25rem));
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-03-08 12:43:06 -05:00
|
|
|
|
|
|
|
|
it('should not output unparsable arbitrary CSS values', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: 'let classes = `w-[${sizes.width}]`',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(``)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-04-01 12:37:22 +02:00
|
|
|
|
|
|
|
|
// Issue: https://github.com/tailwindlabs/tailwindcss/issues/7997
|
|
|
|
|
// `top_right_50%` was a valid percentage before introducing this change
|
|
|
|
|
it('should correctly validate each part when checking for `percentage` data types', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="bg-[top_right_50%]"></div>` }],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
plugins: [],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.bg-\[top_right_50\%\] {
|
|
|
|
|
background-position: top right 50%;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|