Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix container plugin screen order and duplication
  • Loading branch information
stidges committed May 12, 2019
commit 4cbe95900055633b19862a727fa83a4c69494661
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