Skip to content

Commit

Permalink
Add forced-colors variant
Browse files Browse the repository at this point in the history
Also add a contrast-custom variant to match custom contrast preferences
  • Loading branch information
lukewarlow authored and RobinMalfait committed Nov 2, 2023
1 parent 2d6856c commit 6763eda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,11 @@ export let variantPlugins = {
prefersContrastVariants: ({ addVariant }) => {
addVariant('contrast-more', '@media (prefers-contrast: more)')
addVariant('contrast-less', '@media (prefers-contrast: less)')
addVariant('contrast-custom', '@media (prefers-contrast: custom)')
},

forcedColorsVariants: ({ addVariant }) => {
addVariant('forced-colors', '@media (forced-colors: active)')
},
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ function resolvePlugins(context, root) {
variantPlugins['printVariant'],
variantPlugins['screenVariants'],
variantPlugins['orientationVariants'],
variantPlugins['forcedColorsVariants'],
]

return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ exports[`should test the 'prefersContrastVariants' plugin 1`] = `
display: flex;
}
}
@media (prefers-contrast: custom) {
.contrast-custom\\:flex {
display: flex;
}
}
"
`;
9 changes: 9 additions & 0 deletions tests/plugins/variants/forcedColorsVariants.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { css, quickVariantPluginTest } from '../../util/run'

quickVariantPluginTest('forcedColorsVariants').toMatchFormattedCss(css`
@media (forced-colors: active) {
.forced-colors\:flex {
display: flex;
}
}
`)

0 comments on commit 6763eda

Please sign in to comment.