Skip to content

Commit 4f89215

Browse files
reininkadamwathan
andauthored
Unify config helpers into single object (tailwindlabs#5382)
Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com> Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
1 parent e37931b commit 4f89215

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/util/resolveConfig.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ function resolveFunctionKeys(object) {
123123
return val === undefined ? defaultValue : val
124124
}
125125

126+
resolvePath.theme = resolvePath
127+
128+
for (let key in configUtils) {
129+
resolvePath[key] = configUtils[key]
130+
}
131+
126132
return Object.keys(object).reduce((resolved, key) => {
127133
return {
128134
...resolved,

tests/resolveConfig.test.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,3 +2215,62 @@ test('plugins are merged', () => {
22152215
plugins: ['1', '2', '3'],
22162216
})
22172217
})
2218+
2219+
test('all helpers can be destructured from the first function argument', () => {
2220+
const userConfig = {
2221+
theme: {
2222+
example: ({ theme, colors, negative, breakpoints }) => ({
2223+
weight: theme('fontWeight.bold'),
2224+
black: colors.black,
2225+
white: colors.white,
2226+
...negative(theme('spacing')),
2227+
...breakpoints(theme('screens')),
2228+
}),
2229+
},
2230+
}
2231+
2232+
const defaultConfig = {
2233+
prefix: '-',
2234+
important: false,
2235+
separator: ':',
2236+
theme: {
2237+
screens: {
2238+
sm: '640px',
2239+
md: '768px',
2240+
},
2241+
fontWeight: {
2242+
bold: 700,
2243+
},
2244+
spacing: {
2245+
0: '0px',
2246+
1: '1px',
2247+
2: '2px',
2248+
3: '3px',
2249+
4: '4px',
2250+
},
2251+
},
2252+
variants: {},
2253+
}
2254+
2255+
const result = resolveConfig([userConfig, defaultConfig])
2256+
2257+
expect(result).toMatchObject({
2258+
prefix: '-',
2259+
important: false,
2260+
separator: ':',
2261+
theme: {
2262+
example: {
2263+
weight: 700,
2264+
black: '#000',
2265+
white: '#fff',
2266+
'-1': '-1px',
2267+
'-2': '-2px',
2268+
'-3': '-3px',
2269+
'-4': '-4px',
2270+
'screen-sm': '640px',
2271+
'screen-md': '768px',
2272+
},
2273+
},
2274+
variants: {},
2275+
})
2276+
})

0 commit comments

Comments
 (0)