From 36075fae30f224c57d06c1de2c4c05ac5ae56276 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 9 Jan 2019 21:31:51 -0500 Subject: [PATCH] Port borderWidths module to plugin --- src/defaultPlugins.js | 2 ++ src/generators/borderWidths.js | 38 ---------------------------------- src/plugins/borderWidths.js | 25 ++++++++++++++++++++++ src/utilityModules.js | 2 -- 4 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 src/generators/borderWidths.js create mode 100644 src/plugins/borderWidths.js diff --git a/src/defaultPlugins.js b/src/defaultPlugins.js index fc29ce7c6..540bbcde1 100644 --- a/src/defaultPlugins.js +++ b/src/defaultPlugins.js @@ -1,3 +1,4 @@ +import borderWidths from './plugins/borderWidths' import cursor from './plugins/cursor' import display from './plugins/display' import flexbox from './plugins/flexbox' @@ -39,6 +40,7 @@ import zIndex from './plugins/zIndex' export default function (config) { return [ + config.modules.borderWidths === false ? () => {} : borderWidths(), config.modules.cursor === false ? () => {} : cursor(), config.modules.display === false ? () => {} : display(), config.modules.flexbox === false ? () => {} : flexbox(), diff --git a/src/generators/borderWidths.js b/src/generators/borderWidths.js deleted file mode 100644 index f02c4f7cf..000000000 --- a/src/generators/borderWidths.js +++ /dev/null @@ -1,38 +0,0 @@ -import _ from 'lodash' -import defineClasses from '../util/defineClasses' - -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 _.flatMap(generators, generator => { - return _.flatMap(borderWidths, (width, modifier) => { - return generator(width, modifier === 'default' ? '' : `-${modifier}`) - }) - }) -} - -module.exports = function({ borderWidths }) { - return defineBorderWidthUtilities(borderWidths) -} diff --git a/src/plugins/borderWidths.js b/src/plugins/borderWidths.js new file mode 100644 index 000000000..58e625e1c --- /dev/null +++ b/src/plugins/borderWidths.js @@ -0,0 +1,25 @@ +import _ from 'lodash' + +export default function () { + return function ({ addUtilities, config, e }) { + const generators = [ + (value, modifier) => ({ + [`.${e(`border${modifier}`)}`]: { borderWidth: `${value}` }, + }), + (value, modifier) => ({ + [`.${e(`border-t${modifier}`)}`]: { borderTopWidth: `${value}` }, + [`.${e(`border-r${modifier}`)}`]: { borderRightWidth: `${value}` }, + [`.${e(`border-b${modifier}`)}`]: { borderBottomWidth: `${value}` }, + [`.${e(`border-l${modifier}`)}`]: { borderLeftWidth: `${value}` }, + }), + ] + + const utilities = _.flatMap(generators, generator => { + return _.flatMap(config('borderWidths'), (value, modifier) => { + return generator(value, modifier === 'default' ? '' : `-${modifier}`) + }) + }) + + addUtilities(utilities, config('modules.borderWidths')) + } +} diff --git a/src/utilityModules.js b/src/utilityModules.js index 92756b395..44b35466c 100644 --- a/src/utilityModules.js +++ b/src/utilityModules.js @@ -9,7 +9,6 @@ import borderCollapse from './generators/borderCollapse' import borderColors from './generators/borderColors' import borderRadius from './generators/borderRadius' import borderStyle from './generators/borderStyle' -import borderWidths from './generators/borderWidths' export default [ { name: 'lists', generator: lists }, @@ -23,5 +22,4 @@ export default [ { name: 'borderColors', generator: borderColors }, { name: 'borderRadius', generator: borderRadius }, { name: 'borderStyle', generator: borderStyle }, - { name: 'borderWidths', generator: borderWidths }, ]