From 964bf81ee334d7dfd7dbfa7a56cb0cc0e2e97c25 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 9 Jan 2019 21:16:16 -0500 Subject: [PATCH] Port height module to plugin --- src/defaultPlugins.js | 2 ++ src/generators/height.js | 14 -------------- src/plugins/height.js | 13 +++++++++++++ src/utilityModules.js | 2 -- 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 src/generators/height.js create mode 100644 src/plugins/height.js diff --git a/src/defaultPlugins.js b/src/defaultPlugins.js index d9dca45d9..9a50335ab 100644 --- a/src/defaultPlugins.js +++ b/src/defaultPlugins.js @@ -1,3 +1,4 @@ +import height from './plugins/height' import leading from './plugins/leading' import margin from './plugins/margin' import maxHeight from './plugins/maxHeight' @@ -32,6 +33,7 @@ import zIndex from './plugins/zIndex' export default function (config) { return [ + config.modules.height === false ? () => {} : height(), config.modules.leading === false ? () => {} : leading(), config.modules.margin === false ? () => {} : margin(), config.modules.maxHeight === false ? () => {} : maxHeight(), diff --git a/src/generators/height.js b/src/generators/height.js deleted file mode 100644 index 8ba099ca1..000000000 --- a/src/generators/height.js +++ /dev/null @@ -1,14 +0,0 @@ -import _ from 'lodash' -import defineClass from '../util/defineClass' - -function defineHeights(heights) { - return _.map(heights, (size, modifer) => { - return defineClass(`h-${modifer}`, { - height: `${size}`, - }) - }) -} - -export default function(config) { - return _.flatten([defineHeights(config.height)]) -} diff --git a/src/plugins/height.js b/src/plugins/height.js new file mode 100644 index 000000000..67c0ab745 --- /dev/null +++ b/src/plugins/height.js @@ -0,0 +1,13 @@ +import _ from 'lodash' + +export default function () { + return function ({ addUtilities, config, e }) { + const utilities = _.fromPairs(_.map(config('height'), (value, modifier) => { + return [`.${e(`h-${modifier}`)}`, { + 'height': value, + }] + })) + + addUtilities(utilities, config('modules.height')) + } +} diff --git a/src/utilityModules.js b/src/utilityModules.js index ba1e94731..fb98007bb 100644 --- a/src/utilityModules.js +++ b/src/utilityModules.js @@ -16,7 +16,6 @@ import flexbox from './generators/flexbox' import float from './generators/float' import fonts from './generators/fonts' import fontWeights from './generators/fontWeights' -import height from './generators/height' export default [ { name: 'lists', generator: lists }, @@ -37,5 +36,4 @@ export default [ { name: 'float', generator: float }, { name: 'fonts', generator: fonts }, { name: 'fontWeights', generator: fontWeights }, - { name: 'height', generator: height }, ]