Skip to content

Commit 3635778

Browse files
authored
Partially revert tuple syntax PR for screens: #6104 (#6289)
* partially revert tuple syntax PR for `screens`: #6104 * update changelog
1 parent dd06552 commit 3635778

File tree

5 files changed

+7
-123
lines changed

5 files changed

+7
-123
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
### Changed
3030

3131
- Deprecate `decoration-slice` and `decoration-break` in favor `box-decoration-slice` and `box-decoration-break` _(non-breaking)_ ([#6004](https://github.com/tailwindlabs/tailwindcss/pull/6004))
32+
- Removed tuple syntax for `screens` ([#6289](https://github.com/tailwindlabs/tailwindcss/pull/6289))
3233

3334
## [3.0.0-alpha.2] - 2021-11-08
3435

src/util/normalizeScreens.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
* - { sm: '100px', md: '200px' } // Object with string values
88
* - { sm: { min: '100px' }, md: { max: '100px' } } // Object with object values
99
* - { sm: [{ min: '100px' }, { max: '200px' }] } // Object with object array (multiple values)
10-
* - [['sm', '100px'], ['md', '200px']] // Tuple object
1110
*
1211
* Output(s):
1312
* - [{ name: 'sm', values: [{ min: '100px', max: '200px' }] }] // List of objects, that contains multiple values
1413
*/
15-
export function normalizeScreens(screens) {
14+
export function normalizeScreens(screens, root = true) {
1615
if (Array.isArray(screens)) {
1716
return screens.map((screen) => {
17+
if (root && Array.isArray(screen)) {
18+
throw new Error('The tuple syntax is not supported for `screens`.')
19+
}
20+
1821
if (typeof screen === 'string') {
1922
return { name: screen.toString(), values: [{ min: screen, max: undefined }] }
2023
}
@@ -34,7 +37,7 @@ export function normalizeScreens(screens) {
3437
})
3538
}
3639

37-
return normalizeScreens(Object.entries(screens ?? {}))
40+
return normalizeScreens(Object.entries(screens ?? {}), false)
3841
}
3942

4043
function resolveValue({ 'min-width': _minWidth, min = _minWidth, max, raw } = {}) {

tests/containerPlugin.test.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -343,39 +343,3 @@ test('container can use variants', () => {
343343
`)
344344
})
345345
})
346-
347-
test('container can use screens with tuple syntax', () => {
348-
let config = {
349-
content: [{ raw: html`<div class="container"></div>` }],
350-
theme: {
351-
screens: [
352-
[1800, { min: '1800px' }],
353-
[1200, { min: '1200px' }],
354-
[768, { min: '768px' }],
355-
],
356-
},
357-
}
358-
359-
return run('@tailwind components', config).then((result) => {
360-
expect(result.css).toMatchFormattedCss(css`
361-
.container {
362-
width: 100%;
363-
}
364-
@media (min-width: 768px) {
365-
.container {
366-
max-width: 768px;
367-
}
368-
}
369-
@media (min-width: 1200px) {
370-
.container {
371-
max-width: 1200px;
372-
}
373-
}
374-
@media (min-width: 1800px) {
375-
.container {
376-
max-width: 1800px;
377-
}
378-
}
379-
`)
380-
})
381-
})

tests/normalize-screens.test.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,39 +60,3 @@ it('should normalize an object with object values (min-width normalized to width
6060
{ name: 'b', values: [{ min: undefined, max: '1200px' }] },
6161
])
6262
})
63-
64-
it('should normalize a tuple with string values', () => {
65-
let screens = [
66-
['a', '768px'],
67-
['b', '1200px'],
68-
]
69-
70-
expect(normalizeScreens(screens)).toEqual([
71-
{ name: 'a', values: [{ min: '768px', max: undefined }] },
72-
{ name: 'b', values: [{ min: '1200px', max: undefined }] },
73-
])
74-
})
75-
76-
it('should normalize a tuple with object values', () => {
77-
let screens = [
78-
['a', { min: '768px' }],
79-
['b', { max: '1200px' }],
80-
]
81-
82-
expect(normalizeScreens(screens)).toEqual([
83-
{ name: 'a', values: [{ min: '768px', max: undefined }] },
84-
{ name: 'b', values: [{ min: undefined, max: '1200px' }] },
85-
])
86-
})
87-
88-
it('should normalize a tuple with object values (min-width normalized to width)', () => {
89-
let screens = [
90-
['a', { 'min-width': '768px' }],
91-
['b', { max: '1200px' }],
92-
]
93-
94-
expect(normalizeScreens(screens)).toEqual([
95-
{ name: 'a', values: [{ min: '768px', max: undefined }] },
96-
{ name: 'b', values: [{ min: undefined, max: '1200px' }] },
97-
])
98-
})

tests/tailwind-screens.test.js

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,51 +65,3 @@ test('`@tailwind screens` works as an alias for `@tailwind variants`', async ()
6565
`)
6666
})
6767
})
68-
69-
test('screen names are in the correct order', () => {
70-
// Using custom css function here, because otherwise with String.raw, we run
71-
// into an issue with `\31 ` escapes. If we use `\31 ` then JS complains
72-
// about strict mode. But `\\31 ` is not what it expected.
73-
function css(templates) {
74-
return templates.join('')
75-
}
76-
77-
let config = {
78-
content: [
79-
{
80-
raw: html`<div
81-
class="768:font-light 1200:font-normal 1800:font-bold max-w-768 container"
82-
></div>`,
83-
},
84-
],
85-
theme: {
86-
screens: [
87-
[1800, { max: '1800px' }],
88-
[1200, { max: '1200px' }],
89-
[768, { max: '768px' }],
90-
],
91-
},
92-
}
93-
94-
return run('@tailwind utilities;', config).then((result) => {
95-
return expect(result.css).toMatchFormattedCss(css`
96-
@media (max-width: 1800px) {
97-
.\\31 800\\:font-bold {
98-
font-weight: 700;
99-
}
100-
}
101-
102-
@media (max-width: 1200px) {
103-
.\\31 200\\:font-normal {
104-
font-weight: 400;
105-
}
106-
}
107-
108-
@media (max-width: 768px) {
109-
.\\37 68\\:font-light {
110-
font-weight: 300;
111-
}
112-
}
113-
`)
114-
})
115-
})

0 commit comments

Comments
 (0)