Skip to content

Commit

Permalink
Sort from map of utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonohue committed May 24, 2019
1 parent 43a7617 commit 89df3b8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/createUtilitiesFromConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ export default function createUtilitiesFromConfig(configFn = (cfg) => cfg) {
)

// Not actually sorted, but we rely on the key order
const sortedUtilityClasses = Object.keys(utilityClasses)
const sortedUtilityClasses = Object.keys(utilityClasses).reduce(
(map, key, i) => {
map[key] = i
return map
},
{}
)

const cssForUtility = (className, isImportant = false) => {
return parseDeclarations(utilityClasses[className], isImportant).join(" ")
}
const cssForUtility = (className, isImportant = false) =>
parseDeclarations(utilityClasses[className], isImportant).join(" ")

const styleWith = (classNames = "", isImportant = false) => {
const activeApply = classNames.split(" ").filter((name) => apply[name])
Expand All @@ -98,9 +103,7 @@ export default function createUtilitiesFromConfig(configFn = (cfg) => cfg) {
.split(" ")
.map((className) => className.trim())
.filter(Boolean)
.sort((a, b) => {
return sortedUtilityClasses.indexOf(a) - sortedUtilityClasses.indexOf(b)
})
.sort((a, b) => sortedUtilityClasses[a] - sortedUtilityClasses[b])

for (let i = 0; i < activeApply.length; i++) {
const applyClasses = apply[activeApply[i]]
Expand Down

0 comments on commit 89df3b8

Please sign in to comment.