Skip to content

Commit

Permalink
Add inverted-colors variant (#11693)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lukewarlow and philipp-spiess authored Feb 21, 2025
1 parent 62d3e74 commit 751eb74
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8448,6 +8448,7 @@ exports[`getVariants 1`] = `
"dark",
"print",
"forced-colors",
"inverted-colors",
],
},
{
Expand Down Expand Up @@ -9169,5 +9170,12 @@ exports[`getVariants 1`] = `
"selectors": [Function],
"values": [],
},
{
"hasDash": true,
"isArbitrary": false,
"name": "inverted-colors",
"selectors": [Function],
"values": [],
},
]
`;
1 change: 1 addition & 0 deletions packages/tailwindcss/src/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const enableInvertedColors = process.env.FEATURES_ENV !== 'stable'
export const enableUserValid = process.env.FEATURES_ENV !== 'stable'
export const enableWrapAnywhere = process.env.FEATURES_ENV !== 'stable'
10 changes: 10 additions & 0 deletions packages/tailwindcss/src/variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,16 @@ test('forced-colors', async () => {
expect(await run(['forced-colors/foo:flex'])).toEqual('')
})

test('inverted-colors', async () => {
expect(await run(['inverted-colors:flex'])).toMatchInlineSnapshot(`
"@media (inverted-colors: inverted) {
.inverted-colors\\:flex {
display: flex;
}
}"
`)
})

test('nth', async () => {
expect(
await run([
Expand Down
6 changes: 5 additions & 1 deletion packages/tailwindcss/src/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type StyleRule,
} from './ast'
import { type Variant } from './candidate'
import { enableUserValid } from './feature-flags'
import { enableInvertedColors, enableUserValid } from './feature-flags'
import type { Theme } from './theme'
import { compareBreakpoints } from './utils/compare-breakpoints'
import { DefaultMap } from './utils/default-map'
Expand Down Expand Up @@ -1143,6 +1143,10 @@ export function createVariants(theme: Theme): Variants {

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

if (enableInvertedColors) {
staticVariant('inverted-colors', ['@media (inverted-colors: inverted)'])
}

return variants
}

Expand Down

0 comments on commit 751eb74

Please sign in to comment.