Skip to content

Commit 76691a5

Browse files
committed
Allow modules: [...variants] syntax to bulk apply variants
1 parent 0ca7f7a commit 76691a5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

__tests__/mergeConfigWithDefaults.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ test('setting modules to "all" creates all variants for all modules', () => {
8080
})
8181
})
8282

83+
test('setting modules to an array of variants applies those variants to all modules', () => {
84+
const userConfig = {
85+
modules: ['responsive', 'focus', 'hover', 'custom-variant'],
86+
options: {},
87+
}
88+
89+
const defaultConfig = {
90+
modules: {
91+
flexbox: ['responsive'],
92+
textAlign: ['hover'],
93+
textColors: ['focus'],
94+
},
95+
options: {},
96+
}
97+
98+
const result = mergeConfigWithDefaults(userConfig, defaultConfig)
99+
100+
expect(result).toEqual({
101+
modules: {
102+
flexbox: ['responsive', 'focus', 'hover', 'custom-variant'],
103+
textAlign: ['responsive', 'focus', 'hover', 'custom-variant'],
104+
textColors: ['responsive', 'focus', 'hover', 'custom-variant'],
105+
},
106+
options: {},
107+
})
108+
})
109+
83110
test('user options are merged with default options', () => {
84111
const userConfig = {
85112
modules: {},

src/util/mergeConfigWithDefaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import _ from 'lodash'
22

33
function mergeModules(userModules, defaultModules) {
4+
if (_.isArray(userModules)) {
5+
return _.mapValues(defaultModules, () => userModules)
6+
}
7+
48
if (userModules === 'all') {
59
return _.mapValues(defaultModules, () => [
610
'responsive',

0 commit comments

Comments
 (0)