Skip to content

Commit

Permalink
Merge pull request styled-system#812 from styled-system/fix-sort
Browse files Browse the repository at this point in the history
Sort media queries naturally
  • Loading branch information
jxnblk authored Sep 11, 2019
2 parents ec73ace + 1077949 commit dddd25c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export const merge = (a, b) => {
// sort object-value responsive styles
const sort = obj => {
const next = {}
Object.keys(obj).sort().forEach(key => {
next[key] = obj[key]
})
Object.keys(obj)
.sort((a, b) => a.localeCompare(b, undefined, {
numeric: true,
sensitivity: 'base',
}))
.forEach(key => {
next[key] = obj[key]
})
return next
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/test/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,18 @@ test('sorts media queries when responsive object values are used', () => {
sm: '32em',
md: '40em',
lg: '64em',
xl: '128em',
}
},
padding: { _: 16, lg: 64 },
padding: { _: 16, lg: 64, xl: 128 },
margin: { sm: 4, md: 8 },
color: { lg: 'tomato' },
})
expect(Object.keys(styles)).toEqual([
'@media screen and (min-width: 32em)',
'@media screen and (min-width: 40em)',
'@media screen and (min-width: 64em)',
'@media screen and (min-width: 128em)',
'padding',
])
})
Expand Down

0 comments on commit dddd25c

Please sign in to comment.