Skip to content

Commit

Permalink
Merge pull request tailwindlabs#908 from stidges/fix-container-screens
Browse files Browse the repository at this point in the history
Fix container plugin screen order and duplication
  • Loading branch information
adamwathan authored May 13, 2019
2 parents 9c91b9a + 4cbe959 commit 6c2f3b9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
50 changes: 50 additions & 0 deletions __tests__/containerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,56 @@ test.only('screens can be passed explicitly', () => {
`)
})

test.only('screens are ordered ascending by min-width', () => {
const { components } = processPlugins(
[container()],
config({
theme: {
container: {
screens: ['500px', '400px'],
},
},
})
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
@media (min-width: 400px) {
.container { max-width: 400px }
}
@media (min-width: 500px) {
.container { max-width: 500px }
}
`)
})

test.only('screens are deduplicated by min-width', () => {
const { components } = processPlugins(
[container()],
config({
theme: {
container: {
screens: {
sm: '576px',
md: '768px',
'sm-only': { min: '576px', max: '767px' },
},
},
},
})
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
@media (min-width: 576px) {
.container { max-width: 576px }
}
@media (min-width: 768px) {
.container { max-width: 768px }
}
`)
})

test.only('the container can be centered by default', () => {
const { components } = processPlugins(
[container()],
Expand Down
20 changes: 12 additions & 8 deletions src/plugins/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ module.exports = function() {
return function({ addComponents, theme }) {
const minWidths = extractMinWidths(theme('container.screens', theme('screens')))

const atRules = _.map(minWidths, minWidth => {
return {
[`@media (min-width: ${minWidth})`]: {
'.container': {
'max-width': minWidth,
const atRules = _(minWidths)
.sortBy(minWidth => parseInt(minWidth))
.sortedUniq()
.map(minWidth => {
return {
[`@media (min-width: ${minWidth})`]: {
'.container': {
'max-width': minWidth,
},
},
},
}
})
}
})
.value()

addComponents([
{
Expand Down

0 comments on commit 6c2f3b9

Please sign in to comment.