-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update regex extractor * implement `matchVariant` API * add `matchVariant` test * add `values` option to the `matchVariant` API * move `matchVariant` tests to own file * update changelog
- Loading branch information
1 parent
6c63f67
commit fc25299
Showing
5 changed files
with
184 additions
and
4 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
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,132 @@ | ||
import { run, html, css } from './util/run' | ||
|
||
test('partial arbitrary variants', () => { | ||
let config = { | ||
content: [ | ||
{ | ||
raw: html`<div class="potato-[yellow]:bg-yellow-200 potato-[baked]:w-3"></div> `, | ||
}, | ||
], | ||
corePlugins: { preflight: false }, | ||
plugins: [ | ||
({ matchVariant }) => { | ||
matchVariant({ | ||
potato: (flavor) => `.potato-${flavor} &`, | ||
}) | ||
}, | ||
], | ||
} | ||
|
||
let input = css` | ||
@tailwind utilities; | ||
` | ||
|
||
return run(input, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(css` | ||
.potato-baked .potato-\[baked\]\:w-3 { | ||
width: 0.75rem; | ||
} | ||
.potato-yellow .potato-\[yellow\]\:bg-yellow-200 { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(254 240 138 / var(--tw-bg-opacity)); | ||
} | ||
`) | ||
}) | ||
}) | ||
|
||
test('partial arbitrary variants with default values', () => { | ||
let config = { | ||
content: [ | ||
{ | ||
raw: html`<div class="tooltip-bottom:mt-2 tooltip-top:mb-2"></div>`, | ||
}, | ||
], | ||
corePlugins: { preflight: false }, | ||
plugins: [ | ||
({ matchVariant }) => { | ||
matchVariant( | ||
{ | ||
tooltip: (side) => `&${side}`, | ||
}, | ||
{ | ||
values: { | ||
bottom: '[data-location="bottom"]', | ||
top: '[data-location="top"]', | ||
}, | ||
} | ||
) | ||
}, | ||
], | ||
} | ||
|
||
let input = css` | ||
@tailwind utilities; | ||
` | ||
|
||
return run(input, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(css` | ||
.tooltip-bottom\:mt-2[data-location='bottom'] { | ||
margin-top: 0.5rem; | ||
} | ||
.tooltip-top\:mb-2[data-location='top'] { | ||
margin-bottom: 0.5rem; | ||
} | ||
`) | ||
}) | ||
}) | ||
|
||
test('matched variant values maintain the sort order they are registered in', () => { | ||
let config = { | ||
content: [ | ||
{ | ||
raw: html`<div | ||
class="alphabet-c:underline alphabet-a:underline alphabet-d:underline alphabet-b:underline" | ||
></div>`, | ||
}, | ||
], | ||
corePlugins: { preflight: false }, | ||
plugins: [ | ||
({ matchVariant }) => { | ||
matchVariant( | ||
{ | ||
alphabet: (side) => `&${side}`, | ||
}, | ||
{ | ||
values: { | ||
a: '[data-value="a"]', | ||
b: '[data-value="b"]', | ||
c: '[data-value="c"]', | ||
d: '[data-value="d"]', | ||
}, | ||
} | ||
) | ||
}, | ||
], | ||
} | ||
|
||
let input = css` | ||
@tailwind utilities; | ||
` | ||
|
||
return run(input, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(css` | ||
.alphabet-a\:underline[data-value='a'] { | ||
text-decoration-line: underline; | ||
} | ||
.alphabet-b\:underline[data-value='b'] { | ||
text-decoration-line: underline; | ||
} | ||
.alphabet-c\:underline[data-value='c'] { | ||
text-decoration-line: underline; | ||
} | ||
.alphabet-d\:underline[data-value='d'] { | ||
text-decoration-line: underline; | ||
} | ||
`) | ||
}) | ||
}) |