-
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.
Allow variant plugins to tell Tailwind they should stack (#2382)
* Fix unwanted stacking behavior on any non-darkModeVariant "dark" variant (#2380) * Add failing tests for non-darkModeVariant "dark" variant stacking behavior * Fix unwanted non-darkModeVariant "dark" variant stacking (by making the failing test pass) * Add unstable_stack option for variants to tell Tailwind they should stack * Update eslint to allow unstable_ variables * Update changelog Co-authored-by: Navith <28162694+JakeNavith@users.noreply.github.com>
- Loading branch information
1 parent
5200f49
commit 078e0f8
Showing
7 changed files
with
143 additions
and
85 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 |
---|---|---|
@@ -1,38 +1,42 @@ | ||
import buildSelectorVariant from '../util/buildSelectorVariant' | ||
|
||
export default function({ addVariant, config, postcss, prefix }) { | ||
addVariant('dark', ({ container, separator, modifySelectors }) => { | ||
if (config('dark') === 'media') { | ||
const modified = modifySelectors(({ selector }) => { | ||
return buildSelectorVariant(selector, 'dark', separator, message => { | ||
throw container.error(message) | ||
addVariant( | ||
'dark', | ||
({ container, separator, modifySelectors }) => { | ||
if (config('dark') === 'media') { | ||
const modified = modifySelectors(({ selector }) => { | ||
return buildSelectorVariant(selector, 'dark', separator, message => { | ||
throw container.error(message) | ||
}) | ||
}) | ||
}) | ||
const mediaQuery = postcss.atRule({ | ||
name: 'media', | ||
params: '(prefers-color-scheme: dark)', | ||
}) | ||
mediaQuery.append(modified) | ||
container.append(mediaQuery) | ||
return container | ||
} | ||
const mediaQuery = postcss.atRule({ | ||
name: 'media', | ||
params: '(prefers-color-scheme: dark)', | ||
}) | ||
mediaQuery.append(modified) | ||
container.append(mediaQuery) | ||
return container | ||
} | ||
|
||
if (config('dark') === 'class') { | ||
const modified = modifySelectors(({ selector }) => { | ||
return buildSelectorVariant(selector, 'dark', separator, message => { | ||
throw container.error(message) | ||
if (config('dark') === 'class') { | ||
const modified = modifySelectors(({ selector }) => { | ||
return buildSelectorVariant(selector, 'dark', separator, message => { | ||
throw container.error(message) | ||
}) | ||
}) | ||
}) | ||
|
||
modified.walkRules(rule => { | ||
rule.selectors = rule.selectors.map(selector => { | ||
return `${prefix('.dark')} ${selector}` | ||
modified.walkRules(rule => { | ||
rule.selectors = rule.selectors.map(selector => { | ||
return `${prefix('.dark')} ${selector}` | ||
}) | ||
}) | ||
}) | ||
|
||
return modified | ||
} | ||
return modified | ||
} | ||
|
||
throw new Error("The `dark` config option must be either 'media' or 'class'.") | ||
}) | ||
throw new Error("The `dark` config option must be either 'media' or 'class'.") | ||
}, | ||
{ unstable_stack: true } | ||
) | ||
} |
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