Skip to content

Commit b932772

Browse files
committed
Add variants support to container plugin
1 parent 9310efb commit b932772

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed

__tests__/containerPlugin.test.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function config(overrides) {
2121
})
2222
}
2323

24-
test.only('options are not required', () => {
24+
test('options are not required', () => {
2525
const { components } = processPlugins([container()], config())
2626

2727
expect(css(components)).toMatchCss(`
@@ -45,7 +45,7 @@ test.only('options are not required', () => {
4545
`)
4646
})
4747

48-
test.only('screens can be passed explicitly', () => {
48+
test('screens can be passed explicitly', () => {
4949
const { components } = processPlugins(
5050
[container()],
5151
config({
@@ -72,7 +72,7 @@ test.only('screens can be passed explicitly', () => {
7272
`)
7373
})
7474

75-
test.only('screens are ordered ascending by min-width', () => {
75+
test('screens are ordered ascending by min-width', () => {
7676
const { components } = processPlugins(
7777
[container()],
7878
config({
@@ -99,7 +99,7 @@ test.only('screens are ordered ascending by min-width', () => {
9999
`)
100100
})
101101

102-
test.only('screens are deduplicated by min-width', () => {
102+
test('screens are deduplicated by min-width', () => {
103103
const { components } = processPlugins(
104104
[container()],
105105
config({
@@ -130,7 +130,7 @@ test.only('screens are deduplicated by min-width', () => {
130130
`)
131131
})
132132

133-
test.only('the container can be centered by default', () => {
133+
test('the container can be centered by default', () => {
134134
const { components } = processPlugins(
135135
[container()],
136136
config({
@@ -167,7 +167,7 @@ test.only('the container can be centered by default', () => {
167167
`)
168168
})
169169

170-
test.only('horizontal padding can be included by default', () => {
170+
test('horizontal padding can be included by default', () => {
171171
const { components } = processPlugins(
172172
[container()],
173173
config({
@@ -204,7 +204,7 @@ test.only('horizontal padding can be included by default', () => {
204204
`)
205205
})
206206

207-
test.only('responsive horizontal padding can be included by default', () => {
207+
test('responsive horizontal padding can be included by default', () => {
208208
const { components } = processPlugins(
209209
[container()],
210210
config({
@@ -258,7 +258,7 @@ test.only('responsive horizontal padding can be included by default', () => {
258258
`)
259259
})
260260

261-
test.only('setting all options at once', () => {
261+
test('setting all options at once', () => {
262262
const { components } = processPlugins(
263263
[container()],
264264
config({
@@ -292,3 +292,39 @@ test.only('setting all options at once', () => {
292292
}
293293
`)
294294
})
295+
296+
test('container can use variants', () => {
297+
const { components } = processPlugins(
298+
[container()],
299+
config({
300+
theme: {
301+
container: {
302+
screens: ['400px', '500px'],
303+
},
304+
},
305+
variants: {
306+
container: ['responsive', 'hover'],
307+
},
308+
})
309+
)
310+
311+
expect(css(components)).toMatchCss(`
312+
@layer components {
313+
@variants responsive, hover {
314+
.container {
315+
width: 100%
316+
}
317+
@media (min-width: 400px) {
318+
.container {
319+
max-width: 400px
320+
}
321+
}
322+
@media (min-width: 500px) {
323+
.container {
324+
max-width: 500px
325+
}
326+
}
327+
}
328+
}
329+
`)
330+
})

src/plugins/container.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function mapMinWidthsToPadding(minWidths, screens, paddings) {
6363
}
6464

6565
module.exports = function() {
66-
return function({ addComponents, theme }) {
66+
return function({ addComponents, theme, variants }) {
6767
const screens = theme('container.screens', theme('screens'))
6868
const minWidths = extractMinWidths(screens)
6969
const paddings = mapMinWidthsToPadding(minWidths, screens, theme('container.padding'))
@@ -96,15 +96,18 @@ module.exports = function() {
9696
})
9797
.value()
9898

99-
addComponents([
100-
{
101-
'.container': Object.assign(
102-
{ width: '100%' },
103-
theme('container.center', false) ? { marginRight: 'auto', marginLeft: 'auto' } : {},
104-
generatePaddingFor(0)
105-
),
106-
},
107-
...atRules,
108-
])
99+
addComponents(
100+
[
101+
{
102+
'.container': Object.assign(
103+
{ width: '100%' },
104+
theme('container.center', false) ? { marginRight: 'auto', marginLeft: 'auto' } : {},
105+
generatePaddingFor(0)
106+
),
107+
},
108+
...atRules,
109+
],
110+
variants('container')
111+
)
109112
}
110113
}

0 commit comments

Comments
 (0)