Skip to content

Commit 9959b1f

Browse files
committed
Add first-class support for "responsive" components and bucket children
1 parent 658250a commit 9959b1f

File tree

8 files changed

+501
-68
lines changed

8 files changed

+501
-68
lines changed

__tests__/processPlugins.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,62 @@ test("component declarations can optionally ignore 'prefix' option", () => {
11141114
`)
11151115
})
11161116

1117+
test('responsive components are generated with the components at-rule argument', () => {
1118+
const { components } = processPlugins(
1119+
[
1120+
function({ addComponents }) {
1121+
addComponents(
1122+
{
1123+
'.btn-blue': {
1124+
backgroundColor: 'blue',
1125+
},
1126+
},
1127+
{ variants: ['responsive'] }
1128+
)
1129+
},
1130+
],
1131+
makeConfig()
1132+
)
1133+
1134+
expect(css(components)).toMatchCss(`
1135+
@responsive components {
1136+
@variants {
1137+
.btn-blue {
1138+
background-color: blue
1139+
}
1140+
}
1141+
}
1142+
`)
1143+
})
1144+
1145+
test('components can use the array shorthand to add variants', () => {
1146+
const { components } = processPlugins(
1147+
[
1148+
function({ addComponents }) {
1149+
addComponents(
1150+
{
1151+
'.btn-blue': {
1152+
backgroundColor: 'blue',
1153+
},
1154+
},
1155+
['responsive']
1156+
)
1157+
},
1158+
],
1159+
makeConfig()
1160+
)
1161+
1162+
expect(css(components)).toMatchCss(`
1163+
@responsive components {
1164+
@variants {
1165+
.btn-blue {
1166+
background-color: blue
1167+
}
1168+
}
1169+
}
1170+
`)
1171+
})
1172+
11171173
test("component declarations are not affected by the 'important' option", () => {
11181174
const { components } = processPlugins(
11191175
[

__tests__/responsiveAtRule.test.js

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('it can generate responsive variants', () => {
1313
.chocolate { color: brown; }
1414
}
1515
16-
@tailwind screens;
16+
@screens utilities;
1717
`
1818

1919
const output = `
@@ -55,7 +55,7 @@ test('it can generate responsive variants with a custom separator', () => {
5555
.chocolate { color: brown; }
5656
}
5757
58-
@tailwind screens;
58+
@screens utilities;
5959
`
6060

6161
const output = `
@@ -97,7 +97,7 @@ test('it can generate responsive variants when classes have non-standard charact
9797
.chocolate-2\\.5 { color: brown; }
9898
}
9999
100-
@tailwind screens;
100+
@screens utilities;
101101
`
102102

103103
const output = `
@@ -144,7 +144,7 @@ test('responsive variants are grouped', () => {
144144
.chocolate { color: brown; }
145145
}
146146
147-
@tailwind screens;
147+
@screens utilities;
148148
`
149149

150150
const output = `
@@ -190,7 +190,7 @@ test('it can generate responsive variants for nested at-rules', () => {
190190
}
191191
}
192192
193-
@tailwind screens;
193+
@screens utilities;
194194
`
195195

196196
const output = `
@@ -255,7 +255,7 @@ test('it can generate responsive variants for deeply nested at-rules', () => {
255255
}
256256
}
257257
258-
@tailwind screens;
258+
@screens utilities;
259259
`
260260

261261
const output = `
@@ -320,7 +320,7 @@ test('screen prefix is only applied to the last class in a selector', () => {
320320
.banana li * .sandwich #foo > div { color: yellow; }
321321
}
322322
323-
@tailwind screens;
323+
@screens utilities;
324324
`
325325

326326
const output = `
@@ -357,7 +357,7 @@ test('responsive variants are generated for all selectors in a rule', () => {
357357
.foo, .bar { color: yellow; }
358358
}
359359
360-
@tailwind screens;
360+
@screens utilities;
361361
`
362362

363363
const output = `
@@ -394,7 +394,7 @@ test('selectors with no classes cannot be made responsive', () => {
394394
div { color: yellow; }
395395
}
396396
397-
@tailwind screens;
397+
@screens utilities;
398398
`
399399
expect.assertions(1)
400400
return run(input, {
@@ -417,7 +417,7 @@ test('all selectors in a rule must contain classes', () => {
417417
.foo, div { color: yellow; }
418418
}
419419
420-
@tailwind screens;
420+
@screens utilities;
421421
`
422422
expect.assertions(1)
423423
return run(input, {
@@ -433,3 +433,59 @@ test('all selectors in a rule must contain classes', () => {
433433
expect(e).toMatchObject({ name: 'CssSyntaxError' })
434434
})
435435
})
436+
437+
test('responsive components are inserted at @screens components', () => {
438+
const input = `
439+
@responsive components {
440+
.banana { color: yellow; }
441+
}
442+
443+
.apple { color: red; }
444+
445+
@screens components;
446+
447+
@responsive {
448+
.chocolate { color: brown; }
449+
}
450+
451+
@screens utilities;
452+
`
453+
454+
const output = `
455+
.banana { color: yellow; }
456+
.apple { color: red; }
457+
@media (min-width: 500px) {
458+
.sm\\:banana { color: yellow; }
459+
}
460+
@media (min-width: 750px) {
461+
.md\\:banana { color: yellow; }
462+
}
463+
@media (min-width: 1000px) {
464+
.lg\\:banana { color: yellow; }
465+
}
466+
.chocolate { color: brown; }
467+
@media (min-width: 500px) {
468+
.sm\\:chocolate { color: brown; }
469+
}
470+
@media (min-width: 750px) {
471+
.md\\:chocolate { color: brown; }
472+
}
473+
@media (min-width: 1000px) {
474+
.lg\\:chocolate { color: brown; }
475+
}
476+
`
477+
478+
return run(input, {
479+
theme: {
480+
screens: {
481+
sm: '500px',
482+
md: '750px',
483+
lg: '1000px',
484+
},
485+
},
486+
separator: ':',
487+
}).then(result => {
488+
expect(result.css).toMatchCss(output)
489+
expect(result.warnings().length).toBe(0)
490+
})
491+
})

0 commit comments

Comments
 (0)