Port objectPosition module to plugin, conditionally load plugins based on modules config

This commit is contained in:
Adam Wathan 2019-01-09 14:11:48 -05:00
parent 3f089182cf
commit 5b3d6d8861
5 changed files with 44 additions and 42 deletions

View file

@ -1,3 +1,4 @@
import objectPosition from './plugins/objectPosition'
import opacity from './plugins/opacity'
import outline from './plugins/outline'
import overflow from './plugins/overflow'
@ -21,27 +22,30 @@ import whitespace from './plugins/whitespace'
import width from './plugins/width'
import zIndex from './plugins/zIndex'
export default [
opacity(),
outline(),
overflow(),
padding(),
pointerEvents(),
position(),
resize(),
shadows(),
svgFill(),
svgStroke(),
tableLayout(),
textAlign(),
textColors(),
textSizes(),
textStyle(),
tracking(),
userSelect(),
verticalAlign(),
visibility(),
whitespace(),
width(),
zIndex(),
]
export default function (config) {
return [
config.modules.objectPosition === false ? () => {} : objectPosition(),
config.modules.opacity === false ? () => {} : opacity(),
config.modules.outline === false ? () => {} : outline(),
config.modules.overflow === false ? () => {} : overflow(),
config.modules.padding === false ? () => {} : padding(),
config.modules.pointerEvents === false ? () => {} : pointerEvents(),
config.modules.position === false ? () => {} : position(),
config.modules.resize === false ? () => {} : resize(),
config.modules.shadows === false ? () => {} : shadows(),
config.modules.svgFill === false ? () => {} : svgFill(),
config.modules.svgStroke === false ? () => {} : svgStroke(),
config.modules.tableLayout === false ? () => {} : tableLayout(),
config.modules.textAlign === false ? () => {} : textAlign(),
config.modules.textColors === false ? () => {} : textColors(),
config.modules.textSizes === false ? () => {} : textSizes(),
config.modules.textStyle === false ? () => {} : textStyle(),
config.modules.tracking === false ? () => {} : tracking(),
config.modules.userSelect === false ? () => {} : userSelect(),
config.modules.verticalAlign === false ? () => {} : verticalAlign(),
config.modules.visibility === false ? () => {} : visibility(),
config.modules.whitespace === false ? () => {} : whitespace(),
config.modules.width === false ? () => {} : width(),
config.modules.zIndex === false ? () => {} : zIndex(),
]
}

View file

@ -1,15 +0,0 @@
import defineClasses from '../util/defineClasses'
export default function() {
return defineClasses({
'object-bottom': { 'object-position': 'bottom' },
'object-center': { 'object-position': 'center' },
'object-left': { 'object-position': 'left' },
'object-left-bottom': { 'object-position': 'left bottom' },
'object-left-top': { 'object-position': 'left top' },
'object-right': { 'object-position': 'right' },
'object-right-bottom': { 'object-position': 'right bottom' },
'object-right-top': { 'object-position': 'right top' },
'object-top': { 'object-position': 'top' },
})
}

View file

@ -0,0 +1,15 @@
export default function () {
return function ({ addUtilities, config }) {
addUtilities({
'.object-bottom': { 'object-position': 'bottom' },
'.object-center': { 'object-position': 'center' },
'.object-left': { 'object-position': 'left' },
'.object-left-bottom': { 'object-position': 'left bottom' },
'.object-left-top': { 'object-position': 'left top' },
'.object-right': { 'object-position': 'right' },
'.object-right-bottom': { 'object-position': 'right bottom' },
'.object-right-top': { 'object-position': 'right top' },
'.object-top': { 'object-position': 'top' },
}, config('modules.objectPosition'))
}
}

View file

@ -17,7 +17,7 @@ export default function(getConfig) {
return function(css) {
const config = getConfig()
const processedPlugins = processPlugins([
...defaultPlugins,
...defaultPlugins(config),
...config.plugins
], config)
const utilities = generateUtilities(config, processedPlugins.utilities)

View file

@ -25,7 +25,6 @@ import minHeight from './generators/minHeight'
import minWidth from './generators/minWidth'
import negativeMargin from './generators/negativeMargin'
import objectFit from './generators/objectFit'
import objectPosition from './generators/objectPosition'
export default [
{ name: 'lists', generator: lists },
@ -55,5 +54,4 @@ export default [
{ name: 'minWidth', generator: minWidth },
{ name: 'negativeMargin', generator: negativeMargin },
{ name: 'objectFit', generator: objectFit },
{ name: 'objectPosition', generator: objectPosition },
]