-
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.
Add
prefers-contrast
media query variants (#8410)
* Add prefers-contrast variants * add tests for prefers contrast * dark mode should have precedence over prefers contrast variants * update changelog Co-authored-by: Luke Warlow <[email protected]>
- Loading branch information
1 parent
83b4811
commit 816a0f2
Showing
6 changed files
with
97 additions
and
0 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
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,74 @@ | ||
import { run, html, css, defaults } from './util/run' | ||
|
||
it('should be possible to use contrast-more and contrast-less variants', () => { | ||
let config = { | ||
content: [ | ||
{ raw: html`<div class="contrast-more:bg-pink-500 contrast-less:bg-black bg-white"></div>` }, | ||
], | ||
corePlugins: { preflight: false }, | ||
} | ||
|
||
let input = css` | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
` | ||
|
||
return run(input, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(css` | ||
${defaults} | ||
.bg-white { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(255 255 255 / var(--tw-bg-opacity)); | ||
} | ||
@media (prefers-contrast: more) { | ||
.contrast-more\:bg-pink-500 { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(236 72 153 / var(--tw-bg-opacity)); | ||
} | ||
} | ||
@media (prefers-contrast: less) { | ||
.contrast-less\:bg-black { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(0 0 0 / var(--tw-bg-opacity)); | ||
} | ||
} | ||
`) | ||
}) | ||
}) | ||
|
||
it('dark mode should appear after the contrast variants', () => { | ||
let config = { | ||
content: [{ raw: html`<div class="contrast-more:bg-black dark:bg-white"></div>` }], | ||
corePlugins: { preflight: false }, | ||
} | ||
|
||
let input = css` | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
` | ||
|
||
return run(input, config).then((result) => { | ||
expect(result.css).toMatchFormattedCss(css` | ||
${defaults} | ||
@media (prefers-contrast: more) { | ||
.contrast-more\:bg-black { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(0 0 0 / var(--tw-bg-opacity)); | ||
} | ||
} | ||
@media (prefers-color-scheme: dark) { | ||
.dark\:bg-white { | ||
--tw-bg-opacity: 1; | ||
background-color: rgb(255 255 255 / var(--tw-bg-opacity)); | ||
} | ||
} | ||
`) | ||
}) | ||
}) |
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