Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable Dark Mode ClassName #5800

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export let variantPlugins = {
},

darkVariants: ({ config, addVariant }) => {
let mode = config('darkMode', 'media')
let [mode, className = '.dark'] = [].concat(config('darkMode', 'media'))

if (mode === false) {
mode = 'media'
log.warn('darkmode-false', [
Expand All @@ -144,7 +145,7 @@ export let variantPlugins = {
}

if (mode === 'class') {
addVariant('dark', '.dark &')
addVariant('dark', `${className} &`)
} else if (mode === 'media') {
addVariant('dark', '@media (prefers-color-scheme: dark)')
}
Expand Down
22 changes: 22 additions & 0 deletions tests/dark-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ it('should be possible to use the darkMode "class" mode', () => {
})
})

it('should be possible to change the class name', () => {
let config = {
darkMode: ['class', '.test-dark'],
content: [{ raw: html`<div class="dark:font-bold"></div>` }],
corePlugins: { preflight: false },
}

let input = css`
@tailwind base;
@tailwind components;
@tailwind utilities;
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.test-dark .dark\:font-bold {
font-weight: 700;
}
`)
})
})

it('should be possible to use the darkMode "media" mode', () => {
let config = {
darkMode: 'media',
Expand Down