Skip to content

Commit

Permalink
Fix dark/lightMode with array value
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-rogerson committed Jul 2, 2022
1 parent 8969ea0 commit b59e93e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions __fixtures__/darkLightModeArray/darkLightMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import tw from './macro' // twinImport

tw`dark:block`
tw`light:block`
4 changes: 4 additions & 0 deletions __fixtures__/darkLightModeArray/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
darkMode: ['class', '.test-dark'],
lightMode: ['class', '.test-light'],
}
24 changes: 24 additions & 0 deletions __snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20998,6 +20998,30 @@ tw\`cursor-[url(hand.cur), pointer]\`
})


`;

exports[`twin.macro darkLightMode.js: darkLightMode.js 1`] = `

import tw from './macro' // twinImport

tw\`dark:block\`
tw\`light:block\`

↓ ↓ ↓ ↓ ↓ ↓

// twinImport
;({
'.test-dark &': {
display: 'block',
},
})
;({
'.test-light &': {
display: 'block',
},
})


`;

exports[`twin.macro directionalBorders.js: directionalBorders.js 1`] = `
Expand Down
20 changes: 6 additions & 14 deletions src/config/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ const variantPlugins = {
},

darkVariants({ config, addVariant }) {
let [mode, className = '.dark'] = [config('darkMode', 'media')]
// eslint-disable-next-line unicorn/prefer-spread
let [mode, className = '.dark'] = [].concat(config('darkMode', 'media'))

if (mode === false) {
mode = 'media'
console.warn('darkmode-false', [
'The `darkMode` option in your Tailwind CSS configuration is set to `false`, which now behaves the same as `media`.',
'The `darkMode` option in your tailwind config is set to `false`, which now behaves the same as `media`.',
'Change `darkMode` to `media` or remove it entirely.',
'https://tailwindcss.com/docs/upgrade-guide#remove-dark-mode-configuration',
])
Expand All @@ -177,19 +178,10 @@ const variantPlugins = {
}
},

// Twin feature
lightVariants({ config, addVariant }) {
let [mode, className = '.light'] = [
config('lightMode') || config('darkMode') || 'media',
]

if (mode === false) {
mode = 'media'
console.warn('lightmode-false', [
'The `lightMode` option in your Tailwind CSS configuration is set to `false`, which now behaves the same as `media`.',
'Change `lightMode` to `media` or remove it entirely.',
'https://tailwindcss.com/docs/upgrade-guide#remove-dark-mode-configuration',
])
}
// eslint-disable-next-line unicorn/prefer-spread
const [mode, className = '.light'] = [].concat(config('lightMode', 'media'))

if (mode === 'class') {
addVariant('light', `${className} &`)
Expand Down

0 comments on commit b59e93e

Please sign in to comment.