Merge pull request #581 from tailwindcss/custom-modules-all

Allow modules: [...variants] syntax to bulk apply variants
This commit is contained in:
Adam Wathan 2018-11-01 21:52:01 -04:00 committed by GitHub
commit 62bc6079d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -80,6 +80,33 @@ test('setting modules to "all" creates all variants for all modules', () => {
})
})
test('setting modules to an array of variants applies those variants to all modules', () => {
const userConfig = {
modules: ['responsive', 'focus', 'hover', 'custom-variant'],
options: {},
}
const defaultConfig = {
modules: {
flexbox: ['responsive'],
textAlign: ['hover'],
textColors: ['focus'],
},
options: {},
}
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
expect(result).toEqual({
modules: {
flexbox: ['responsive', 'focus', 'hover', 'custom-variant'],
textAlign: ['responsive', 'focus', 'hover', 'custom-variant'],
textColors: ['responsive', 'focus', 'hover', 'custom-variant'],
},
options: {},
})
})
test('user options are merged with default options', () => {
const userConfig = {
modules: {},

View File

@ -1,6 +1,10 @@
import _ from 'lodash'
function mergeModules(userModules, defaultModules) {
if (_.isArray(userModules)) {
return _.mapValues(defaultModules, () => userModules)
}
if (userModules === 'all') {
return _.mapValues(defaultModules, () => [
'responsive',