-
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.
Register dark mode plugin outside of resolveConfig code path (#2368)
- Loading branch information
1 parent
fd194f0
commit 6a9c3e7
Showing
5 changed files
with
51 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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) | ||
}) | ||
}) | ||
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) | ||
}) | ||
}) | ||
|
||
modified.walkRules(rule => { | ||
rule.selectors = rule.selectors.map(selector => { | ||
return `${prefix('.dark')} ${selector}` | ||
}) | ||
}) | ||
|
||
return modified | ||
} | ||
|
||
throw new Error("The `dark` config option must be either 'media' or 'class'.") | ||
}) | ||
} |
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