From 3c99be09cabbdf4f6d180ef5760b7b286d5712c1 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 9 Jan 2019 21:11:50 -0500 Subject: [PATCH] Port maxWidth module to plugin --- src/defaultPlugins.js | 2 ++ src/generators/maxWidth.js | 14 -------------- src/plugins/maxWidth.js | 13 +++++++++++++ src/utilityModules.js | 2 -- 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 src/generators/maxWidth.js create mode 100644 src/plugins/maxWidth.js diff --git a/src/defaultPlugins.js b/src/defaultPlugins.js index 8967e1026..1a2b2f88e 100644 --- a/src/defaultPlugins.js +++ b/src/defaultPlugins.js @@ -1,3 +1,4 @@ +import maxWidth from './plugins/maxWidth' import minHeight from './plugins/minHeight' import minWidth from './plugins/minWidth' import negativeMargin from './plugins/negativeMargin' @@ -28,6 +29,7 @@ import zIndex from './plugins/zIndex' export default function (config) { return [ + config.modules.maxWidth === false ? () => {} : maxWidth(), config.modules.minHeight === false ? () => {} : minHeight(), config.modules.minWidth === false ? () => {} : minWidth(), config.modules.negativeMargin === false ? () => {} : negativeMargin(), diff --git a/src/generators/maxWidth.js b/src/generators/maxWidth.js deleted file mode 100644 index 9daa4d270..000000000 --- a/src/generators/maxWidth.js +++ /dev/null @@ -1,14 +0,0 @@ -import _ from 'lodash' -import defineClass from '../util/defineClass' - -function defineMaxWidths(widths) { - return _.map(widths, (size, modifer) => { - return defineClass(`max-w-${modifer}`, { - 'max-width': `${size}`, - }) - }) -} - -export default function(config) { - return _.flatten([defineMaxWidths(config.maxWidth)]) -} diff --git a/src/plugins/maxWidth.js b/src/plugins/maxWidth.js new file mode 100644 index 000000000..dadd826ae --- /dev/null +++ b/src/plugins/maxWidth.js @@ -0,0 +1,13 @@ +import _ from 'lodash' + +export default function () { + return function ({ addUtilities, config, e }) { + const utilities = _.fromPairs(_.map(config('maxWidth'), (value, modifier) => { + return [`.${e(`max-w-${modifier}`)}`, { + 'max-width': value, + }] + })) + + addUtilities(utilities, config('modules.maxWidth')) + } +} diff --git a/src/utilityModules.js b/src/utilityModules.js index ce62cd447..9a8b7639a 100644 --- a/src/utilityModules.js +++ b/src/utilityModules.js @@ -20,7 +20,6 @@ import height from './generators/height' import leading from './generators/leading' import margin from './generators/margin' import maxHeight from './generators/maxHeight' -import maxWidth from './generators/maxWidth' export default [ { name: 'lists', generator: lists }, @@ -45,5 +44,4 @@ export default [ { name: 'leading', generator: leading }, { name: 'margin', generator: margin }, { name: 'maxHeight', generator: maxHeight }, - { name: 'maxWidth', generator: maxWidth }, ]