Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit b3deb81

Browse files
committed
Sort variant plugins relative to custom variant plugins in BC compatible way
1 parent 5a193da commit b3deb81

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

src/corePlugins/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
} = require('../pluginUtils')
1212

1313
module.exports = {
14-
variants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
14+
pseudoClassVariants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
1515
let pseudoVariants = [
1616
['first', 'first-child'],
1717
['last', 'last-child'],
@@ -57,7 +57,8 @@ module.exports = {
5757
})
5858
)
5959
}
60-
60+
},
61+
reducedMotionVariants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
6162
addVariant(
6263
'motion-safe',
6364
transformLastClasses(
@@ -77,7 +78,8 @@ module.exports = {
7778
() => postcss.atRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' })
7879
)
7980
)
80-
81+
},
82+
directionVariants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
8183
addVariant(
8284
'ltr',
8385
transformAllSelectors(
@@ -91,7 +93,8 @@ module.exports = {
9193
(selector) => `[dir="rtl"] ${updateAllClasses(selector, (className) => `rtl:${className}`)}`
9294
)
9395
)
94-
96+
},
97+
darkVariants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
9598
if (config.darkMode === 'class') {
9699
addVariant(
97100
'dark',
@@ -118,7 +121,8 @@ module.exports = {
118121
)
119122
)
120123
}
121-
124+
},
125+
screenVariants: function ({ jit: { config, theme, addUtilities, addVariant, e } }) {
122126
for (let screen in theme.screens) {
123127
let size = theme.screens[screen]
124128
let query = buildMediaQuery(size)

src/index.test.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ div {
368368
.group:active .group-active\:opacity-10 {
369369
opacity: 0.1;
370370
}
371+
.foo\:custom-util {
372+
background: #abcdef !important;
373+
}
374+
.foo\:hover\:custom-util:hover {
375+
background: #abcdef !important;
376+
}
371377
@media (prefers-reduced-motion: no-preference) {
372378
.motion-safe\:transition {
373379
transition-property: background-color, border-color, color, fill, stroke, opacity, box-shadow,
@@ -390,12 +396,6 @@ div {
390396
.dark .dark\:custom-util {
391397
background: #abcdef;
392398
}
393-
.foo\:custom-util {
394-
background: #abcdef !important;
395-
}
396-
.foo\:hover\:custom-util:hover {
397-
background: #abcdef !important;
398-
}
399399
@media (min-width: 640px) {
400400
.sm\:container {
401401
width: 100%;
@@ -508,7 +508,7 @@ div {
508508
}
509509
}
510510
@media (prefers-reduced-motion: no-preference) {
511-
.foo\:dark .md\:dark\:motion-safe\:active\:custom-util:active {
511+
.dark .md\:dark\:motion-safe\:foo\:active\:custom-util:active {
512512
background: #abcdef !important;
513513
}
514514
}

src/index.test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="sm:custom-util"></div>
2323
<div class="dark:custom-util"></div>
2424
<div class="motion-safe:custom-util"></div>
25-
<div class="md:foo:dark:motion-safe:active:custom-util"></div>
25+
<div class="md:dark:motion-safe:foo:active:custom-util"></div>
2626
<div class="aspect-w-1 aspect-h-2"></div>
2727
<div class="aspect-w-3 aspect-h-4"></div>
2828
<div class="filter-none filter-grayscale"></div>

src/lib/setupContext.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,6 @@ function setupContext(configOrPath) {
659659

660660
let corePluginList = Object.entries(corePlugins)
661661
.map(([name, plugin]) => {
662-
// TODO: Make variants a real core plugin so we don't special case it
663-
if (name === 'variants') {
664-
return plugin
665-
}
666-
667662
if (!tailwindConfig.corePlugins.includes(name)) {
668663
return null
669664
}
@@ -707,9 +702,19 @@ function setupContext(configOrPath) {
707702
}
708703
})
709704

705+
// TODO: This is a workaround for backwards compatibility, since custom variants
706+
// were historically sorted before screen/stackable variants.
707+
let beforeVariants = [corePlugins['pseudoClassVariants']]
708+
let afterVariants = [
709+
corePlugins['directionVariants'],
710+
corePlugins['reducedMotionVariants'],
711+
corePlugins['darkVariants'],
712+
corePlugins['screenVariants'],
713+
]
714+
710715
registerPlugins(
711716
context.tailwindConfig,
712-
[...corePluginList, ...userPlugins, ...layerPlugins],
717+
[...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins],
713718
context
714719
)
715720

0 commit comments

Comments
 (0)