Skip to content

Commit

Permalink
Merge pull request #911 from tailwindcss/fix-global-variants
Browse files Browse the repository at this point in the history
Fix global variants not working when configs are merged
  • Loading branch information
adamwathan committed May 13, 2019
2 parents 7e7b6d9 + 0183b86 commit fa17b48
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
64 changes: 64 additions & 0 deletions __tests__/resolveConfig.test.js
Expand Up @@ -261,6 +261,70 @@ test('variants key is merged instead of replaced', () => {
})
})

test('a global variants list replaces the default', () => {
const userConfig = {
variants: ['responsive', 'hover', 'focus', 'active'],
}

const defaultConfig = {
prefix: '-',
important: false,
separator: ':',
theme: {
colors: {
'grey-darker': '#606f7b',
'grey-dark': '#8795a1',
grey: '#b8c2cc',
'grey-light': '#dae1e7',
'grey-lighter': '#f1f5f8',
},
fonts: {
sans: ['system-ui', 'BlinkMacSystemFont', '-apple-system', 'Roboto', 'sans-serif'],
serif: ['Constantia', 'Lucida Bright', 'Georgia', 'serif'],
},
screens: {
sm: '500px',
md: '750px',
lg: '1000px',
},
},
variants: {
appearance: ['responsive'],
backgroundAttachment: ['responsive'],
borderCollapse: [],
borderColors: ['responsive', 'hover', 'focus'],
borderRadius: ['responsive'],
},
}

const result = resolveConfig([userConfig, defaultConfig])

expect(result).toEqual({
prefix: '-',
important: false,
separator: ':',
theme: {
colors: {
'grey-darker': '#606f7b',
'grey-dark': '#8795a1',
grey: '#b8c2cc',
'grey-light': '#dae1e7',
'grey-lighter': '#f1f5f8',
},
fonts: {
sans: ['system-ui', 'BlinkMacSystemFont', '-apple-system', 'Roboto', 'sans-serif'],
serif: ['Constantia', 'Lucida Bright', 'Georgia', 'serif'],
},
screens: {
sm: '500px',
md: '750px',
lg: '1000px',
},
},
variants: ['responsive', 'hover', 'focus', 'active'],
})
})

test('missing top level keys are pulled from the default config', () => {
const userConfig = {}

Expand Down
6 changes: 5 additions & 1 deletion src/util/resolveConfig.js
Expand Up @@ -65,7 +65,11 @@ export default function resolveConfig(configs) {
return defaults(
{
theme: resolveFunctionKeys(mergeExtensions(defaults({}, ...map(configs, 'theme')))),
variants: defaults({}, ...map(configs, 'variants')),
variants: (firstVariants => {
return Array.isArray(firstVariants)
? firstVariants
: defaults({}, ...map(configs, 'variants'))
})(defaults({}, ...map(configs)).variants),
},
...configs
)
Expand Down

0 comments on commit fa17b48

Please sign in to comment.