Move container component to a built-in plugin
This commit is contained in:
parent
20461a3418
commit
6e7ae58910
5 changed files with 62 additions and 3 deletions
|
|
@ -872,7 +872,9 @@ module.exports = {
|
|||
|
|
||||
*/
|
||||
|
||||
plugins: [],
|
||||
plugins: [
|
||||
require('./plugins/container')(),
|
||||
],
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
|||
1
plugins/container.js
Normal file
1
plugins/container.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('../lib/plugins/container')
|
||||
|
|
@ -54,6 +54,10 @@ program
|
|||
|
||||
const output = fs.readFileSync(path.resolve(__dirname, '../defaultConfig.stub.js'), 'utf8')
|
||||
fs.outputFileSync(destination, output.replace('// let defaultConfig', 'let defaultConfig'))
|
||||
fs.outputFileSync(
|
||||
destination,
|
||||
output.replace("require('./plugins/container')", "require('tailwindcss/plugins/container')")
|
||||
)
|
||||
console.log(`Generated Tailwind config: ${destination}`)
|
||||
process.exit()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import fs from 'fs'
|
||||
import postcss from 'postcss'
|
||||
import container from '../generators/container'
|
||||
import utilityModules from '../utilityModules'
|
||||
import prefixTree from '../util/prefixTree'
|
||||
import generateModules from '../util/generateModules'
|
||||
|
|
@ -22,7 +21,7 @@ export default function(config) {
|
|||
|
||||
if (atRule.params === 'components') {
|
||||
const pluginComponentTree = postcss.root({
|
||||
nodes: [...container(unwrappedConfig), ...pluginComponents],
|
||||
nodes: pluginComponents,
|
||||
})
|
||||
|
||||
pluginComponentTree.walk(node => (node.source = atRule.source))
|
||||
|
|
|
|||
53
src/plugins/container.js
Normal file
53
src/plugins/container.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* eslint-disable no-shadow */
|
||||
import _ from 'lodash'
|
||||
import postcss from 'postcss'
|
||||
import defineClass from '../util/defineClass'
|
||||
|
||||
function extractMinWidths(breakpoints) {
|
||||
return _.flatMap(breakpoints, breakpoints => {
|
||||
if (_.isString(breakpoints)) {
|
||||
breakpoints = { min: breakpoints }
|
||||
}
|
||||
|
||||
if (!_.isArray(breakpoints)) {
|
||||
breakpoints = [breakpoints]
|
||||
}
|
||||
|
||||
return _(breakpoints)
|
||||
.filter(breakpoint => {
|
||||
return _.has(breakpoint, 'min') || _.has(breakpoint, 'min-width')
|
||||
})
|
||||
.map(breakpoint => {
|
||||
return _.get(breakpoint, 'min-width', breakpoint.min)
|
||||
})
|
||||
.value()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function(options) {
|
||||
return function({ addComponents, config }) {
|
||||
const screens = _.get(options, 'screens', config('screens'))
|
||||
|
||||
const minWidths = extractMinWidths(screens)
|
||||
|
||||
const atRules = _.map(minWidths, minWidth => {
|
||||
const atRule = postcss.atRule({
|
||||
name: 'media',
|
||||
params: `(min-width: ${minWidth})`,
|
||||
})
|
||||
atRule.append(
|
||||
defineClass('container', {
|
||||
'max-width': minWidth,
|
||||
})
|
||||
)
|
||||
return atRule
|
||||
})
|
||||
|
||||
addComponents([
|
||||
defineClass('container', {
|
||||
width: '100%',
|
||||
}),
|
||||
...atRules,
|
||||
])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue