Skip to content

Commit

Permalink
Unify config helpers into single object (#5382)
Browse files Browse the repository at this point in the history
Co-Authored-By: Adam Wathan <[email protected]>

Co-authored-by: Adam Wathan <[email protected]>
  • Loading branch information
reinink and adamwathan authored Sep 3, 2021
1 parent e37931b commit 4f89215
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/util/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
59 changes: 59 additions & 0 deletions tests/resolveConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
})
})

0 comments on commit 4f89215

Please sign in to comment.