Skip to content

Commit 751eb74

Browse files
Add inverted-colors variant (#11693)
Add a variant for the [`inverted-colors`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/inverted-colors) media query. This has been supported in Safari for a while. I'm also implementing support in Chrome atm. I've decided to only add the inverted-colors: inverted variant because the `none` state isn't really useful. --------- Co-authored-by: Philipp Spiess <[email protected]>
1 parent 62d3e74 commit 751eb74

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- _Experimental_: Add `inverted-colors` variant ([#11693](https://github.com/tailwindlabs/tailwindcss/pull/11693))
1213
- _Experimental_: Add `user-valid` and `user-invalid` variants ([#12370](https://github.com/tailwindlabs/tailwindcss/pull/12370))
1314
- _Experimental_: Add `wrap-anywhere`, `wrap-break-word`, and `wrap-normal` utilities ([#12128](https://github.com/tailwindlabs/tailwindcss/pull/12128))
1415

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8448,6 +8448,7 @@ exports[`getVariants 1`] = `
84488448
"dark",
84498449
"print",
84508450
"forced-colors",
8451+
"inverted-colors",
84518452
],
84528453
},
84538454
{
@@ -9169,5 +9170,12 @@ exports[`getVariants 1`] = `
91699170
"selectors": [Function],
91709171
"values": [],
91719172
},
9173+
{
9174+
"hasDash": true,
9175+
"isArbitrary": false,
9176+
"name": "inverted-colors",
9177+
"selectors": [Function],
9178+
"values": [],
9179+
},
91729180
]
91739181
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export const enableInvertedColors = process.env.FEATURES_ENV !== 'stable'
12
export const enableUserValid = process.env.FEATURES_ENV !== 'stable'
23
export const enableWrapAnywhere = process.env.FEATURES_ENV !== 'stable'

packages/tailwindcss/src/variants.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,16 @@ test('forced-colors', async () => {
19071907
expect(await run(['forced-colors/foo:flex'])).toEqual('')
19081908
})
19091909

1910+
test('inverted-colors', async () => {
1911+
expect(await run(['inverted-colors:flex'])).toMatchInlineSnapshot(`
1912+
"@media (inverted-colors: inverted) {
1913+
.inverted-colors\\:flex {
1914+
display: flex;
1915+
}
1916+
}"
1917+
`)
1918+
})
1919+
19101920
test('nth', async () => {
19111921
expect(
19121922
await run([

packages/tailwindcss/src/variants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
type StyleRule,
1313
} from './ast'
1414
import { type Variant } from './candidate'
15-
import { enableUserValid } from './feature-flags'
15+
import { enableInvertedColors, enableUserValid } from './feature-flags'
1616
import type { Theme } from './theme'
1717
import { compareBreakpoints } from './utils/compare-breakpoints'
1818
import { DefaultMap } from './utils/default-map'
@@ -1143,6 +1143,10 @@ export function createVariants(theme: Theme): Variants {
11431143

11441144
staticVariant('forced-colors', ['@media (forced-colors: active)'])
11451145

1146+
if (enableInvertedColors) {
1147+
staticVariant('inverted-colors', ['@media (inverted-colors: inverted)'])
1148+
}
1149+
11461150
return variants
11471151
}
11481152

0 commit comments

Comments
 (0)