Skip to content

Commit 52bf52b

Browse files
authored
Merge pull request #67 from nlemoine/add-tailwind-custom-selector-docs
Add docs for Tailwind custom dark class handling
2 parents 2e72ecb + 73eec3a commit 52bf52b

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

README.md

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Similar to the tailwindcss configurations you are used to. It is also possible t
2020
- Variables can be formed through using nested object notation.
2121
- Different variables can be composed for the Dark Mode.
2222
- Dark Mode variables are set automatically through the `class` or `media` modes on your configuration.
23-
- If `darkMode` config are set as `class`, custom dark selector can be defined.
23+
- Dark Mode custom selector is inherited from [Tailwind configuration](https://tailwindcss.com/docs/dark-mode#customizing-the-class-name)
2424
- It allows you to add custom themes while creating your own plugin via the plugin API.
2525
- Prefix can be defined for variables. (It is useful when using the plugin API)
2626
- You can configure your own needs such as multi-themes without needing an additional plugin!
@@ -176,22 +176,70 @@ module.exports = {
176176
}
177177
```
178178

179-
#### with the `darkToRoot` and `darkSelector` configurations
179+
#### Custom dark selector
180180

181-
If the `darkMode`configuration is set as `'class'` in your tailwindcss configuration, you can change and customize the `darkToRoot` and `darkSelector` settings.
181+
Note that the plugin will use your custom selector if [enabled in your Tailwind configuration](https://tailwindcss.com/docs/dark-mode#customizing-the-class-name).
182+
183+
```javascript
184+
// tailwind.config.js
185+
186+
module.exports = {
187+
188+
darkMode: ['class', '.custom-dark-selector'],
189+
190+
theme: {
191+
variables: {
192+
DEFAULT: {
193+
colors: {
194+
red: {
195+
50: 'red',
196+
},
197+
},
198+
},
199+
},
200+
darkVariables: {
201+
DEFAULT: {
202+
colors: {
203+
red: {
204+
50: 'blue',
205+
},
206+
},
207+
},
208+
},
209+
},
210+
plugins: [
211+
require('@mertasan/tailwindcss-variables')
212+
]
213+
}
214+
```
215+
216+
**Output:**
217+
218+
```css
219+
:root {
220+
--colors-red-50: red
221+
}
222+
223+
:root.custom-dark-selector {
224+
--colors-red-50: blue
225+
}
226+
```
227+
228+
#### with the `darkToRoot` configuration
229+
230+
If the `darkMode` configuration is set as `'class'` in your tailwindcss configuration, you can change and customize the `darkToRoot` setting.
182231

183232

184233
| Option | Type | Default | Description |
185234
|-------------- |-------- |--------- |------------------------------------------------------------------------- |
186-
| darkSelector | string | .dark | CSS selector used for Dark mode. |
187-
| darkToRoot | bool | true | Does the selector defined as`darkSelector` being used as :root ? |
235+
| darkToRoot | bool | true | |
188236

189237
```javascript
190238
// tailwind.config.js
191239

192240
module.exports = {
193241

194-
darkMode: 'class',
242+
darkMode: ['class', '.custom-dark-selector'],
195243

196244
theme: {
197245
variables: {
@@ -233,7 +281,6 @@ module.exports = {
233281
plugins: [
234282
require('@mertasan/tailwindcss-variables')({
235283
darkToRoot: false,
236-
darkSelector: '.custom-dark-selector',
237284
})
238285
]
239286
}

0 commit comments

Comments
 (0)