From b5a51e879daab1f53d47854456ae252b1f4ea4d2 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 9 Jan 2019 21:12:45 -0500 Subject: [PATCH] Port maxHeight module to plugin --- src/defaultPlugins.js | 2 ++ src/generators/maxHeight.js | 14 -------------- src/plugins/maxHeight.js | 13 +++++++++++++ src/utilityModules.js | 2 -- 4 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 src/generators/maxHeight.js create mode 100644 src/plugins/maxHeight.js diff --git a/src/defaultPlugins.js b/src/defaultPlugins.js index 1a2b2f88e..f559851f4 100644 --- a/src/defaultPlugins.js +++ b/src/defaultPlugins.js @@ -1,3 +1,4 @@ +import maxHeight from './plugins/maxHeight' import maxWidth from './plugins/maxWidth' import minHeight from './plugins/minHeight' import minWidth from './plugins/minWidth' @@ -29,6 +30,7 @@ import zIndex from './plugins/zIndex' export default function (config) { return [ + config.modules.maxHeight === false ? () => {} : maxHeight(), config.modules.maxWidth === false ? () => {} : maxWidth(), config.modules.minHeight === false ? () => {} : minHeight(), config.modules.minWidth === false ? () => {} : minWidth(), diff --git a/src/generators/maxHeight.js b/src/generators/maxHeight.js deleted file mode 100644 index ae42ba6fb..000000000 --- a/src/generators/maxHeight.js +++ /dev/null @@ -1,14 +0,0 @@ -import _ from 'lodash' -import defineClass from '../util/defineClass' - -function defineMaxHeights(heights) { - return _.map(heights, (size, modifer) => { - return defineClass(`max-h-${modifer}`, { - 'max-height': `${size}`, - }) - }) -} - -export default function(config) { - return _.flatten([defineMaxHeights(config.maxHeight)]) -} diff --git a/src/plugins/maxHeight.js b/src/plugins/maxHeight.js new file mode 100644 index 000000000..b6f50dcdf --- /dev/null +++ b/src/plugins/maxHeight.js @@ -0,0 +1,13 @@ +import _ from 'lodash' + +export default function () { + return function ({ addUtilities, config, e }) { + const utilities = _.fromPairs(_.map(config('maxHeight'), (value, modifier) => { + return [`.${e(`max-h-${modifier}`)}`, { + 'max-height': value, + }] + })) + + addUtilities(utilities, config('modules.maxHeight')) + } +} diff --git a/src/utilityModules.js b/src/utilityModules.js index 9a8b7639a..b562a7871 100644 --- a/src/utilityModules.js +++ b/src/utilityModules.js @@ -19,7 +19,6 @@ import fontWeights from './generators/fontWeights' import height from './generators/height' import leading from './generators/leading' import margin from './generators/margin' -import maxHeight from './generators/maxHeight' export default [ { name: 'lists', generator: lists }, @@ -43,5 +42,4 @@ export default [ { name: 'height', generator: height }, { name: 'leading', generator: leading }, { name: 'margin', generator: margin }, - { name: 'maxHeight', generator: maxHeight }, ]