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
Sort border width utilities from most general to most specific
  • Loading branch information
adamwathan committed Nov 17, 2017
commit ddfa8de684b3dee5be8772ffc3347eb3471d7e51
160 changes: 80 additions & 80 deletions __tests__/fixtures/tailwind-output.css
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,22 @@ button,
border-width: 0;
}

.border-2 {
border-width: 2px;
}

.border-4 {
border-width: 4px;
}

.border-8 {
border-width: 8px;
}

.border {
border-width: 1px;
}

.border-t-0 {
border-top-width: 0;
}
Expand All @@ -1658,10 +1674,6 @@ button,
border-left-width: 0;
}

.border-2 {
border-width: 2px;
}

.border-t-2 {
border-top-width: 2px;
}
Expand All @@ -1678,10 +1690,6 @@ button,
border-left-width: 2px;
}

.border-4 {
border-width: 4px;
}

.border-t-4 {
border-top-width: 4px;
}
Expand All @@ -1698,10 +1706,6 @@ button,
border-left-width: 4px;
}

.border-8 {
border-width: 8px;
}

.border-t-8 {
border-top-width: 8px;
}
Expand All @@ -1718,10 +1722,6 @@ button,
border-left-width: 8px;
}

.border {
border-width: 1px;
}

.border-t {
border-top-width: 1px;
}
Expand Down Expand Up @@ -4762,6 +4762,22 @@ button,
border-width: 0;
}

.sm\:border-2 {
border-width: 2px;
}

.sm\:border-4 {
border-width: 4px;
}

.sm\:border-8 {
border-width: 8px;
}

.sm\:border {
border-width: 1px;
}

.sm\:border-t-0 {
border-top-width: 0;
}
Expand All @@ -4778,10 +4794,6 @@ button,
border-left-width: 0;
}

.sm\:border-2 {
border-width: 2px;
}

.sm\:border-t-2 {
border-top-width: 2px;
}
Expand All @@ -4798,10 +4810,6 @@ button,
border-left-width: 2px;
}

.sm\:border-4 {
border-width: 4px;
}

.sm\:border-t-4 {
border-top-width: 4px;
}
Expand All @@ -4818,10 +4826,6 @@ button,
border-left-width: 4px;
}

.sm\:border-8 {
border-width: 8px;
}

.sm\:border-t-8 {
border-top-width: 8px;
}
Expand All @@ -4838,10 +4842,6 @@ button,
border-left-width: 8px;
}

.sm\:border {
border-width: 1px;
}

.sm\:border-t {
border-top-width: 1px;
}
Expand Down Expand Up @@ -7883,6 +7883,22 @@ button,
border-width: 0;
}

.md\:border-2 {
border-width: 2px;
}

.md\:border-4 {
border-width: 4px;
}

.md\:border-8 {
border-width: 8px;
}

.md\:border {
border-width: 1px;
}

.md\:border-t-0 {
border-top-width: 0;
}
Expand All @@ -7899,10 +7915,6 @@ button,
border-left-width: 0;
}

.md\:border-2 {
border-width: 2px;
}

.md\:border-t-2 {
border-top-width: 2px;
}
Expand All @@ -7919,10 +7931,6 @@ button,
border-left-width: 2px;
}

.md\:border-4 {
border-width: 4px;
}

.md\:border-t-4 {
border-top-width: 4px;
}
Expand All @@ -7939,10 +7947,6 @@ button,
border-left-width: 4px;
}

.md\:border-8 {
border-width: 8px;
}

.md\:border-t-8 {
border-top-width: 8px;
}
Expand All @@ -7959,10 +7963,6 @@ button,
border-left-width: 8px;
}

.md\:border {
border-width: 1px;
}

.md\:border-t {
border-top-width: 1px;
}
Expand Down Expand Up @@ -11004,6 +11004,22 @@ button,
border-width: 0;
}

.lg\:border-2 {
border-width: 2px;
}

