Skip to content

Commit b299b6f

Browse files
authored
Support new presets key + extending core plugins config (#2474)
* WIP * Support array for Tailwind config * Drop array format for `presets` key instead * Update changelog
1 parent 427299e commit b299b6f

14 files changed

+345
-166
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add experimental `2xl` breakpoint ([#2468](https://github.com/tailwindlabs/tailwindcss/pull/2468))
1313
- Add `col-span-full` and `row-span-full` ([#2471](https://github.com/tailwindlabs/tailwindcss/pull/2471))
1414
- Promote `defaultLineHeights` and `standardFontWeights` from experimental to future
15+
- Add new `presets` config option ([#2474](https://github.com/tailwindlabs/tailwindcss/pull/2474))
1516

1617
## [1.8.12] - 2020-10-07
1718

__tests__/configurePlugins.test.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import configurePlugins from '../src/util/configurePlugins'
22

33
test('setting a plugin to false removes it', () => {
4-
const plugins = {
5-
fontSize: () => 'fontSize',
6-
display: () => 'display',
7-
backgroundPosition: () => 'backgroundPosition',
8-
}
4+
const plugins = ['fontSize', 'display', 'backgroundPosition']
95

106
const configuredPlugins = configurePlugins(
117
{
@@ -18,23 +14,15 @@ test('setting a plugin to false removes it', () => {
1814
})
1915

2016
test('passing only false removes all plugins', () => {
21-
const plugins = {
22-
fontSize: () => 'fontSize',
23-
display: () => 'display',
24-
backgroundPosition: () => 'backgroundPosition',
25-
}
17+
const plugins = ['fontSize', 'display', 'backgroundPosition']
2618

2719
const configuredPlugins = configurePlugins(false, plugins)
2820

2921
expect(configuredPlugins).toEqual([])
3022
})
3123

3224
test('passing an array whitelists plugins', () => {
33-
const plugins = {
34-
fontSize: () => 'fontSize',
35-
display: () => 'display',
36-
backgroundPosition: () => 'backgroundPosition',
37-
}
25+
const plugins = ['fontSize', 'display', 'backgroundPosition']
3826

3927
const configuredPlugins = configurePlugins(['display'], plugins)
4028

__tests__/customConfig.test.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,107 @@ test('tailwind.config.js is picked up by default when passing an empty object',
210210
})
211211
})
212212
})
213+
214+
test('the default config can be overridden using the presets key', () => {
215+
return postcss([
216+
tailwind({
217+
presets: [
218+
{
219+
theme: {
220+
extend: {
221+
colors: {
222+
black: 'black',
223+
},
224+
backgroundColor: theme => theme('colors'),
225+
},
226+
},
227+
corePlugins: ['backgroundColor'],
228+
},
229+
],
230+
theme: {
231+
extend: { colors: { white: 'white' } },
232+
},
233+
}),
234+
])
235+
.process(
236+
`
237+
@tailwind utilities
238+
`,
239+
{ from: undefined }
240+
)
241+
.then(result => {
242+
const expected = `
243+
.bg-black {
244+
background-color: black;
245+
}
246+
.bg-white {
247+
background-color: white;
248+
}
249+
`
250+
251+
expect(result.css).toMatchCss(expected)
252+
})
253+
})
254+
255+
test('presets can have their own presets', () => {
256+
return postcss([
257+
tailwind({
258+
presets: [
259+
{
260+
theme: {
261+
colors: { red: '#dd0000' },
262+
},
263+
},
264+
{
265+
presets: [
266+
{
267+
theme: {
268+
colors: {
269+
transparent: 'transparent',
270+
red: '#ff0000',
271+
},
272+
},
273+
},
274+
],
275+
theme: {
276+
extend: {
277+
colors: {
278+
black: 'black',
279+
red: '#ee0000',
280+
},
281+
backgroundColor: theme => theme('colors'),
282+
},
283+
},
284+
corePlugins: ['backgroundColor'],
285+
},
286+
],
287+
theme: {
288+
extend: { colors: { white: 'white' } },
289+
},
290+
}),
291+
])
292+
.process(
293+
`
294+
@tailwind utilities
295+
`,
296+
{ from: undefined }
297+
)
298+
.then(result => {
299+
const expected = `
300+
.bg-transparent {
301+
background-color: transparent;
302+
}
303+
.bg-red {
304+
background-color: #ee0000;
305+
}
306+
.bg-black {
307+
background-color: black;
308+
}
309+
.bg-white {
310+
background-color: white;
311+
}
312+
`
313+
314+
expect(result.css).toMatchCss(expected)
315+
})
316+
})

0 commit comments

Comments
 (0)