Skip to content

Commit d5a6ae9

Browse files
author
Quang Phan
committed
feat: tailwind support via plugin
1 parent c7dbf3d commit d5a6ae9

5 files changed

Lines changed: 347 additions & 1 deletion

File tree

.changeset/tricky-chicken-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'postcss-color-scheme': minor
3+
---
4+
5+
provide tailwind plugin as first party support, import at `postcss-color-scheme/tailwind`

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
[![github.actions.changeset.badge]][github.actions.changeset] [![codecov.badge]][codecov] [![MIT][license.badge]][license] [![npm.badge]][npm]
44

5+
## Table of Contents
6+
7+
- [postcss-color-scheme](#postcss-color-scheme)
8+
- [Table of Contents](#table-of-contents)
9+
- [Changelog](#changelog)
10+
- [Installation](#installation)
11+
- [Design Decisions](#design-decisions)
12+
- [Supported At Rules](#supported-at-rules)
13+
- [Global Variant](#global-variant)
14+
- [Test Cases \& Examples](#test-cases--examples)
15+
- [Tailwind Support](#tailwind-support)
16+
517
## [Changelog][changelog]
618

7-
Postcss plugin for handling `prefers-color-scheme`
19+
Postcss plugin for handling `prefers-color-scheme`, plus [tailwind support](#tailwind-support)
820

921
Input
1022

@@ -140,6 +152,31 @@ The following table lists test cases covered by this plugin, please refer to [te
140152
| with [postcss-nesting] | `.my-class { & .nested { @dark { color: white } } }` | [input][tests.with-postcss-nesting.input] | [output][tests.with-postcss-nesting.output] |
141153
| with [postcss-nested] | `.my-class { .nested { @dark { color: white } } }` | [input][tests.with-postcss-nested.input] | [output][tests.with-postcss-nested.output] |
142154

155+
## Tailwind Support
156+
157+
Make sure you have installed and configured `tailwindcss`.
158+
159+
```bash
160+
npm install --save-dev tailwindcss
161+
```
162+
163+
Add `postcss-color-scheme` to your tailwind config as a plugin, and turn off the default `darkMode` handling.
164+
165+
```js
166+
/** @type {import("tailwindcss").Config } */
167+
module.exports = {
168+
// your config ...
169+
darkMode: '',
170+
plugins: [require('postcss-color-scheme/tailwind')],
171+
};
172+
```
173+
174+
Now, the following is available:
175+
176+
```html
177+
<input class="text-white dark:text-black light:border-gray-500">
178+
```
179+
143180
[changelog]: ./CHANGELOG.md
144181
[tests]: https://github.com/vnphanquang/postcss-color-scheme/blob/main/src/color-scheme.test.js
145182

@@ -169,3 +206,4 @@ The following table lists test cases covered by this plugin, please refer to [te
169206

170207
[postcss-nesting]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting
171208
[postcss-nested]: https://github.com/postcss/postcss-nested
209+
[tailwind]: https://tailwindcss.com/

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"version": "0.1.0",
44
"description": "postcss plugin for handling prefers-color-scheme",
55
"main": "src/index.js",
6+
"exports": {
7+
"./package.json": "./package.json",
8+
"./tailwind": "./src/tailwind.js",
9+
".": "./src/index.js"
10+
},
611
"scripts": {
712
"test": "vitest --ui --coverage",
813
"ci:test": "vitest run --coverage",
@@ -40,6 +45,7 @@
4045
"postcss-nested": "^6.0.1",
4146
"postcss-nesting": "^11.2.2",
4247
"prettier": "^2.8.7",
48+
"tailwindcss": "^3.3.1",
4349
"vitest": "^0.29.8"
4450
},
4551
"engines": {

0 commit comments

Comments
 (0)