.lg\:border-4 {
border-width: 4px;
}

.lg\:border-8 {
border-width: 8px;
}

.lg\:border {
border-width: 1px;
}

.lg\:border-t-0 {
border-top-width: 0;
}
Expand All @@ -11020,10 +11036,6 @@ button,
border-left-width: 0;
}

.lg\:border-2 {
border-width: 2px;
}

.lg\:border-t-2 {
border-top-width: 2px;
}
Expand All @@ -11040,10 +11052,6 @@ button,
border-left-width: 2px;
}

.lg\:border-4 {
border-width: 4px;
}

.lg\:border-t-4 {
border-top-width: 4px;
}
Expand All @@ -11060,10 +11068,6 @@ button,
border-left-width: 4px;
}

.lg\:border-8 {
border-width: 8px;
}

.lg\:border-t-8 {
border-top-width: 8px;
}
Expand All @@ -11080,10 +11084,6 @@ button,
border-left-width: 8px;
}

.lg\:border {
border-width: 1px;
}

.lg\:border-t {
border-top-width: 1px;
}
Expand Down Expand Up @@ -14125,6 +14125,22 @@ button,
border-width: 0;
}

.xl\:border-2 {
border-width: 2px;
}

.xl\:border-4 {
border-width: 4px;
}

.xl\:border-8 {
border-width: 8px;
}

.xl\:border {
border-width: 1px;
}

.xl\:border-t-0 {
border-top-width: 0;
}
Expand All @@ -14141,10 +14157,6 @@ button,
border-left-width: 0;
}

.xl\:border-2 {
border-width: 2px;
}

.xl\:border-t-2 {
border-top-width: 2px;
}
Expand All @@ -14161,10 +14173,6 @@ button,
border-left-width: 2px;
}

.xl\:border-4 {
border-width: 4px;
}

.xl\:border-t-4 {
border-top-width: 4px;
}
Expand All @@ -14181,10 +14189,6 @@ button,
border-left-width: 4px;
}

.xl\:border-8 {
border-width: 8px;
}

.xl\:border-t-8 {
border-top-width: 8px;
}
Expand All @@ -14201,10 +14205,6 @@ button,
border-left-width: 8px;
}

.xl\:border {
border-width: 1px;
}

.xl\:border-t {
border-top-width: 1px;
}
Expand Down
48 changes: 29 additions & 19 deletions src/generators/borderWidths.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import _ from 'lodash'
import defineClasses from '../util/defineClasses'

function sizedBorder(width, modifier) {
modifier = modifier === 'default' ? '' : `-${modifier}`
function defineBorderWidthUtilities(borderWidths) {
const generators = [
(width, modifier) =>
defineClasses({
[`border${modifier}`]: {
'border-width': `${width}`,
},
}),
(width, modifier) =>
defineClasses({
[`border-t${modifier}`]: {
'border-top-width': `${width}`,
},
[`border-r${modifier}`]: {
'border-right-width': `${width}`,
},
[`border-b${modifier}`]: {
'border-bottom-width': `${width}`,
},
[`border-l${modifier}`]: {
'border-left-width': `${width}`,
},
}),
]

return defineClasses({
[`border${modifier}`]: {
'border-width': `${width}`,
},
[`border-t${modifier}`]: {
'border-top-width': `${width}`,
},
[`border-r${modifier}`]: {
'border-right-width': `${width}`,
},
[`border-b${modifier}`]: {
'border-bottom-width': `${width}`,
},
[`border-l${modifier}`]: {
'border-left-width': `${width}`,
},
return _.flatMap(generators, generator => {
return _.flatMap(borderWidths, (width, modifier) => {
return generator(width, modifier === 'default' ? '' : `-${modifier}`)
})
})
}

module.exports = function({ borderWidths }) {
return _.flatMap(borderWidths, sizedBorder)
return defineBorderWidthUtilities(borderWidths)
}