Unify config helpers into single object (#5382)

Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>

Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
This commit is contained in:
Jonathan Reinink 2021-09-03 10:31:19 -04:00 • committed by GitHub
parent e37931ba65
commit 4f89215d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View file

@ -123,6 +123,12 @@ function resolveFunctionKeys(object) {
return val === undefined ? defaultValue : val
}
resolvePath.theme = resolvePath
for (let key in configUtils) {
resolvePath[key] = configUtils[key]
}
return Object.keys(object).reduce((resolved, key) => {
return {
...resolved,

View file

@ -2215,3 +2215,62 @@ test('plugins are merged', () => {
plugins: ['1', '2', '3'],
})
})
test('all helpers can be destructured from the first function argument', () => {
const userConfig = {
theme: {
example: ({ theme, colors, negative, breakpoints }) => ({
weight: theme('fontWeight.bold'),
black: colors.black,
white: colors.white,
...negative(theme('spacing')),
...breakpoints(theme('screens')),
}),
},
}
const defaultConfig = {
prefix: '-',
important: false,
separator: ':',
theme: {
screens: {
sm: '640px',
md: '768px',
},
fontWeight: {
bold: 700,
},
spacing: {
0: '0px',
1: '1px',
2: '2px',
3: '3px',
4: '4px',
},
},
variants: {},
}
const result = resolveConfig([userConfig, defaultConfig])
expect(result).toMatchObject({
prefix: '-',
important: false,
separator: ':',
theme: {
example: {
weight: 700,
black: '#000',
white: '#fff',
'-1': '-1px',
'-2': '-2px',
'-3': '-3px',
'-4': '-4px',
'screen-sm': '640px',
'screen-md': '768px',
},
},
variants: {},
})
})