-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: Add exhaustive pseudo-class and pseudo-element variant support (#…
…4482) * Add first-line, first-letter, and marker variants * Add selection variant Co-Authored-By: Eric Rodrigues Pires <[email protected]> * Add remaining pseudo-class variants * Add target pseudo-class Co-Authored-By: Peter Neupauer <[email protected]> * add test for parallel variants * implement parallel variants Co-authored-by: Eric Rodrigues Pires <[email protected]> Co-authored-by: Peter Neupauer <[email protected]> Co-authored-by: Robin Malfait <[email protected]>
- Loading branch information
1 parent
8cd6017
commit d1e9632
Showing
6 changed files
with
437 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import postcss from 'postcss' | ||
import path from 'path' | ||
import tailwind from '../../src/jit/index.js' | ||
import { transformAllSelectors, updateAllClasses } from '../../src/util/pluginUtils.js' | ||
|
||
function run(input, config = {}) { | ||
const { currentTestName } = expect.getState() | ||
|
||
return postcss(tailwind(config)).process(input, { | ||
from: `${path.resolve(__filename)}?test=${currentTestName}`, | ||
}) | ||
} | ||
|
||
test('basic parallel variants', async () => { | ||
let config = { | ||
mode: 'jit', | ||
purge: [ | ||
{ | ||
raw: '<div class="font-normal hover:test:font-black test:font-bold test:font-medium"></div>', | ||
}, | ||
], | ||
theme: {}, | ||
plugins: [ | ||
function test({ addVariant, config }) { | ||
addVariant('test', [ | ||
transformAllSelectors((selector) => { | ||
let variantSelector = updateAllClasses(selector, (className) => { | ||
return `test${config('separator')}${className}` | ||
}) | ||
|
||
return `${variantSelector} *::test` | ||
}), | ||
transformAllSelectors((selector) => { | ||
return updateAllClasses(selector, (className, { withPseudo }) => { | ||
return withPseudo(`test${config('separator')}${className}`, '::test') | ||
}) | ||
}), | ||
]) | ||
}, | ||
], | ||
} | ||
|
||
let css = `@tailwind utilities` | ||
|
||
return run(css, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(` | ||
.font-normal { | ||
font-weight: 400; | ||
} | ||
.test\\:font-bold *::test { | ||
font-weight: 700; | ||
} | ||
.test\\:font-medium *::test { | ||
font-weight: 500; | ||
} | ||
.hover\\:test\\:font-black:hover *::test { | ||
font-weight: 900; | ||
} | ||
.test\\:font-bold::test { | ||
font-weight: 700; | ||
} | ||
.test\\:font-medium::test { | ||
font-weight: 500; | ||
} | ||
.hover\\:test\\:font-black:hover::test { | ||
font-weight: 900; | ||
} | ||
`) | ||
}) | ||
}) |
Oops, something went wrong.