-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configurable Dark Mode ClassName
- Loading branch information
Showing
4 changed files
with
107 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'twind': patch | ||
--- | ||
|
||
configurable Dark Mode ClassName |
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,92 @@ | ||
import { assert, test } from 'vitest' | ||
|
||
import { twind, virtual } from '..' | ||
|
||
test('should be possible to use the darkMode "class" mode', () => { | ||
const tw = twind( | ||
{ | ||
darkMode: 'class', | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, ['.dark .dark\\:font-700{font-weight:700}']) | ||
}) | ||
|
||
test('should be possible to change the class name', () => { | ||
const tw = twind( | ||
{ | ||
darkMode: ['class', '.test-dark'], | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, ['.test-dark .dark\\:font-700{font-weight:700}']) | ||
}) | ||
|
||
test('should be possible to use any selector', () => { | ||
const tw = twind( | ||
{ | ||
darkMode: '[theme=dark] &', | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, ['[theme=dark] .dark\\:font-700{font-weight:700}']) | ||
}) | ||
|
||
test('should be possible to use the darkMode "media" mode', () => { | ||
const tw = twind( | ||
{ | ||
darkMode: 'media', | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, [ | ||
'@media (prefers-color-scheme:dark){.dark\\:font-700{font-weight:700}}', | ||
]) | ||
}) | ||
|
||
test('should default to the `media` mode when no mode is provided', () => { | ||
const tw = twind( | ||
{ | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, [ | ||
'@media (prefers-color-scheme:dark){.dark\\:font-700{font-weight:700}}', | ||
]) | ||
}) | ||
|
||
test('should default to the `media` mode when mode is set to `false`', () => { | ||
const tw = twind( | ||
{ | ||
darkMode: false, | ||
rules: [['font-', 'fontWeight']], | ||
}, | ||
virtual(), | ||
) | ||
|
||
assert.strictEqual(tw('dark:font-700'), 'dark:font-700') | ||
|
||
assert.deepEqual(tw.target, [ | ||
'@media (prefers-color-scheme:dark){.dark\\:font-700{font-weight:700}}', | ||
]) | ||
}) |
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