Skip to content

Commit f3db5f1

Browse files
authored
Merge pull request #765 from tailwindcss/make-container-core
Make container plugin a core plugin, configured in theme
2 parents 49d852c + fefc53b commit f3db5f1

File tree

6 files changed

+47
-69
lines changed

6 files changed

+47
-69
lines changed

__tests__/cli.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ describe('cli', () => {
3030
it('creates a Tailwind config file without comments', () => {
3131
return cli(['init', '--no-comments']).then(() => {
3232
expect(utils.writeFile.mock.calls[0][1]).not.toContain('/**')
33-
expect(utils.writeFile.mock.calls[0][1]).toContain('//')
3433
})
3534
})
3635
})

__tests__/containerPlugin.test.js

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,16 @@ test.only('options are not required', () => {
4141
`)
4242
})
4343

44-
test.only('screens can be specified explicitly', () => {
44+
test.only('screens can be passed explicitly', () => {
4545
const { components } = processPlugins(
46-
[
47-
container({
48-
screens: {
49-
sm: '400px',
50-
lg: '500px',
46+
[container()],
47+
config({
48+
theme: {
49+
container: {
50+
screens: ['400px', '500px'],
5151
},
52-
}),
53-
],
54-
config()
55-
)
56-
57-
expect(css(components)).toMatchCss(`
58-
.container { width: 100% }
59-
@media (min-width: 400px) {
60-
.container { max-width: 400px }
61-
}
62-
@media (min-width: 500px) {
63-
.container { max-width: 500px }
64-
}
65-
`)
66-
})
67-
68-
test.only('screens can be an array', () => {
69-
const { components } = processPlugins(
70-
[
71-
container({
72-
screens: ['400px', '500px'],
73-
}),
74-
],
75-
config()
52+
},
53+
})
7654
)
7755

7856
expect(css(components)).toMatchCss(`
@@ -88,12 +66,14 @@ test.only('screens can be an array', () => {
8866

8967
test.only('the container can be centered by default', () => {
9068
const { components } = processPlugins(
91-
[
92-
container({
93-
center: true,
94-
}),
95-
],
96-
config()
69+
[container()],
70+
config({
71+
theme: {
72+
container: {
73+
center: true,
74+
},
75+
},
76+
})
9777
)
9878

9979
expect(css(components)).toMatchCss(`
@@ -119,12 +99,14 @@ test.only('the container can be centered by default', () => {
11999

120100
test.only('horizontal padding can be included by default', () => {
121101
const { components } = processPlugins(
122-
[
123-
container({
124-
padding: '2rem',
125-
}),
126-
],
127-
config()
102+
[container()],
103+
config({
104+
theme: {
105+
container: {
106+
padding: '2rem',
107+
},
108+
},
109+
})
128110
)
129111

130112
expect(css(components)).toMatchCss(`
@@ -150,17 +132,16 @@ test.only('horizontal padding can be included by default', () => {
150132

151133
test.only('setting all options at once', () => {
152134
const { components } = processPlugins(
153-
[
154-
container({
155-
screens: {
156-
sm: '400px',
157-
lg: '500px',
135+
[container()],
136+
config({
137+
theme: {
138+
container: {
139+
screens: ['400px', '500px'],
140+
center: true,
141+
padding: '2rem',
158142
},
159-
center: true,
160-
padding: '2rem',
161-
}),
162-
],
163-
config()
143+
},
144+
})
164145
)
165146

166147
expect(css(components)).toMatchCss(`

defaultConfig.stub.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ module.exports = {
7070
width: ['responsive'],
7171
zIndex: ['responsive'],
7272
},
73-
corePlugins: {
74-
},
75-
plugins: [
76-
require('./plugins/container')({
77-
// center: true,
78-
// padding: '1rem',
79-
}),
80-
],
73+
corePlugins: {},
74+
plugins: [],
8175
}

plugins/container.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/corePlugins.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import preflight from './plugins/preflight'
2+
import container from './plugins/container'
23
import appearance from './plugins/appearance'
34
import backgroundAttachment from './plugins/backgroundAttachment'
45
import backgroundColor from './plugins/backgroundColor'
@@ -68,6 +69,7 @@ import configurePlugins from './util/configurePlugins'
6869
export default function({ corePlugins: corePluginConfig }) {
6970
return configurePlugins(corePluginConfig, {
7071
preflight,
72+
container,
7173
appearance,
7274
backgroundAttachment,
7375
backgroundColor,

src/plugins/container.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ function extractMinWidths(breakpoints) {
2222
})
2323
}
2424

25-
module.exports = function(options) {
25+
module.exports = function() {
2626
return function({ addComponents, config }) {
27-
const screens = _.get(options, 'screens', config('theme.screens'))
28-
29-
const minWidths = extractMinWidths(screens)
27+
const minWidths = extractMinWidths(config('theme.container.screens', config('theme.screens')))
3028

3129
const atRules = _.map(minWidths, minWidth => {
3230
return {
@@ -42,9 +40,14 @@ module.exports = function(options) {
4240
{
4341
'.container': Object.assign(
4442
{ width: '100%' },
45-
_.get(options, 'center', false) ? { marginRight: 'auto', marginLeft: 'auto' } : {},
46-
_.has(options, 'padding')
47-
? { paddingRight: options.padding, paddingLeft: options.padding }
43+
config('theme.container.center', false)
44+
? { marginRight: 'auto', marginLeft: 'auto' }
45+
: {},
46+
_.has(config('theme.container', {}), 'padding')
47+
? {
48+
paddingRight: config('theme.container.padding'),
49+
paddingLeft: config('theme.container.padding'),
50+
}
4851
: {}
4952
),
5053
},

0 commit comments

Comments
 (0)