2021-04-30 16:58:40 +02:00
|
|
|
import fs from 'fs'
|
|
|
|
|
import path from 'path'
|
2022-02-25 14:52:20 -05:00
|
|
|
import postcss from 'postcss'
|
2023-01-20 12:45:04 -05:00
|
|
|
import { crosscheck, run, html, css, defaults } from './util/run'
|
2021-04-02 11:16:15 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
crosscheck(({ stable, oxide }) => {
|
|
|
|
|
test('variants', () => {
|
|
|
|
|
let config = {
|
2024-01-05 14:39:34 -05:00
|
|
|
darkMode: 'selector',
|
2023-01-20 12:45:04 -05:00
|
|
|
content: [path.resolve(__dirname, './variants.test.html')],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind base;
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
stable
|
|
|
|
|
.expect(result.css)
|
|
|
|
|
.toMatchFormattedCss(
|
|
|
|
|
fs.readFileSync(path.resolve(__dirname, './variants.test.css'), 'utf8')
|
|
|
|
|
)
|
|
|
|
|
oxide
|
|
|
|
|
.expect(result.css)
|
|
|
|
|
.toMatchFormattedCss(
|
|
|
|
|
fs.readFileSync(path.resolve(__dirname, './variants.oxide.test.css'), 'utf8')
|
|
|
|
|
)
|
|
|
|
|
})
|
2021-04-02 11:16:15 -04:00
|
|
|
})
|
2021-06-23 02:40:52 +02:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('order matters and produces different behaviour', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
2024-02-13 14:08:43 -05:00
|
|
|
<div class="hover:file:[--value:1]"></div>
|
|
|
|
|
<div class="file:hover:[--value:2]"></div>
|
2023-01-20 12:45:04 -05:00
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
2023-02-17 20:21:22 +01:00
|
|
|
stable.expect(result.css).toMatchFormattedCss(css`
|
2024-02-13 14:08:43 -05:00
|
|
|
.hover\:file\:\[--value\:1\]::-webkit-file-upload-button:hover {
|
|
|
|
|
--value: 1;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
2024-02-13 14:08:43 -05:00
|
|
|
.hover\:file\:\[--value\:1\]::file-selector-button:hover {
|
|
|
|
|
--value: 1;
|
|
|
|
|
}
|
|
|
|
|
.file\:hover\:\[--value\:2\]:hover::-webkit-file-upload-button {
|
|
|
|
|
--value: 2;
|
|
|
|
|
}
|
|
|
|
|
.file\:hover\:\[--value\:2\]:hover::file-selector-button {
|
|
|
|
|
--value: 2;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
`)
|
2023-02-17 20:21:22 +01:00
|
|
|
oxide.expect(result.css).toMatchFormattedCss(css`
|
2024-02-13 14:08:43 -05:00
|
|
|
.hover\:file\:\[--value\:1\]::-webkit-file-upload-button:hover {
|
|
|
|
|
--value: 1;
|
|
|
|
|
}
|
|
|
|
|
.hover\:file\:\[--value\:1\]::file-selector-button:hover {
|
|
|
|
|
--value: 1;
|
|
|
|
|
}
|
|
|
|
|
.file\:hover\:\[--value\:2\]:hover::-webkit-file-upload-button {
|
|
|
|
|
--value: 2;
|
2023-02-17 20:21:22 +01:00
|
|
|
}
|
2024-02-13 14:08:43 -05:00
|
|
|
.file\:hover\:\[--value\:2\]:hover::file-selector-button {
|
|
|
|
|
--value: 2;
|
2023-02-17 20:21:22 +01:00
|
|
|
}
|
|
|
|
|
`)
|
2023-01-20 12:45:04 -05:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('custom advanced variants', () => {
|
2023-07-11 16:04:38 -04:00
|
|
|
test('at-rules without params', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="ogre:text-center"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('ogre', '@layer')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components; @tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@layer {
|
|
|
|
|
.ogre\:text-center {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('prose-headings usage on its own', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="prose-headings:text-center"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('prose-headings', ':where(&) :is(h1, h2, h3, h4)')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
:where(.prose-headings\:text-center) :is(h1, h2, h3, h4) {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('prose-headings with another "simple" variant', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="hover:prose-headings:text-center"></div>
|
|
|
|
|
<div class="prose-headings:hover:text-center"></div>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('prose-headings', ':where(&) :is(h1, h2, h3, h4)')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
:where(.hover\:prose-headings\:text-center) :is(h1, h2, h3, h4):hover,
|
2023-01-20 12:45:04 -05:00
|
|
|
:where(.prose-headings\:hover\:text-center:hover) :is(h1, h2, h3, h4) {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('prose-headings with another "complex" variant', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="group-hover:prose-headings:text-center"></div>
|
|
|
|
|
<div class="prose-headings:group-hover:text-center"></div>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('prose-headings', ':where(&) :is(h1, h2, h3, h4)')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
.group:hover :where(.group-hover\:prose-headings\:text-center) :is(h1, h2, h3, h4),
|
2023-01-20 12:45:04 -05:00
|
|
|
:where(.group:hover .prose-headings\:group-hover\:text-center) :is(h1, h2, h3, h4) {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('using variants with multi-class selectors', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="screen:parent screen:child"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant, addComponents }) {
|
|
|
|
|
addComponents({
|
|
|
|
|
'.parent .child': {
|
|
|
|
|
foo: 'bar',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
addVariant('screen', '@media screen')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media screen {
|
2023-01-31 15:37:49 +01:00
|
|
|
.screen\:parent .child,
|
2023-01-20 12:45:04 -05:00
|
|
|
.parent .screen\:child {
|
|
|
|
|
foo: bar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('using multiple classNames in your custom variant', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="my-variant:underline test"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('my-variant', '&:where(.one, .two, .three)')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
|
|
|
|
|
@layer components {
|
|
|
|
|
.test {
|
|
|
|
|
@apply my-variant:italic;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.test:where(.one, .two, .three) {
|
|
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
.my-variant\:underline:where(.one, .two, .three) {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('variant format string must include at-rule or & (1)', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="wtf-bbq:text-center"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('wtf-bbq', 'lol')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await expect(run('@tailwind components;@tailwind utilities', config)).rejects.toThrowError(
|
|
|
|
|
"Your custom variant `wtf-bbq` has an invalid format string. Make sure it's an at-rule or contains a `&` placeholder."
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('variant format string must include at-rule or & (2)', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="wtf-bbq:text-center"></div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
|
|
|
|
addVariant('wtf-bbq', () => 'lol')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await expect(run('@tailwind components;@tailwind utilities', config)).rejects.toThrowError(
|
|
|
|
|
"Your custom variant `wtf-bbq` has an invalid format string. Make sure it's an at-rule or contains a `&` placeholder."
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('stacked peer variants', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: 'peer-disabled:peer-focus:peer-hover:border-blue-500' }],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind base;
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
2023-02-17 20:21:22 +01:00
|
|
|
let result = await run(input, config)
|
|
|
|
|
stable.expect(result.css).toIncludeCss(css`
|
2023-01-20 12:45:04 -05:00
|
|
|
.peer:disabled:focus:hover ~ .peer-disabled\:peer-focus\:peer-hover\:border-blue-500 {
|
|
|
|
|
--tw-border-opacity: 1;
|
|
|
|
|
border-color: rgb(59 130 246 / var(--tw-border-opacity));
|
|
|
|
|
}
|
2023-02-17 20:21:22 +01:00
|
|
|
`)
|
|
|
|
|
oxide.expect(result.css).toIncludeCss(css`
|
|
|
|
|
.peer:disabled:focus:hover ~ .peer-disabled\:peer-focus\:peer-hover\:border-blue-500 {
|
|
|
|
|
border-color: #3b82f6;
|
|
|
|
|
}
|
|
|
|
|
`)
|
2023-01-20 12:45:04 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should properly handle keyframes with multiple variants', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: 'animate-spin hover:animate-spin focus:animate-spin hover:animate-bounce focus:animate-bounce',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
let result = await run(input, config)
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@keyframes spin {
|
|
|
|
|
to {
|
|
|
|
|
transform: rotate(360deg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.animate-spin {
|
2023-01-31 15:37:49 +01:00
|
|
|
animation: 1s linear infinite spin;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
@keyframes bounce {
|
|
|
|
|
0%,
|
|
|
|
|
100% {
|
|
|
|
|
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
|
2023-01-31 15:37:49 +01:00
|
|
|
transform: translateY(-25%);
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
50% {
|
|
|
|
|
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
|
2023-01-31 15:37:49 +01:00
|
|
|
transform: none;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.hover\:animate-bounce:hover {
|
2023-01-31 15:37:49 +01:00
|
|
|
animation: 1s infinite bounce;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
.hover\:animate-spin:hover {
|
2023-01-31 15:37:49 +01:00
|
|
|
animation: 1s linear infinite spin;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
.focus\:animate-bounce:focus {
|
2023-01-31 15:37:49 +01:00
|
|
|
animation: 1s infinite bounce;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
.focus\:animate-spin:focus {
|
2023-01-31 15:37:49 +01:00
|
|
|
animation: 1s linear infinite spin;
|
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
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('custom addVariant with more complex media query params', () => {
|
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
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
2023-01-20 12:45:04 -05:00
|
|
|
raw: html` <div class="magic:text-center"></div> `,
|
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
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
2023-01-20 12:45:04 -05:00
|
|
|
addVariant('magic', '@media screen and (max-width: 600px)')
|
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
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-20 12:45:04 -05:00
|
|
|
@media screen and (max-width: 600px) {
|
|
|
|
|
.magic\:text-center {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('custom addVariant with nested media & format shorthand', () => {
|
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
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
2023-01-20 12:45:04 -05:00
|
|
|
raw: html` <div class="magic:text-center"></div> `,
|
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
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
2023-01-20 12:45:04 -05:00
|
|
|
addVariant('magic', '@supports (hover: hover) { @media print { &:disabled } }')
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@supports (hover: hover) {
|
|
|
|
|
@media print {
|
|
|
|
|
.magic\:text-center:disabled {
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('before and after variants are a bit special, and forced to the end', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="before:hover:text-center"></div>
|
|
|
|
|
<div class="hover:before:text-center"></div>
|
|
|
|
|
`,
|
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
|
|
|
},
|
|
|
|
|
],
|
2023-01-20 12:45:04 -05:00
|
|
|
plugins: [],
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
.before\:hover\:text-center:hover:before,
|
|
|
|
|
.hover\:before\:text-center:hover:before {
|
2023-01-20 12:45:04 -05:00
|
|
|
content: var(--tw-content);
|
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
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('before and after variants are a bit special, and forced to the end (2)', () => {
|
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
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
2023-01-20 12:45:04 -05:00
|
|
|
<div class="before:prose-headings:text-center"></div>
|
|
|
|
|
<div class="prose-headings:before:text-center"></div>
|
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
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addVariant }) {
|
2021-10-18 18:11:34 +02:00
|
|
|
addVariant('prose-headings', ':where(&) :is(h1, h2, h3, h4)')
|
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
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
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
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
:where(.before\:prose-headings\:text-center) :is(h1, h2, h3, h4):before,
|
|
|
|
|
:where(.prose-headings\:before\:text-center) :is(h1, h2, h3, h4):before {
|
2023-01-20 12:45:04 -05:00
|
|
|
content: var(--tw-content);
|
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
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-11-06 07:25:32 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('returning non-strings and non-selectors in addVariant', () => {
|
|
|
|
|
/** @type {import('../types/config').Config} */
|
2021-11-06 07:25:32 -04:00
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
2023-01-20 12:45:04 -05:00
|
|
|
raw: html`
|
|
|
|
|
<div class="peer-aria-expanded:text-center"></div>
|
|
|
|
|
<div class="peer-aria-expanded-2:text-center"></div>
|
|
|
|
|
`,
|
2021-11-06 07:25:32 -04:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
plugins: [
|
2023-01-20 12:45:04 -05:00
|
|
|
function ({ addVariant, e }) {
|
|
|
|
|
addVariant('peer-aria-expanded', ({ modifySelectors, separator }) =>
|
|
|
|
|
// Returning anything other string | string[] | undefined here is not supported
|
|
|
|
|
// But we're trying to be lenient here and just throw it out
|
|
|
|
|
modifySelectors(
|
|
|
|
|
({ className }) =>
|
|
|
|
|
`.peer[aria-expanded="true"] ~ .${e(`peer-aria-expanded${separator}${className}`)}`
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
addVariant('peer-aria-expanded-2', ({ modifySelectors, separator }) => {
|
|
|
|
|
let nodes = modifySelectors(
|
|
|
|
|
({ className }) => `.${e(`peer-aria-expanded-2${separator}${className}`)}`
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
// Returning anything other than strings here is not supported
|
|
|
|
|
// But we're trying to be lenient here and just throw it out
|
|
|
|
|
nodes,
|
|
|
|
|
'.peer[aria-expanded="false"] ~ &',
|
|
|
|
|
]
|
2021-11-06 07:25:32 -04:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind components;@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
.peer[aria-expanded='true'] ~ .peer-aria-expanded\:text-center,
|
2023-01-20 12:45:04 -05:00
|
|
|
.peer[aria-expanded='false'] ~ .peer-aria-expanded-2\:text-center {
|
|
|
|
|
text-align: center;
|
2021-11-06 07:25:32 -04:00
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-12-10 10:57:40 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('should not generate variants of user css if it is not inside a layer', () => {
|
2021-12-10 10:57:40 +01:00
|
|
|
let config = {
|
2023-01-20 12:45:04 -05:00
|
|
|
content: [{ raw: html`<div class="hover:foo"></div>` }],
|
|
|
|
|
plugins: [],
|
2021-12-10 10:57:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
.foo {
|
|
|
|
|
color: red;
|
2021-12-10 10:57:40 +01:00
|
|
|
}
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2023-01-20 12:45:04 -05:00
|
|
|
.foo {
|
|
|
|
|
color: red;
|
2021-12-10 10:57:40 +01:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-12-10 10:57:40 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('should be possible to use responsive modifiers that are defined with special characters', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="<sm:underline"></div>` }],
|
|
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
'<sm': { max: '399px' },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
plugins: [],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (max-width: 399px) {
|
|
|
|
|
.\<sm\:underline {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
2021-12-10 10:57:40 +01:00
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-05-14 13:58:02 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('including just the base layer should not produce variants', () => {
|
2022-05-14 13:58:02 -04:00
|
|
|
let config = {
|
2023-01-20 12:45:04 -05:00
|
|
|
content: [{ raw: html`<div class="sm:container sm:underline"></div>` }],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind base', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(
|
|
|
|
|
css`
|
|
|
|
|
${defaults}
|
|
|
|
|
`
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('variants for components should not be produced in a file without a components layer', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="sm:container sm:underline"></div>` }],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:underline {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('variants for utilities should not be produced in a file without a utilities layer', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="sm:container sm:underline"></div>` }],
|
2022-05-14 13:58:02 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run('@tailwind components', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
max-width: 640px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 768px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
max-width: 768px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 1024px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
max-width: 1024px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 1280px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
max-width: 1280px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 1536px) {
|
|
|
|
|
.sm\:container {
|
|
|
|
|
max-width: 1536px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-05-14 13:58:02 -04:00
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('The visited variant removes opacity support', () => {
|
2022-05-14 13:58:02 -04:00
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
2023-01-20 12:45:04 -05:00
|
|
|
raw: html`
|
|
|
|
|
<a class="visited:border-red-500 visited:bg-red-500 visited:text-red-500"
|
|
|
|
|
>Look, it's a link!</a
|
|
|
|
|
>
|
|
|
|
|
`,
|
2022-05-14 13:58:02 -04:00
|
|
|
},
|
|
|
|
|
],
|
2023-01-20 12:45:04 -05:00
|
|
|
plugins: [],
|
2022-05-14 13:58:02 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run('@tailwind utilities', config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.visited\:border-red-500:visited {
|
2023-01-31 15:37:49 +01:00
|
|
|
border-color: #ef4444;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
.visited\:bg-red-500:visited {
|
2023-01-31 15:37:49 +01:00
|
|
|
background-color: #ef4444;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
.visited\:text-red-500:visited {
|
2023-01-31 15:37:49 +01:00
|
|
|
color: #ef4444;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-05-14 13:58:02 -04: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
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('appends variants to the correct place when using postcss documents', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="underline sm:underline"></div>` }],
|
|
|
|
|
plugins: [],
|
|
|
|
|
corePlugins: { preflight: false },
|
2021-06-23 02:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
const doc = postcss.document()
|
|
|
|
|
doc.append(postcss.parse(`a {}`))
|
|
|
|
|
doc.append(postcss.parse(`@tailwind base`))
|
|
|
|
|
doc.append(postcss.parse(`@tailwind utilities`))
|
|
|
|
|
doc.append(postcss.parse(`b {}`))
|
2021-10-01 17:31:09 +02:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
const result = doc.toResult()
|
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
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(result, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
${defaults}
|
|
|
|
|
.underline {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:underline {
|
|
|
|
|
text-decoration-line: underline;
|
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
|
|
|
}
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05: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
|
|
|
})
|
2021-11-12 16:38:03 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('variants support multiple, grouped selectors (html)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="sm:base1 sm:base2"></div>` }],
|
|
|
|
|
plugins: [],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
2021-11-12 16:38:03 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
.base1 .foo,
|
|
|
|
|
.base1 .bar {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2021-11-12 16:38:03 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
.base2 .bar .base2-foo {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2021-11-12 16:38:03 +01:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`
|
2021-12-17 14:49:07 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:base1 .foo,
|
2023-01-31 15:37:49 +01:00
|
|
|
.sm\:base1 .bar,
|
2023-01-20 12:45:04 -05:00
|
|
|
.sm\:base2 .bar .base2-foo {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-06-12 10:50:41 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('variants support multiple, grouped selectors (apply)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="baz"></div>` }],
|
|
|
|
|
plugins: [],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
2022-06-12 10:50:41 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
.base .foo,
|
|
|
|
|
.base .bar {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2022-06-12 10:50:41 -04:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
.baz {
|
|
|
|
|
@apply sm:base;
|
2022-06-12 10:50:41 -04:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`
|
2021-12-17 14:49:07 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.baz .foo,
|
|
|
|
|
.baz .bar {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-12-17 14:49:07 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('variants only picks the used selectors in a group (html)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="sm:b"></div>` }],
|
|
|
|
|
plugins: [],
|
|
|
|
|
corePlugins: { preflight: false },
|
2021-12-17 14:49:07 +01:00
|
|
|
}
|
2022-01-03 11:17:58 +01:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
.a,
|
|
|
|
|
.b {
|
|
|
|
|
color: red;
|
2022-01-03 11:17:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`
|
2022-01-14 10:20:43 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
.sm\:b {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-01-14 10:20:43 -05:00
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
it('variants only picks the used selectors in a group (apply)', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="baz"></div>` }],
|
|
|
|
|
plugins: [],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
2022-01-14 10:20:43 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
.a,
|
|
|
|
|
.b {
|
|
|
|
|
color: red;
|
2022-01-14 10:20:43 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
.baz {
|
|
|
|
|
@apply sm:b;
|
|
|
|
|
}
|
|
|
|
|
`
|
2022-01-14 10:20:43 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
return expect(result.css).toMatchFormattedCss(css`
|
2022-01-14 10:20:43 -05:00
|
|
|
@media (min-width: 640px) {
|
2023-01-20 12:45:04 -05:00
|
|
|
.baz {
|
|
|
|
|
color: red;
|
2022-01-14 10:20:43 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`)
|
|
|
|
|
})
|
2022-01-14 10:20:43 -05:00
|
|
|
})
|
2022-02-14 13:24:18 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('hoverOnlyWhenSupported adds hover and pointer media features by default', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
future: {
|
|
|
|
|
hoverOnlyWhenSupported: true,
|
2022-02-14 13:24:18 -05:00
|
|
|
},
|
2023-01-20 12:45:04 -05:00
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div class="hover:underline group-hover:underline peer-hover:underline"></div>`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
2022-02-25 14:52:20 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind base;
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
2022-02-25 14:52:20 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
${defaults}
|
|
|
|
|
@media (hover: hover) and (pointer: fine) {
|
2023-01-31 15:37:49 +01:00
|
|
|
.hover\:underline:hover,
|
|
|
|
|
.group:hover .group-hover\:underline,
|
2023-01-20 12:45:04 -05:00
|
|
|
.peer:hover ~ .peer-hover\:underline {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
2022-02-25 14:52:20 -05:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`)
|
|
|
|
|
})
|
2022-02-25 14:52:20 -05:00
|
|
|
})
|
2022-05-03 13:10:27 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('multi-class utilities handle selector-mutating variants correctly', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div
|
|
|
|
|
class="after:foo after:bar after:baz hover:foo hover:bar hover:baz group-hover:foo group-hover:bar group-hover:baz peer-checked:foo peer-checked:bar peer-checked:baz"
|
|
|
|
|
></div>`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div
|
|
|
|
|
class="after:foo1 after:bar1 after:baz1 hover:foo1 hover:bar1 hover:baz1 group-hover:foo1 group-hover:bar1 group-hover:baz1 peer-checked:foo1 peer-checked:bar1 peer-checked:baz1"
|
|
|
|
|
></div>`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
2022-05-03 13:10:27 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
.foo.bar.baz {
|
2022-05-03 13:10:27 -04:00
|
|
|
color: red;
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
.foo1 .bar1 .baz1 {
|
2022-05-03 13:10:27 -04:00
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`
|
2022-05-03 13:10:27 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
// The second set of ::after cases (w/ descendant selectors)
|
|
|
|
|
// are clearly "wrong" BUT you can't have a descendant of a
|
|
|
|
|
// pseudo - element so the utilities `after:foo1` and
|
|
|
|
|
// `after:bar1` are non-sensical so this is still
|
|
|
|
|
// perfectly fine behavior
|
2022-05-03 13:10:27 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
.after\:foo.bar.baz:after,
|
|
|
|
|
.after\:bar.foo.baz:after,
|
|
|
|
|
.after\:baz.foo.bar:after,
|
|
|
|
|
.after\:foo1 .bar1 .baz1:after,
|
|
|
|
|
.foo1 .after\:bar1 .baz1:after,
|
|
|
|
|
.foo1 .bar1 .after\:baz1:after {
|
2023-01-20 12:45:04 -05:00
|
|
|
content: var(--tw-content);
|
|
|
|
|
color: red;
|
2022-05-20 11:20:20 -04:00
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
.hover\:foo:hover.bar.baz,
|
|
|
|
|
.hover\:bar:hover.foo.baz,
|
|
|
|
|
.hover\:baz:hover.foo.bar,
|
|
|
|
|
.hover\:foo1:hover .bar1 .baz1,
|
|
|
|
|
.foo1 .hover\:bar1:hover .baz1,
|
|
|
|
|
.foo1 .bar1 .hover\:baz1:hover,
|
|
|
|
|
.group:hover .group-hover\:foo.bar.baz,
|
|
|
|
|
.group:hover .group-hover\:bar.foo.baz,
|
|
|
|
|
.group:hover .group-hover\:baz.foo.bar,
|
|
|
|
|
.group:hover .group-hover\:foo1 .bar1 .baz1,
|
|
|
|
|
.foo1 .group:hover .group-hover\:bar1 .baz1,
|
|
|
|
|
.foo1 .bar1 .group:hover .group-hover\:baz1,
|
|
|
|
|
.peer:checked ~ .peer-checked\:foo.bar.baz,
|
|
|
|
|
.peer:checked ~ .peer-checked\:bar.foo.baz,
|
|
|
|
|
.peer:checked ~ .peer-checked\:baz.foo.bar,
|
|
|
|
|
.peer:checked ~ .peer-checked\:foo1 .bar1 .baz1,
|
|
|
|
|
.foo1 .peer:checked ~ .peer-checked\:bar1 .baz1,
|
2023-01-20 12:45:04 -05:00
|
|
|
.foo1 .bar1 .peer:checked ~ .peer-checked\:baz1 {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-05-20 11:20:20 -04:00
|
|
|
})
|
2022-09-06 12:58:38 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('class inside pseudo-class function :has', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{ raw: html`<div class="foo hover:foo sm:foo"></div>` },
|
|
|
|
|
{ raw: html`<div class="bar hover:bar sm:bar"></div>` },
|
|
|
|
|
{ raw: html`<div class="baz hover:baz sm:baz"></div>` },
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
2022-09-06 12:58:38 -04:00
|
|
|
}
|
2022-09-12 15:08:31 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
@layer utilities {
|
|
|
|
|
:where(.foo) {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
:is(.foo, .bar, .baz) {
|
2023-01-20 12:45:04 -05:00
|
|
|
color: orange;
|
|
|
|
|
}
|
|
|
|
|
:is(.foo) {
|
|
|
|
|
color: yellow;
|
|
|
|
|
}
|
|
|
|
|
html:has(.foo) {
|
|
|
|
|
color: green;
|
|
|
|
|
}
|
2022-09-12 15:08:31 -04:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`
|
2022-09-12 15:08:31 -04:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
:where(.foo) {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
:is(.foo, .bar, .baz) {
|
2023-01-20 12:45:04 -05:00
|
|
|
color: orange;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
.foo {
|
|
|
|
|
color: #ff0;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
html:has(.foo) {
|
|
|
|
|
color: green;
|
|
|
|
|
}
|
|
|
|
|
:where(.hover\:foo:hover) {
|
2022-09-12 15:08:31 -04:00
|
|
|
color: red;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
:is(.hover\:foo:hover, .bar, .baz),
|
|
|
|
|
:is(.foo, .hover\:bar:hover, .baz),
|
|
|
|
|
:is(.foo, .bar, .hover\:baz:hover) {
|
2022-09-12 15:08:31 -04:00
|
|
|
color: orange;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
.hover\:foo:hover {
|
|
|
|
|
color: #ff0;
|
2022-09-12 15:08:31 -04:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
html:has(.hover\:foo:hover) {
|
2022-09-12 15:08:31 -04:00
|
|
|
color: green;
|
|
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
@media (min-width: 640px) {
|
|
|
|
|
:where(.sm\:foo) {
|
|
|
|
|
color: red;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
:is(.sm\:foo, .bar, .baz),
|
|
|
|
|
:is(.foo, .sm\:bar, .baz),
|
|
|
|
|
:is(.foo, .bar, .sm\:baz) {
|
2023-01-20 12:45:04 -05:00
|
|
|
color: orange;
|
|
|
|
|
}
|
2023-01-31 15:37:49 +01:00
|
|
|
.sm\:foo {
|
|
|
|
|
color: #ff0;
|
2023-01-20 12:45:04 -05:00
|
|
|
}
|
|
|
|
|
html:has(.sm\:foo) {
|
|
|
|
|
color: green;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-09-12 15:08:31 -04:00
|
|
|
})
|
2022-10-24 23:44:32 +08:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('variant functions returning arrays should output correct results when nesting', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [{ raw: html`<div class="test:foo" />` }],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ addUtilities, addVariant }) {
|
|
|
|
|
addVariant('test', () => ['@media (test)'])
|
|
|
|
|
addUtilities({
|
|
|
|
|
'.foo': {
|
|
|
|
|
display: 'grid',
|
|
|
|
|
'> *': {
|
|
|
|
|
'grid-column': 'span 2',
|
|
|
|
|
},
|
2022-10-24 23:44:32 +08:00
|
|
|
},
|
2023-01-20 12:45:04 -05:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
],
|
2022-10-24 23:44:32 +08:00
|
|
|
}
|
2022-12-02 12:18:23 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
2023-01-16 14:41:34 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let result = await run(input, config)
|
2023-01-16 14:41:34 -05:00
|
|
|
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
2023-01-20 12:45:04 -05:00
|
|
|
@media (test) {
|
|
|
|
|
.test\:foo {
|
|
|
|
|
display: grid;
|
|
|
|
|
}
|
|
|
|
|
.test\:foo > * {
|
|
|
|
|
grid-column: span 2;
|
2023-01-16 14:41:34 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
|
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('variants with slashes in them work', () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="ar-1/10:text-red-500">ar-1/10</div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
theme: {
|
|
|
|
|
extend: {
|
|
|
|
|
screens: {
|
|
|
|
|
'ar-1/10': { raw: '(min-aspect-ratio: 1/10)' },
|
2023-01-16 14:41:34 -05:00
|
|
|
},
|
2023-01-20 12:45:04 -05:00
|
|
|
},
|
2023-01-16 14:41:34 -05:00
|
|
|
},
|
2023-01-20 12:45:04 -05:00
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
2023-01-16 14:41:34 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
2023-01-16 14:41:34 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
2023-02-17 20:21:22 +01:00
|
|
|
stable.expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
@media (min-aspect-ratio: 1 / 10) {
|
2023-01-20 12:45:04 -05:00
|
|
|
.ar-1\/10\:text-red-500 {
|
|
|
|
|
--tw-text-opacity: 1;
|
|
|
|
|
color: rgb(239 68 68 / var(--tw-text-opacity));
|
|
|
|
|
}
|
2023-01-16 14:41:34 -05:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
`)
|
2023-02-17 20:21:22 +01:00
|
|
|
oxide.expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-aspect-ratio: 1 / 10) {
|
|
|
|
|
.ar-1\/10\:text-red-500 {
|
|
|
|
|
color: #ef4444;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
2023-01-20 12:45:04 -05:00
|
|
|
})
|
2023-01-16 14:41:34 -05:00
|
|
|
})
|
|
|
|
|
|
2023-03-10 22:44:25 +01:00
|
|
|
test('variants with slashes support modifiers', () => {
|
2023-01-20 12:45:04 -05:00
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html` <div class="ar-1/10/20:text-red-500">ar-1/10</div> `,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
plugins: [
|
|
|
|
|
function ({ matchVariant }) {
|
|
|
|
|
matchVariant(
|
|
|
|
|
'ar',
|
|
|
|
|
(value, { modifier }) => {
|
|
|
|
|
return [`@media (min-aspect-ratio: ${value}) and (foo: ${modifier})`]
|
|
|
|
|
},
|
|
|
|
|
{ values: { '1/10': '1/10' } }
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
2022-12-02 12:18:23 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
2022-12-02 12:18:23 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
return run(input, config).then((result) => {
|
2023-02-17 20:21:22 +01:00
|
|
|
stable.expect(result.css).toMatchFormattedCss(css`
|
2023-01-31 15:37:49 +01:00
|
|
|
@media (min-aspect-ratio: 1 / 10) and (foo: 20) {
|
2023-01-20 12:45:04 -05:00
|
|
|
.ar-1\/10\/20\:text-red-500 {
|
|
|
|
|
--tw-text-opacity: 1;
|
|
|
|
|
color: rgb(239 68 68 / var(--tw-text-opacity));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
2023-02-17 20:21:22 +01:00
|
|
|
oxide.expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
@media (min-aspect-ratio: 1 / 10) and (foo: 20) {
|
|
|
|
|
.ar-1\/10\/20\:text-red-500 {
|
|
|
|
|
color: #ef4444;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`)
|
2023-01-20 12:45:04 -05:00
|
|
|
})
|
|
|
|
|
})
|
2022-12-02 12:18:23 -05:00
|
|
|
|
2023-01-20 12:45:04 -05:00
|
|
|
test('arbitrary variant selectors should not re-order scrollbar pseudo classes', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="[&::-webkit-scrollbar:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-scrollbar-button:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-scrollbar-thumb:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-scrollbar-track:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-scrollbar-track-piece:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-scrollbar-corner:hover]:underline" />
|
|
|
|
|
<div class="[&::-webkit-resizer:hover]:underline" />
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
2022-12-02 12:18:23 -05:00
|
|
|
}
|
2023-01-20 12:45:04 -05:00
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
let result = await run(input, config)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.\[\&\:\:-webkit-resizer\:hover\]\:underline::-webkit-resizer:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar-button\:hover\]\:underline::-webkit-scrollbar-button:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar-corner\:hover\]\:underline::-webkit-scrollbar-corner:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar-thumb\:hover\]\:underline::-webkit-scrollbar-thumb:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar-track-piece\:hover\]\:underline::-webkit-scrollbar-track-piece:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar-track\:hover\]\:underline::-webkit-scrollbar-track:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
.\[\&\:\:-webkit-scrollbar\:hover\]\:underline::-webkit-scrollbar:hover {
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2023-03-10 12:03:38 -05:00
|
|
|
|
|
|
|
|
test('stacking dark and rtl variants', async () => {
|
|
|
|
|
let config = {
|
2024-01-05 14:39:34 -05:00
|
|
|
darkMode: 'selector',
|
2023-03-10 12:03:38 -05:00
|
|
|
content: [
|
|
|
|
|
{
|
2023-03-21 15:31:41 +01:00
|
|
|
raw: html`<div class="dark:rtl:italic" />`,
|
2023-03-10 12:03:38 -05:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
let result = await run(input, config)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
2024-01-05 14:39:34 -05:00
|
|
|
.dark\:rtl\:italic:where([dir='rtl'], [dir='rtl'] *):where(.dark, .dark *) {
|
2023-03-10 12:03:38 -05:00
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2023-03-21 15:31:41 +01:00
|
|
|
|
|
|
|
|
test('stacking dark and rtl variants with pseudo elements', async () => {
|
|
|
|
|
let config = {
|
2024-01-05 14:39:34 -05:00
|
|
|
darkMode: 'selector',
|
2023-03-21 15:31:41 +01:00
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`<div class="dark:rtl:placeholder:italic" />`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
let result = await run(input, config)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
2024-01-05 14:39:34 -05:00
|
|
|
.dark\:rtl\:placeholder\:italic:where([dir='rtl'], [dir='rtl'] *):where(
|
|
|
|
|
.dark,
|
|
|
|
|
.dark *
|
|
|
|
|
)::placeholder {
|
2023-03-21 15:31:41 +01:00
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2023-12-09 09:11:00 -05:00
|
|
|
|
|
|
|
|
test('* is matched by the parser as the children variant', async () => {
|
|
|
|
|
let config = {
|
|
|
|
|
content: [
|
|
|
|
|
{
|
|
|
|
|
raw: html`
|
|
|
|
|
<div class="*:italic" />
|
|
|
|
|
<div class="*:hover:italic" />
|
|
|
|
|
<div class="hover:*:italic" />
|
|
|
|
|
<div class="data-[slot=label]:*:hover:italic" />
|
|
|
|
|
<div class="[&_p]:*:hover:italic" />
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
corePlugins: { preflight: false },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let input = css`
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
let result = await run(input, config)
|
|
|
|
|
|
|
|
|
|
expect(result.css).toMatchFormattedCss(css`
|
|
|
|
|
.\*\:italic > *,
|
|
|
|
|
.\*\:hover\:italic:hover > *,
|
|
|
|
|
.hover\:\*\:italic > :hover,
|
|
|
|
|
.data-\[slot\=label\]\:\*\:hover\:italic:hover > [data-slot='label'],
|
|
|
|
|
.\[\&_p\]\:\*\:hover\:italic:hover > * p {
|
|
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
})
|
2022-12-02 12:18:23 -05:00
|
|
|
})
|