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 committed Jul 26, 2023
1 parent e0c52a9 commit a8a07f5
Show file tree
Hide file tree
Showing 4 changed files with 20 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 @@ -759,6 +759,7 @@ function resolvePlugins(context, root) {
variantPlugins['printVariant'],
variantPlugins['screenVariants'],
variantPlugins['orientationVariants'],
variantPlugins['forcedColorsVariants'],
]

return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
Expand Down
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;
}
}
`)
5 changes: 5 additions & 0 deletions tests/plugins/variants/prefersContrastVariants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ quickVariantPluginTest('prefersContrastVariants').toMatchFormattedCss(css`
display: flex;
}
}
@media (prefers-contrast: custom) {
.contrast-custom\:flex {
display: flex;
}
}
`)

0 comments on commit a8a07f5

Please sign in to comment.